Java Code Examples for org.sqlite.database.sqlite.SQLiteDatabase

The following examples show how to use org.sqlite.database.sqlite.SQLiteDatabase. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: SQLite   Source File: SQLiteContentProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public final Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    String table = getType(uri);
    if (TextUtils.isEmpty(table)) {
        throw new IllegalArgumentException("No such table to query");
    } else {
        return database.query(table,
                projection,
                selection,
                selectionArgs,
                null,
                null,
                sortOrder);
    }
}
 
Example 2
Source Project: SQLite   Source File: SQLiteContentProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    String table = getType(uri);
    if (TextUtils.isEmpty(table)) {
        throw new IllegalArgumentException("No such table to insert");
    } else {
        int numInserted = 0;
        database.beginTransaction();
        try {
            for (ContentValues contentValues : values) {
                long id = database.insertWithOnConflict(table, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
                if (id > 0) {
                    numInserted++;
                }
            }
            database.setTransactionSuccessful();
        } finally {
            database.endTransaction();
        }
        return numInserted;
    }
}
 
Example 3
Source Project: AndroidSchool   Source File: RequestTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    TableBuilder.create(this)
            .textColumn(REQUEST)
            .textColumn(STATUS)
            .textColumn(ERROR)
            .primaryKey(REQUEST)
            .execute(database);
}
 
Example 4
Source Project: AndroidSchool   Source File: CityTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    TableBuilder.create(this)
            .textColumn(CITY_NAME)
            .textColumn(WEATHER)
            .textColumn(MAIN)
            .textColumn(WIND)
            .execute(database);
}
 
Example 5
Source Project: AndroidSchool   Source File: WeatherCityTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    TableBuilder.create(this)
            .textColumn(CITY_ID)
            .textColumn(CITY_NAME)
            .primaryKey(CITY_ID)
            .execute(database);
}
 
Example 6
Source Project: AndroidSchool   Source File: CityTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    TableBuilder.create(this)
            .textColumn(CITY_NAME)
            .textColumn(WEATHER)
            .textColumn(MAIN)
            .textColumn(WIND)
            .execute(database);
}
 
Example 7
Source Project: SQLite   Source File: SQLiteContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public final Uri insert(@NonNull Uri uri, ContentValues values) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    String table = getType(uri);
    if (TextUtils.isEmpty(table)) {
        throw new IllegalArgumentException("No such table to insert");
    } else {
        long id = database.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        return ContentUris.withAppendedId(uri, id);
    }
}
 
Example 8
Source Project: SQLite   Source File: SQLiteContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    String table = getType(uri);
    if (TextUtils.isEmpty(table)) {
        throw new IllegalArgumentException("No such table to delete");
    } else {
        return database.delete(table, selection, selectionArgs);
    }
}
 
Example 9
Source Project: SQLite   Source File: SQLiteContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final int update(@NonNull Uri uri, ContentValues values,
                  String selection, String[] selectionArgs) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    String table = getType(uri);
    if (TextUtils.isEmpty(table)) {
        throw new IllegalArgumentException("No such table to update");
    } else {
        return database.update(table, values, selection, selectionArgs);
    }
}
 
Example 10
Source Project: SQLite   Source File: SQLiteHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
    for (Table table : mSchema) {
        if (oldVersion < newVersion && newVersion <= table.getLastUpgradeVersion()) {
            table.onUpgrade(database);
        }
    }
}
 
Example 11
Source Project: SQLite   Source File: TestTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    TableBuilder.create(this)
            .intColumn(ID)
            .realColumn(RATING)
            .textColumn(TEXT)
            .primaryKey(ID)
            .execute(database);
}
 
Example 12
Source Project: SQLite   Source File: JUnitTestTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    TableBuilder.create(this)
            .intColumn(ID)
            .realColumn(RATING)
            .textColumn(TEXT)
            .primaryKey(ID)
            .execute(database);
}
 
Example 13
Source Project: squidb   Source File: TestReactiveDatabase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onConfigure(ISQLiteDatabase db) {
    /** @see AttachDetachTest#testAttacherInTransactionOnAnotherThread() */
    Object wrappedObject = db.getWrappedObject();
    if (wrappedObject instanceof SQLiteDatabase) {
        ((SQLiteDatabase) wrappedObject).enableWriteAheadLogging();
    } else if (wrappedObject instanceof android.database.sqlite.SQLiteDatabase) {
        ((android.database.sqlite.SQLiteDatabase) wrappedObject).enableWriteAheadLogging();
    }
}
 
Example 14
Source Project: squidb   Source File: ExtraUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to run the query on the db and return the value in the
 * first column of the first row.
 */
public static long longForQuery(
    SQLiteDatabase db, String query, String[] selectionArgs
) {
    SQLiteStatement prog = db.compileStatement(query);
    try {
        return longForQuery(prog, selectionArgs);
    } finally {
        prog.close();
    }
}
 
Example 15
Source Project: imsdk-android   Source File: DatabaseHelper.java    License: MIT License 4 votes vote down vote up
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    super.onDowngrade(db, oldVersion, newVersion);
}
 
Example 16
Source Project: SQLite   Source File: TableBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public void execute(@NonNull SQLiteDatabase database) {
    database.execSQL(buildSQL());
}
 
Example 17
Source Project: SQLite   Source File: SQLiteHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database) {
    for (Table table : mSchema) {
        table.onCreate(database);
    }
}
 
Example 18
Source Project: SQLite   Source File: BaseTable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onUpgrade(@NonNull SQLiteDatabase database) {
    database.execSQL("DROP TABLE IF EXISTS " + getTableName());
    onCreate(database);
}
 
Example 19
Source Project: SQLite   Source File: ContentProviderErrorsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(@NonNull SQLiteDatabase database) {
    throw new RuntimeException("Stub!");
}
 
Example 20
Source Project: squidb   Source File: SQLiteBindingsCursorFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) {
    bindArgumentsToProgram(query, sqlArgs);
    return new SQLiteCursor(masterQuery, editTable, query);
}
 
Example 21
Source Project: squidb   Source File: SQLiteBindingsAdapter.java    License: Apache License 2.0 4 votes vote down vote up
public SQLiteBindingsAdapter(SQLiteDatabase db) {
    if (db == null) {
        throw new NullPointerException("Can't create SQLiteDatabaseAdapter with a null SQLiteDatabase");
    }
    this.db = db;
}
 
Example 22
Source Project: squidb   Source File: SQLiteBindingsAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SQLiteDatabase getWrappedObject() {
    return db;
}
 
Example 23
Source Project: squidb   Source File: SQLiteBindingsOpenHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ISQLiteDatabase openForWriting() {
    SQLiteDatabase database = super.getWritableDatabase();
    return new SQLiteBindingsAdapter(database);
}
 
Example 24
Source Project: squidb   Source File: SQLiteBindingsOpenHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase db) {
    delegate.onCreate(new SQLiteBindingsAdapter(db));
}
 
Example 25
Source Project: squidb   Source File: SQLiteBindingsOpenHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    delegate.onUpgrade(new SQLiteBindingsAdapter(db), oldVersion, newVersion);
}
 
Example 26
Source Project: squidb   Source File: SQLiteBindingsOpenHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    delegate.onDowngrade(new SQLiteBindingsAdapter(db), oldVersion, newVersion);
}
 
Example 27
Source Project: squidb   Source File: SQLiteBindingsOpenHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onConfigure(SQLiteDatabase db) {
    delegate.onConfigure(new SQLiteBindingsAdapter(db));
}
 
Example 28
Source Project: squidb   Source File: SQLiteBindingsOpenHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onOpen(SQLiteDatabase db) {
    delegate.onOpen(new SQLiteBindingsAdapter(db));
}
 
Example 29
Source Project: SQLite   Source File: Table.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * This method creates and adds table to the database.
 *
 * You can create it manually with SQL, but it's recommended to use {@link ru.arturvasilov.sqlite.utils.TableBuilder}
 *
 * @param database - instance of SQLite database where you should create the table
 */
void onCreate(@NonNull SQLiteDatabase database);
 
Example 30
Source Project: SQLite   Source File: Table.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * This method is provided for data migration purposes.
 *
 * In this method you should decide how you want to update this table
 * (how data migration works - {@link Table#getLastUpgradeVersion()}
 *
 * Default implementation in {@link BaseTable} simple drops table and call {@link Table#onCreate(SQLiteDatabase)}
 *
 * @param database - instance of SQLite database where you should update the table
 */
void onUpgrade(@NonNull SQLiteDatabase database);