Java Code Examples for android.database.sqlite.SQLiteDatabase.compileStatement()

The following are Jave code examples for showing how to use compileStatement() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PeSanKita-android   File: SmsDatabase.java   View Source Code Vote up 6 votes
SQLiteStatement createInsertStatement(SQLiteDatabase database) {
  return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " +
                                                                    PERSON + ", " +
                                                                    DATE_SENT + ", " +
                                                                    DATE_RECEIVED  + ", " +
                                                                    PROTOCOL + ", " +
                                                                    READ + ", " +
                                                                    STATUS + ", " +
                                                                    TYPE + ", " +
                                                                    REPLY_PATH_PRESENT + ", " +
                                                                    SUBJECT + ", " +
                                                                    BODY + ", " +
                                                                    SERVICE_CENTER +
                                                                    ", " + THREAD_ID + ") " +
                                   " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
}
 
Example 2
Project: buildAPKsApps   File: DataManager.java   View Source Code Vote up 6 votes
public int createItem(int list_id, String label)
{
    Log.v(L.TAG, "DataManager.createItem(): Insert item " + label);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("insert into items (list_id,label,active) values (?,?,?)");        
    stmt.bindLong(1, list_id);
    stmt.bindString(2, label);
    stmt.bindLong(3, 1);
    long id = stmt.executeInsert();
    stmt.close();
    db.close();
    
    Log.d(L.TAG, "DataManager.createItem(): Inserted item and got id " + id);
    if(id == -1)
    {
        Log.e(L.TAG, "DataManager.createItem(): Attempt to insert item failed. Got " + id + " from executeInsert()");
    }
    return (int)id;
}
 
Example 3
Project: healthvault-java-sdk   File: ViewProvider.java   View Source Code Vote up 6 votes
public Uri insert(Uri uri, ContentValues values) {
	SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();
	
	List<String> segments = uri.getPathSegments();
	String recordId = segments.get(1);
	String name = segments.get(3);

       String insertView = "Insert or replace into views (record_id, name, query, date_synced) values(?,?,?,?)";

       SQLiteStatement insertViewStmt = sqlDb.compileStatement(insertView);

       insertViewStmt.bindString(1, recordId);
       insertViewStmt.bindString(2, name);
       insertViewStmt.bindString(3, values.getAsString("query"));
       insertViewStmt.bindString(4, values.getAsString("date_synced"));
       insertViewStmt.execute();
       
       getContext()
               .getContentResolver()
               .notifyChange(uri, null);
      
       return uri;
}
 
Example 4
Project: openlocate-android   File: LocationTable.java   View Source Code Vote up 6 votes
static void addAll(SQLiteDatabase database, List<OpenLocateLocation> locations) {
    if (database == null || locations == null || locations.isEmpty()) {
        return;
    }

    SQLiteStatement statement = database.compileStatement(BULK_INSERT_LOCATION);

    database.beginTransaction();
    for (OpenLocateLocation location : locations) {
        statement.clearBindings();
        statement.bindString(COLUMN_LOCATION_INDEX, location.getJson().toString());
        statement.bindLong(2, location.getCreated().getTime());
        statement.execute();
    }

    database.setTransactionSuccessful();
    database.endTransaction();
}
 
Example 5
Project: Android-SQLite-Master-Project   File: UserMessagesRelationDao.java   View Source Code Vote up 6 votes
public static void saveUserMessagesRelations(@NonNull SQLiteDatabase database,
                                             @NonNull User user) {
    if (Utils.isNullOrEmpty(user.getMessages())) {
        return;
    }

    final SQLiteStatement statement = database.compileStatement(UserMessagesRelationContract.Script.Insert.INSERT);
    try {
        database.beginTransaction();
        for (Message message : user.getMessages())
            insertUserMessage(statement, user.getId(), message.getId());
        database.setTransactionSuccessful();
    } finally {
        database.setTransactionSuccessful();
    }
}
 
Example 6
Project: buildAPKsApps   File: DataManager.java   View Source Code Vote up 5 votes
private int countItemsInList(SQLiteDatabase db, int listId)
{
    SQLiteStatement stmt = db.compileStatement("select count(*) from items where list_id=?");        
    stmt.bindLong(1, listId);
    int rv = (int)stmt.simpleQueryForLong();
    stmt.close();
    
    return rv;
}
 
Example 7
Project: KBUnitTest   File: ShadowDatabaseUtils.java   View Source Code Vote up 5 votes
/**
 * Utility method to run the query on the db and return the blob value in the
 * first column of the first row.
 *
 * @return A read-only file descriptor for a copy of the blob value.
 */
public static ParcelFileDescriptor blobFileDescriptorForQuery(SQLiteDatabase db,
                                                              String query, String[] selectionArgs) {
    SQLiteStatement prog = db.compileStatement(query);
    try {
        return blobFileDescriptorForQuery(prog, selectionArgs);
    } finally {
        prog.close();
    }
}
 
Example 8
Project: SQLite-Performance   File: DbHelper.java   View Source Code Vote up 5 votes
private void createFiles(SQLiteDatabase db) {
    mFileNames = new String[mFiles];
    byte[] rawData = new byte[mFileSize+mFiles];
    Random random = new Random();
    random.nextBytes(rawData);

    ByteArrayOutputStream[] streams = new ByteArrayOutputStream[mFiles];
    for (int i = 0; i < mFiles; i++) {
        streams[i] = new ByteArrayOutputStream(mFileSize);
        streams[i].write(rawData, i, mFileSize);
        mFileNames[i] = String.valueOf(i);
    }

    SQLiteStatement insert = db.compileStatement("INSERT INTO files (filename, data) VALUES (?, ?)");
    for (int i = 0; i < mFiles; i++) {
        insert.bindString(1, mFileNames[i]);
        insert.bindBlob(2, streams[i].toByteArray());

        insert.execute();
    }
}
 
Example 9
Project: MapaDeIgarassu   File: DataBaseUtil.java   View Source Code Vote up 5 votes
public void updateLocation(LocationModel locationModel) {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement(Constants.UPDATE_TABLE_LOCATION);
    stmt.bindString(1, locationModel.getName());
    stmt.bindDouble(2, locationModel.getLongitude());
    stmt.bindDouble(3, locationModel.getLatitude());
    stmt.bindString(4, locationModel.getAddress());
    stmt.bindString(5, locationModel.getDescription());
    stmt.bindLong(6, locationModel.getId());
    stmt.execute();
}
 
Example 10
Project: sealtalk-android-master   File: RongDatabaseDriver.java   View Source Code Vote up 5 votes
private <T> T executeInsert(
        SQLiteDatabase database,
        String query,
        ExecuteResultHandler<T> handler) {
    SQLiteStatement statement = database.compileStatement(query);
    long count = statement.executeInsert();
    return handler.handleInsert(count);
}
 
Example 11
Project: Android-SQLite-Master-Project   File: UserDao.java   View Source Code Vote up 5 votes
public static User save(@NonNull SQLiteDatabase database, @NonNull User user) {
    final SQLiteStatement statement = database.compileStatement(UserContract.Script.Insert.INSERT);
    try {
        database.beginTransaction();
        insertUser(statement, user);
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
    return user;
}
 
Example 12
Project: buildAPKsApps   File: DataManager.java   View Source Code Vote up 5 votes
private int countInactiveItemsInList(SQLiteDatabase db, int listId)
{
    SQLiteStatement stmt = db.compileStatement("select count(*) from items where list_id=? and active=1");        
    stmt.bindLong(1, listId);
    int rv = (int)stmt.simpleQueryForLong();
    stmt.close();
    
    return rv;
}
 
Example 13
Project: buildAPKsApps   File: DataManager.java   View Source Code Vote up 5 votes
public void deleteItem(int itemId)
{
    Log.d(L.TAG, "Deleting item " + itemId);

    SQLiteDatabase db = helper.getWritableDatabase();
    
    SQLiteStatement stmt = db.compileStatement("delete from items where id=?");        
    stmt.bindLong(1, itemId);
    stmt.execute();
    stmt.close();
    db.close();
}
 
Example 14
Project: weex-uikit   File: DefaultWXStorage.java   View Source Code Vote up 5 votes
private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
    SQLiteDatabase database = mDatabaseSupplier.getDatabase();
    if (database == null) {
        return false;
    }

    WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
    String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
    SQLiteStatement statement = null;
    String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
    try {
        statement = database.compileStatement(sql);
        statement.clearBindings();
        statement.bindString(1, key);
        statement.bindString(2, value);
        statement.bindString(3, timeStamp);
        statement.bindLong(4, isPersistent ? 1 : 0);
        statement.execute();
        return true;
    } catch (Exception e) {
        WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
        if (e instanceof SQLiteFullException) {
            if (allowRetryWhenFull && trimToSize()) {
                //try again
                //setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
                WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
                return performSetItem(key, value, isPersistent, false);
            }
        }

        return false;
    } finally {
        if(statement != null) {
            statement.close();
        }
    }
}
 
Example 15
Project: KBUnitTest   File: ShadowDatabaseUtils.java   View Source Code Vote up 5 votes
/**
 * Utility method to run the query on the db and return the value in the
 * first column of the first row.
 */
public static String stringForQuery(SQLiteDatabase db, String query, String[] selectionArgs) {
    SQLiteStatement prog = db.compileStatement(query);
    try {
        return stringForQuery(prog, selectionArgs);
    } finally {
        prog.close();
    }
}
 
Example 16
Project: buildAPKsApps   File: DataManager.java   View Source Code Vote up 5 votes
public void updateItemLabel(int itemId, String newLabel)
{
    Log.d(L.TAG, "Updating label of item " + itemId + " to " + newLabel);

    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("update items set label=? where id=?");        
    stmt.bindString(1, newLabel);
    stmt.bindLong(2, itemId);
    stmt.execute();
    stmt.close();
    db.close();
}
 
Example 17
Project: buildAPKsApps   File: DataManager.java   View Source Code Vote up 5 votes
public void moveItem(int itemId, int toListId)
{
    Log.d(L.TAG, "Moving item " + itemId + " to list " + toListId);
    
    SQLiteDatabase db = helper.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement("update items set list_id=? where id=?");        
    stmt.bindLong(1, toListId);
    stmt.bindLong(2, itemId);
    stmt.execute();
    stmt.close();
    db.close();
}
 
Example 18
Project: MapaDeIgarassu   File: DataBaseUtil.java   View Source Code Vote up 4 votes
public void deleteLocation(int locationId) {
    SQLiteDatabase db = this.getWritableDatabase();
    SQLiteStatement stmt = db.compileStatement(Constants.DELETE_LOCATION);
    stmt.bindLong(1, locationId);
    stmt.execute();
}
 
Example 19
Project: SimpleUILauncher   File: LauncherProvider.java   View Source Code Vote up 4 votes
/**
 * Replaces all shortcuts of type {@link Favorites#ITEM_TYPE_SHORTCUT} which have a valid
 * launcher activity target with {@link Favorites#ITEM_TYPE_APPLICATION}.
 */
@Thunk void convertShortcutsToLauncherActivities(SQLiteDatabase db) {
    db.beginTransaction();
    Cursor c = null;
    SQLiteStatement updateStmt = null;

    try {
        // Only consider the primary user as other users can't have a shortcut.
        long userSerial = getDefaultUserSerial();
        c = db.query(Favorites.TABLE_NAME, new String[] {
                Favorites._ID,
                Favorites.INTENT,
            }, "itemType=" + Favorites.ITEM_TYPE_SHORTCUT + " AND profileId=" + userSerial,
            null, null, null, null);

        updateStmt = db.compileStatement("UPDATE favorites SET itemType="
                + Favorites.ITEM_TYPE_APPLICATION + " WHERE _id=?");

        final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
        final int intentIndex = c.getColumnIndexOrThrow(Favorites.INTENT);

        while (c.moveToNext()) {
            String intentDescription = c.getString(intentIndex);
            Intent intent;
            try {
                intent = Intent.parseUri(intentDescription, 0);
            } catch (URISyntaxException e) {
                Log.e(TAG, "Unable to parse intent", e);
                continue;
            }

            if (!Utilities.isLauncherAppTarget(intent)) {
                continue;
            }

            long id = c.getLong(idIndex);
            updateStmt.bindLong(1, id);
            updateStmt.executeUpdateDelete();
        }
        db.setTransactionSuccessful();
    } catch (SQLException ex) {
        Log.w(TAG, "Error deduping shortcuts", ex);
    } finally {
        db.endTransaction();
        if (c != null) {
            c.close();
        }
        if (updateStmt != null) {
            updateStmt.close();
        }
    }
}
 
Example 20
Project: healthvault-java-sdk   File: ViewThingsProvider.java   View Source Code Vote up 4 votes
public int delete(Uri uri, String selection, String[] selectionArgs) {
	// TODO: Delete things not shared with other views
	
	SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();

	List<String> segments = uri.getPathSegments();

	String recordId = segments.get(1);
	String name = segments.get(3);

	String deleteView = "delete from view_things where record_id = ? and view_name = ?";
       SQLiteStatement deleteViewStmt = sqlDb.compileStatement(deleteView);

	deleteViewStmt.bindString(1, recordId);
	deleteViewStmt.bindString(2, name);
	
	int rc = deleteViewStmt.executeUpdateDelete();
	
	getContext()
               .getContentResolver()
               .notifyChange(uri, null);

	return rc;
}