Search in sources :

Example 16 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project c-geo by just-radovan.

the class cgData method hasLogOffline.

public boolean hasLogOffline(String geocode) {
    if (geocode == null || geocode.length() == 0) {
        return false;
    }
    init();
    try {
        final SQLiteStatement countSql = databaseRO.compileStatement("select count(_id) from " + dbTableLogsOffline + " where geocode = \"" + geocode.toUpperCase() + "\"");
        final int count = (int) countSql.simpleQueryForLong();
        if (count > 0) {
            return true;
        }
        countSql.close();
    } catch (Exception e) {
        Log.e(cgSettings.tag, "cgData.hasLogOffline: " + e.toString());
    }
    return false;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 17 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android-priority-jobqueue by path.

the class SqliteJobQueue method delete.

private void delete(Long id) {
    SQLiteStatement stmt = sqlHelper.getDeleteStatement();
    synchronized (stmt) {
        stmt.clearBindings();
        stmt.bindLong(1, id);
        stmt.execute();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 18 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseStatementTest method testStatementMultipleBindings.

@MediumTest
public void testStatementMultipleBindings() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER, str TEXT);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num, str) VALUES (?, ?)");
    for (long i = 0; i < 10; i++) {
        statement.bindLong(1, i);
        statement.bindString(2, Long.toHexString(i));
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
    int numCol = c.getColumnIndexOrThrow("num");
    int strCol = c.getColumnIndexOrThrow("str");
    assertTrue(c.moveToFirst());
    for (long i = 0; i < 10; i++) {
        long num = c.getLong(numCol);
        String str = c.getString(strCol);
        assertEquals(i, num);
        assertEquals(Long.toHexString(i), str);
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 19 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseStatementTest method testStatementLongBinding.

@MediumTest
public void testStatementLongBinding() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (int i = 0; i < 10; i++) {
        statement.bindLong(1, i);
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int numCol = c.getColumnIndexOrThrow("num");
    c.moveToFirst();
    for (long i = 0; i < 10; i++) {
        long num = c.getLong(numCol);
        assertEquals(i, num);
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 20 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseStatementTest method testStatementConstraint.

@MediumTest
public void testStatementConstraint() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    // Try to insert NULL, which violates the constraint
    try {
        statement.clearBindings();
        statement.execute();
        fail("expected exception not thrown");
    } catch (SQLiteConstraintException e) {
    // expected
    }
    // Make sure the statement can still be used
    statement.bindLong(1, 1);
    statement.execute();
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int numCol = c.getColumnIndexOrThrow("num");
    c.moveToFirst();
    long num = c.getLong(numCol);
    assertEquals(1, num);
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)249 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 SQLException (android.database.SQLException)21 Test (org.junit.Test)20 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 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 ContentValues (android.content.ContentValues)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2