use of android.database.sqlite.SQLiteDoneException in project android_frameworks_base by ParanoidAndroid.
the class DatabaseStatementTest method testSimpleQuery.
@MediumTest
public void testSimpleQuery() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL, str TEXT NOT NULL);");
mDatabase.execSQL("INSERT INTO test VALUES (1234, 'hello');");
SQLiteStatement statement1 = mDatabase.compileStatement("SELECT num FROM test WHERE str = ?");
SQLiteStatement statement2 = mDatabase.compileStatement("SELECT str FROM test WHERE num = ?");
try {
statement1.bindString(1, "hello");
long value = statement1.simpleQueryForLong();
assertEquals(1234, value);
statement1.bindString(1, "world");
statement1.simpleQueryForLong();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
try {
statement2.bindLong(1, 1234);
String value = statement1.simpleQueryForString();
assertEquals("hello", value);
statement2.bindLong(1, 5678);
statement1.simpleQueryForString();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
statement1.close();
statement2.close();
}
use of android.database.sqlite.SQLiteDoneException in project android_frameworks_base by DirtyUnicorns.
the class DatabaseStatementTest method testSimpleQuery.
@MediumTest
public void testSimpleQuery() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL, str TEXT NOT NULL);");
mDatabase.execSQL("INSERT INTO test VALUES (1234, 'hello');");
SQLiteStatement statement1 = mDatabase.compileStatement("SELECT num FROM test WHERE str = ?");
SQLiteStatement statement2 = mDatabase.compileStatement("SELECT str FROM test WHERE num = ?");
try {
statement1.bindString(1, "hello");
long value = statement1.simpleQueryForLong();
assertEquals(1234, value);
statement1.bindString(1, "world");
statement1.simpleQueryForLong();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
try {
statement2.bindLong(1, 1234);
String value = statement1.simpleQueryForString();
assertEquals("hello", value);
statement2.bindLong(1, 5678);
statement1.simpleQueryForString();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
statement1.close();
statement2.close();
}
use of android.database.sqlite.SQLiteDoneException in project NetGuard by M66B.
the class DatabaseHelper method getQName.
public String getQName(int uid, String ip) {
lock.readLock().lock();
try {
SQLiteDatabase db = this.getReadableDatabase();
// There is a segmented index on resource
// There is an index on access.daddr
String query = "SELECT d.qname";
query += " FROM dns AS d";
query += " LEFT JOIN access AS a";
query += " ON a.daddr = d.qname AND a.uid = " + uid;
query += " WHERE d.resource = '" + ip.replace("'", "''") + "'";
query += " ORDER BY CASE a.daddr WHEN NULL THEN 1 ELSE 0 END, d.qname";
query += " LIMIT 1";
return db.compileStatement(query).simpleQueryForString();
} catch (SQLiteDoneException ignored) {
// Not found
return null;
} finally {
lock.readLock().unlock();
}
}
use of android.database.sqlite.SQLiteDoneException in project android_frameworks_base by crdroidandroid.
the class DatabaseStatementTest method testSimpleQuery.
@MediumTest
public void testSimpleQuery() throws Exception {
mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL, str TEXT NOT NULL);");
mDatabase.execSQL("INSERT INTO test VALUES (1234, 'hello');");
SQLiteStatement statement1 = mDatabase.compileStatement("SELECT num FROM test WHERE str = ?");
SQLiteStatement statement2 = mDatabase.compileStatement("SELECT str FROM test WHERE num = ?");
try {
statement1.bindString(1, "hello");
long value = statement1.simpleQueryForLong();
assertEquals(1234, value);
statement1.bindString(1, "world");
statement1.simpleQueryForLong();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
try {
statement2.bindLong(1, 1234);
String value = statement1.simpleQueryForString();
assertEquals("hello", value);
statement2.bindLong(1, 5678);
statement1.simpleQueryForString();
fail("shouldn't get here");
} catch (SQLiteDoneException e) {
// expected
}
statement1.close();
statement2.close();
}
use of android.database.sqlite.SQLiteDoneException in project XPrivacy by M66B.
the class PrivacyService method getUsage.
// Usage
@Override
public long getUsage(List<PRestriction> listRestriction) throws RemoteException {
long lastUsage = 0;
try {
int uid = -1;
for (PRestriction restriction : listRestriction) if (uid < 0)
uid = restriction.uid;
else if (uid != restriction.uid)
throw new SecurityException();
enforcePermission(uid);
SQLiteDatabase dbUsage = getDbUsage();
// Precompile statement when needed
if (stmtGetUsageRestriction == null) {
String sql = "SELECT MAX(time) FROM " + cTableUsage + " WHERE uid=? AND restriction=?";
stmtGetUsageRestriction = dbUsage.compileStatement(sql);
}
if (stmtGetUsageMethod == null) {
String sql = "SELECT MAX(time) FROM " + cTableUsage + " WHERE uid=? AND restriction=? AND method=?";
stmtGetUsageMethod = dbUsage.compileStatement(sql);
}
mLockUsage.readLock().lock();
try {
dbUsage.beginTransaction();
try {
for (PRestriction restriction : listRestriction) {
if (restriction.methodName == null)
try {
synchronized (stmtGetUsageRestriction) {
stmtGetUsageRestriction.clearBindings();
stmtGetUsageRestriction.bindLong(1, restriction.uid);
stmtGetUsageRestriction.bindString(2, restriction.restrictionName);
lastUsage = Math.max(lastUsage, stmtGetUsageRestriction.simpleQueryForLong());
}
} catch (SQLiteDoneException ignored) {
}
else
try {
synchronized (stmtGetUsageMethod) {
stmtGetUsageMethod.clearBindings();
stmtGetUsageMethod.bindLong(1, restriction.uid);
stmtGetUsageMethod.bindString(2, restriction.restrictionName);
stmtGetUsageMethod.bindString(3, restriction.methodName);
lastUsage = Math.max(lastUsage, stmtGetUsageMethod.simpleQueryForLong());
}
} catch (SQLiteDoneException ignored) {
}
}
dbUsage.setTransactionSuccessful();
} finally {
dbUsage.endTransaction();
}
} finally {
mLockUsage.readLock().unlock();
}
} catch (Throwable ex) {
Util.bug(null, ex);
throw new RemoteException(ex.toString());
}
return lastUsage;
}
Aggregations