use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by AOSPA.
the class DatabaseStatementTest method testStatementMultiThreaded.
@MediumTest
public void testStatementMultiThreaded() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER, str TEXT);");
SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num, str) VALUES (?, ?)");
StatementTestThread thread = new StatementTestThread(mDatabase, statement);
thread.start();
try {
thread.join();
} finally {
statement.close();
}
}
use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by AOSPA.
the class DatabaseStatementTest method testExecuteStatement.
@MediumTest
public void testExecuteStatement() throws Exception {
populateDefaultTable();
SQLiteStatement statement = mDatabase.compileStatement("DELETE FROM test");
statement.execute();
Cursor c = mDatabase.query("test", null, null, null, null, null, null);
assertEquals(0, c.getCount());
c.deactivate();
statement.close();
}
use of android.database.sqlite.SQLiteStatement in project WordPress-Android by wordpress-mobile.
the class ReaderBlogTable method addOrUpdateBlog.
public static void addOrUpdateBlog(ReaderBlog blogInfo) {
if (blogInfo == null) {
return;
}
String sql = "INSERT OR REPLACE INTO tbl_blog_info" + " (blog_id, feed_id, blog_url, image_url, feed_url, name, description, is_private, is_jetpack, is_following, num_followers, date_updated)" + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)";
SQLiteStatement stmt = ReaderDatabase.getWritableDb().compileStatement(sql);
try {
stmt.bindLong(1, blogInfo.blogId);
stmt.bindLong(2, blogInfo.feedId);
stmt.bindString(3, blogInfo.getUrl());
stmt.bindString(4, blogInfo.getImageUrl());
stmt.bindString(5, blogInfo.getFeedUrl());
stmt.bindString(6, blogInfo.getName());
stmt.bindString(7, blogInfo.getDescription());
stmt.bindLong(8, SqlUtils.boolToSql(blogInfo.isPrivate));
stmt.bindLong(9, SqlUtils.boolToSql(blogInfo.isJetpack));
stmt.bindLong(10, SqlUtils.boolToSql(blogInfo.isFollowing));
stmt.bindLong(11, blogInfo.numSubscribers);
stmt.bindString(12, DateTimeUtils.iso8601FromDate(new Date()));
stmt.execute();
} finally {
SqlUtils.closeStatement(stmt);
}
}
use of android.database.sqlite.SQLiteStatement in project WordPress-Android by wordpress-mobile.
the class ReaderCommentTable method addOrUpdateComments.
public static void addOrUpdateComments(ReaderCommentList comments) {
if (comments == null || comments.size() == 0) {
return;
}
SQLiteDatabase db = ReaderDatabase.getWritableDb();
db.beginTransaction();
SQLiteStatement stmt = db.compileStatement("INSERT OR REPLACE INTO tbl_comments (" + COLUMN_NAMES + ") VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16)");
try {
for (ReaderComment comment : comments) {
stmt.bindLong(1, comment.blogId);
stmt.bindLong(2, comment.postId);
stmt.bindLong(3, comment.commentId);
stmt.bindLong(4, comment.parentId);
stmt.bindString(5, comment.getAuthorName());
stmt.bindString(6, comment.getAuthorAvatar());
stmt.bindString(7, comment.getAuthorUrl());
stmt.bindLong(8, comment.authorId);
stmt.bindLong(9, comment.authorBlogId);
stmt.bindString(10, comment.getPublished());
stmt.bindLong(11, comment.timestamp);
stmt.bindString(12, comment.getStatus());
stmt.bindString(13, comment.getText());
stmt.bindLong(14, comment.numLikes);
stmt.bindLong(15, SqlUtils.boolToSql(comment.isLikedByCurrentUser));
stmt.bindLong(16, comment.pageNumber);
stmt.execute();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
SqlUtils.closeStatement(stmt);
}
}
use of android.database.sqlite.SQLiteStatement in project WordPress-Android by wordpress-mobile.
the class ReaderTagTable method setRecommendedTags.
public static void setRecommendedTags(ReaderTagList tagList) {
if (tagList == null) {
return;
}
SQLiteDatabase db = ReaderDatabase.getWritableDb();
SQLiteStatement stmt = db.compileStatement("INSERT INTO tbl_tags_recommended (tag_slug, tag_display_name, tag_title, tag_type, endpoint) VALUES (?1,?2,?3,?4,?5)");
db.beginTransaction();
try {
try {
// first delete all recommended tags
db.execSQL("DELETE FROM tbl_tags_recommended");
// then insert the passed ones
for (ReaderTag tag : tagList) {
stmt.bindString(1, tag.getTagSlug());
stmt.bindString(2, tag.getTagDisplayName());
stmt.bindString(3, tag.getTagTitle());
stmt.bindLong(4, tag.tagType.toInt());
stmt.bindString(5, tag.getEndpoint());
stmt.execute();
}
db.setTransactionSuccessful();
} catch (SQLException e) {
AppLog.e(T.READER, e);
}
} finally {
SqlUtils.closeStatement(stmt);
db.endTransaction();
}
}
Aggregations