use of android.database.sqlite.SQLiteException in project requery by requery.
the class SqlitexStatement method executeUpdate.
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
SQLiteStatement statement = null;
try {
statement = connection.getDatabase().compileStatement(sql);
if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
long rowId = statement.executeInsert();
insertResult = new SingleResultSet(this, rowId);
updateCount = 1;
} else {
updateCount = statement.executeUpdateDelete();
}
} catch (SQLiteException e) {
SqlitexConnection.throwSQLException(e);
} finally {
if (statement != null) {
statement.close();
}
}
return updateCount;
}
use of android.database.sqlite.SQLiteException in project android_frameworks_base by ParanoidAndroid.
the class SettingsProvider method lookupValue.
// Looks up value 'key' in 'table' and returns either a single-pair Bundle,
// possibly with a null value, or null on failure.
private Bundle lookupValue(DatabaseHelper dbHelper, String table, final SettingsCache cache, String key) {
if (cache == null) {
Slog.e(TAG, "cache is null for user " + UserHandle.getCallingUserId() + " : key=" + key);
return null;
}
synchronized (cache) {
Bundle value = cache.get(key);
if (value != null) {
if (value != TOO_LARGE_TO_CACHE_MARKER) {
return value;
}
// else we fall through and read the value from disk
} else if (cache.fullyMatchesDisk()) {
// from somebody's UI thread...
return NULL_SETTING;
}
}
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = null;
try {
cursor = db.query(table, COLUMN_VALUE, "name=?", new String[] { key }, null, null, null, null);
if (cursor != null && cursor.getCount() == 1) {
cursor.moveToFirst();
return cache.putIfAbsent(key, cursor.getString(0));
}
} catch (SQLiteException e) {
Log.w(TAG, "settings lookup error", e);
return null;
} finally {
if (cursor != null)
cursor.close();
}
cache.putIfAbsent(key, null);
return NULL_SETTING;
}
use of android.database.sqlite.SQLiteException in project android_frameworks_base by ParanoidAndroid.
the class DatabaseErrorHandlerTest method testDatabaseIsCorrupt.
public void testDatabaseIsCorrupt() throws IOException {
mDatabase.execSQL("create table t (i int);");
// write junk into the database file
BufferedWriter writer = new BufferedWriter(new FileWriter(mDatabaseFile.getPath()));
writer.write("blah");
writer.close();
assertTrue(mDatabaseFile.exists());
// should trigger call to MyDatabaseCorruptionHandler.onCorruption
try {
mDatabase.execSQL("select * from t;");
fail("expected exception");
} catch (SQLiteDiskIOException e) {
// expected
if (mDatabaseFile.exists()) {
mDatabaseFile.delete();
}
} catch (SQLiteException e) {
}
// database file should be gone
assertFalse(mDatabaseFile.exists());
// after corruption handler is called, the database file should be free of
// database corruption
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, new MyDatabaseCorruptionHandler());
assertTrue(db.isDatabaseIntegrityOk());
}
use of android.database.sqlite.SQLiteException in project platform_frameworks_base by android.
the class DrmManagerClient method convertUriToPath.
/**
* This method expects uri in the following format
* content://media/<table_name>/<row_index> (or)
* file://sdcard/test.mp4
* http://test.com/test.mp4
*
* Here <table_name> shall be "video" or "audio" or "images"
* <row_index> the index of the content in given table
*/
private String convertUriToPath(Uri uri) {
String path = null;
if (null != uri) {
String scheme = uri.getScheme();
if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
path = uri.getPath();
} else if (scheme.equals("http")) {
path = uri.toString();
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
String[] projection = new String[] { MediaStore.MediaColumns.DATA };
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
throw new IllegalArgumentException("Given Uri could not be found" + " in media store");
}
int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(pathIndex);
} catch (SQLiteException e) {
throw new IllegalArgumentException("Given Uri is not formatted in a way " + "so that it can be found in media store.");
} finally {
if (null != cursor) {
cursor.close();
}
}
} else {
throw new IllegalArgumentException("Given Uri scheme is not supported");
}
}
return path;
}
use of android.database.sqlite.SQLiteException in project DBFlow by Raizlabs.
the class BaseDatabaseHelper method executeCreations.
/**
* This method executes CREATE TABLE statements as well as CREATE VIEW on the database passed.
*/
protected void executeCreations(final DatabaseWrapper database) {
try {
database.beginTransaction();
List<ModelAdapter> modelAdapters = databaseDefinition.getModelAdapters();
for (ModelAdapter modelAdapter : modelAdapters) {
try {
database.execSQL(modelAdapter.getCreationQuery());
} catch (SQLiteException e) {
FlowLog.logError(e);
}
}
// create our model views
List<ModelViewAdapter> modelViews = databaseDefinition.getModelViewAdapters();
for (ModelViewAdapter modelView : modelViews) {
QueryBuilder queryBuilder = new QueryBuilder().append("CREATE VIEW IF NOT EXISTS").appendSpaceSeparated(modelView.getViewName()).append("AS ").append(modelView.getCreationQuery());
try {
database.execSQL(queryBuilder.getQuery());
} catch (SQLiteException e) {
FlowLog.logError(e);
}
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
}
Aggregations