Search in sources :

Example 46 with SQLiteStatement

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();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 47 with SQLiteStatement

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();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 48 with SQLiteStatement

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);
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Date(java.util.Date)

Example 49 with SQLiteStatement

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);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) ReaderComment(org.wordpress.android.models.ReaderComment)

Example 50 with SQLiteStatement

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();
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)252 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 Test (org.junit.Test)22 SQLException (android.database.SQLException)21 Date (java.util.Date)12 TargetApi (android.annotation.TargetApi)8 SQLiteDoneException (android.database.sqlite.SQLiteDoneException)8 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)7 SdkSuppress (android.support.test.filters.SdkSuppress)7 ArrayList (java.util.ArrayList)5 SQLiteException (android.database.sqlite.SQLiteException)4 SQLiteFullException (android.database.sqlite.SQLiteFullException)4 SQLException (java.sql.SQLException)4 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 Savepoint (java.sql.Savepoint)3 ContentValues (android.content.ContentValues)2