List of usage examples for android.database.sqlite SQLiteDatabase execSQL
public void execSQL(String sql, Object[] bindArgs) throws SQLException
From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java
protected int update(SQLiteDatabase database, String sql, Object[] values, int[] types) { try {/* w ww. ja v a 2s .c o m*/ if (values != null) { database.execSQL(sql, toStringArray(values)); } else { database.execSQL(sql); } return queryForObject(database, "select changes()", Integer.class); } catch (Exception ex) { throw translate(ex); } }
From source file:com.futureplatforms.kirin.extensions.databases.DatabasesBackend.java
protected void execSQL(SQLiteDatabase db, String sql, Object[] params) { db.execSQL(sql, params); }
From source file:com.flowzr.activity.MainActivity.java
private void updateFieldInTable(SQLiteDatabase db, String table, long id, String field, String value) { db.execSQL("update " + table + " set " + field + "=? where _id=?", new Object[] { value, id }); }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private void mergeDbs() { Log.d(LOG_TAG, "update received - juggling dbs"); // Get main database, attach temp db to it. SQLiteDatabase mainDb = dataService.getHelper().getWritableDatabase(); mainDb.execSQL("attach database ? as ka_temp", new Object[] { dataService.getDatabasePath("ka_temp").getAbsolutePath() }); mainDb.beginTransaction();// www. j av a 2s . com try { // Maintain download status. String sql = "select max(download_status), dlm_id, youtube_id from video where download_status != ? group by youtube_id"; Cursor c = mainDb.rawQuery(sql, new String[] { "" + Video.DL_STATUS_NOT_STARTED }); Cursor c1; String[] videoIds = new String[c.getCount()]; int i = 0; while (c.moveToNext()) { String youtube_id = c.getString(c.getColumnIndex("youtube_id")); String download_status = c.getString(c.getColumnIndex("max(download_status)")); long dlm_id = c.getLong(c.getColumnIndex("dlm_id")); videoIds[i++] = youtube_id; ContentValues v = new ContentValues(); v.put("download_status", download_status); v.put("dlm_id", dlm_id); String[] idArg = new String[] { youtube_id }; mainDb.update("ka_temp.video", v, "youtube_id = ?", idArg); // cursor over parent topics of this video sql = "select ka_temp.topic._id from ka_temp.topic, ka_temp.topicvideo, ka_temp.video where ka_temp.video.youtube_id=? and ka_temp.topicvideo.video_id=ka_temp.video.readable_id and ka_temp.topicvideo.topic_id=ka_temp.topic._id"; c1 = mainDb.rawQuery(sql, idArg); Log.d(LOG_TAG, String.format("updating counts for %d topics", c1.getCount())); while (c1.moveToNext()) { String topicId = c1.getString(c1.getColumnIndex("_id")); DatabaseHelper.incrementDownloadedVideoCounts(mainDb, topicId, "ka_temp.topic"); } c1.close(); } c.close(); mainDb.execSQL("delete from topic"); mainDb.execSQL("insert into topic select * from ka_temp.topic"); mainDb.execSQL("delete from topicvideo"); mainDb.execSQL("insert into topicvideo select * from ka_temp.topicvideo"); mainDb.execSQL("delete from video"); mainDb.execSQL("insert into video select * from ka_temp.video"); mainDb.setTransactionSuccessful(); } finally { mainDb.endTransaction(); mainDb.execSQL("detach database ka_temp"); } Log.d(LOG_TAG, "finished juggling"); }
From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java
private void deleteRunningBalance(long accountId, long transactionId, long amount, long dateTime) { if (accountId <= 0) { return;//from ww w . j a va 2 s . com } SQLiteDatabase db = db(); db.execSQL(DELETE_RUNNING_BALANCE, new Object[] { accountId, transactionId }); db.execSQL(UPDATE_RUNNING_BALANCE, new Object[] { -amount, accountId, dateTime }); }
From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java
private void insertRunningBalance(long accountId, long transactionId, long datetime, long amount, long deltaAmount) { if (accountId <= 0) { return;//from ww w . j av a 2 s. co m } long previousTransactionBalance = fetchAccountBalanceAtTheTime(accountId, datetime); SQLiteDatabase db = db(); db.execSQL(INSERT_RUNNING_BALANCE, new Object[] { accountId, transactionId, datetime, previousTransactionBalance + amount }); db.execSQL(UPDATE_RUNNING_BALANCE, new Object[] { deltaAmount, accountId, datetime }); }
From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java
private void updateLastUsed(Transaction t) { SQLiteDatabase db = db(); if (t.isTransfer()) { db.execSQL(ACCOUNT_LAST_ACCOUNT_UPDATE, new Object[] { t.toAccountId, t.fromAccountId }); }/*from www . j a va2s. c o m*/ db.execSQL(ACCOUNT_LAST_CATEGORY_UPDATE, new Object[] { t.categoryId, t.fromAccountId }); db.execSQL(PAYEE_LAST_CATEGORY_UPDATE, new Object[] { t.categoryId, t.payeeId }); db.execSQL(CATEGORY_LAST_PROJECT_UPDATE, new Object[] { t.projectId, t.categoryId }); }
From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java
private void breakSplitTransactions(Account account, long date) { SQLiteDatabase db = db(); long dayEnd = DateUtils.atDayEnd(date); db.execSQL(BREAK_SPLIT_TRANSACTIONS_1, new Object[] { account.id, dayEnd }); db.execSQL(BREAK_SPLIT_TRANSACTIONS_2, new Object[] { account.id, dayEnd }); db.delete(//from w w w.j a v a2s .com TRANSACTION_ATTRIBUTE_TABLE, TransactionAttributeColumns.TRANSACTION_ID + " in (SELECT _id from " + TRANSACTION_TABLE + " where " + TransactionColumns.datetime + "<=?)", new String[] { String.valueOf(dayEnd) }); }
From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java
/** * Re-populates running_balance for specific account * * @param account selected account/*from ww w. j a v a2 s. com*/ */ public void rebuildRunningBalanceForAccount(Account account) { SQLiteDatabase db = db(); db.beginTransaction(); try { String accountId = String.valueOf(account.getId()); db.execSQL("delete from running_balance where account_id=?", new Object[] { accountId }); WhereFilter filter = new WhereFilter(""); filter.put(Criteria.eq(BlotterFilter.FROM_ACCOUNT_ID, accountId)); filter.asc("datetime"); filter.asc("_id"); Cursor c = getBlotterForAccountWithSplits(filter); Object[] values = new Object[4]; values[0] = accountId; try { long balance = 0; while (c.moveToNext()) { long parentId = c.getLong(BlotterColumns.parent_id.ordinal()); int isTransfer = c.getInt(BlotterColumns.is_transfer.ordinal()); if (parentId > 0) { if (isTransfer >= 0) { // we only interested in the second part of the transfer-split // which is marked with is_transfer=-1 (see v_blotter_for_account_with_splits) continue; } } long fromAccountId = c.getLong(BlotterColumns.from_account_id.ordinal()); long toAccountId = c.getLong(BlotterColumns.to_account_id.ordinal()); if (toAccountId > 0 && toAccountId == fromAccountId) { // weird bug when a transfer is done from an account to the same account continue; } balance += c.getLong(DatabaseHelper.BlotterColumns.from_amount.ordinal()); values[1] = c.getString(DatabaseHelper.BlotterColumns._id.ordinal()); values[2] = c.getString(DatabaseHelper.BlotterColumns.datetime.ordinal()); values[3] = balance; db.execSQL( "insert into running_balance(account_id,transaction_id,datetime,balance) values (?,?,?,?)", values); } } finally { c.close(); } updateAccountLastTransactionDate(account.id); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java
public int deleteAccount(long id) { SQLiteDatabase db = db(); db.beginTransaction();/*from ww w.j a v a 2s . c o m*/ try { String[] sid = new String[] { String.valueOf(id) }; Account a = load(Account.class, id); writeDeleteLog(TRANSACTION_TABLE, a.remoteKey); db.execSQL(UPDATE_ORPHAN_TRANSACTIONS_1, sid); db.execSQL(UPDATE_ORPHAN_TRANSACTIONS_2, sid); db.delete(TRANSACTION_ATTRIBUTE_TABLE, TransactionAttributeColumns.TRANSACTION_ID + " in (SELECT _id from " + TRANSACTION_TABLE + " where " + TransactionColumns.from_account_id + "=?)", sid); db.delete(TRANSACTION_TABLE, TransactionColumns.from_account_id + "=?", sid); int count = db.delete(ACCOUNT_TABLE, "_id=?", sid); db.setTransactionSuccessful(); return count; } finally { db.endTransaction(); } }