io.requery.android.database.sqlite.SQLiteDatabase Java Examples
The following examples show how to use
io.requery.android.database.sqlite.SQLiteDatabase.
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 File: DatabaseErrorHandlerTest.java From sqlite-android with Apache License 2.0 | 6 votes |
public void onCorruption(SQLiteDatabase dbObj) { boolean databaseOk = dbObj.isDatabaseIntegrityOk(); // close the database try { dbObj.close(); } catch (SQLiteException e) { /* ignore */ } if (databaseOk) { // database is just fine. no need to delete the database file Log.e("CorruptionHandler", "no corruption in the database: " + mDatabaseFile.getPath()); } else { // database is corrupt. delete the database file Log.e("CorruptionHandler", "deleting the database file: " + mDatabaseFile.getPath()); new File(dbDir, DB_NAME).delete(); } }
Example #2
Source File: DB.java From FairEmail with GNU General Public License v3.0 | 6 votes |
@Override public void init(@NonNull DatabaseConfiguration configuration) { // https://www.sqlite.org/pragma.html#pragma_wal_autocheckpoint if (BuildConfig.DEBUG) { File dbfile = configuration.context.getDatabasePath(DB_NAME); if (dbfile.exists()) { try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbfile.getPath(), null, SQLiteDatabase.OPEN_READWRITE)) { Log.i("DB checkpoint=" + DB_CHECKPOINT); try (Cursor cursor = db.rawQuery("PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT + ";", null)) { cursor.moveToNext(); // required } } } } super.init(configuration); }
Example #3
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 6 votes |
public static void update29(SQLiteDatabase db) { String tableName = DBHelper.T_LOG_TRANSACTIONS; String columnName = DBHelper.C_LOG_TRANSACTIONS_COMMENT; db.execSQL("ALTER TABLE " + tableName + " ADD COLUMN SearchString TEXT;"); db.execSQL("ALTER TABLE " + DBHelper.T_REF_SENDERS + " ADD COLUMN "+DBHelper.C_REF_SENDERS_ADD_CREDIT_LIMIT_TO_BALANCE+" INTEGER NOT NULL DEFAULT 0;"); Cursor cursor = db.query(tableName, new String[]{DBHelper.C_ID, columnName}, "Deleted = 0", null, null, null, null); ContentValues cv = new ContentValues(); try { if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { cv.clear(); cv.put("SearchString", Translit.toTranslit(cursor.getString(1).toLowerCase())); db.update(tableName, cv, "_id = " + cursor.getString(0), null); cursor.moveToNext(); } } } finally { cursor.close(); } }
Example #4
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 6 votes |
public static void update31(SQLiteDatabase db, Context context) { db.execSQL("ALTER TABLE " + DBHelper.T_REF_PROJECTS + " ADD COLUMN "+DBHelper.C_REF_PROJECTS_COLOR+" TEXT DEFAULT '#ffffff';"); Cursor cursorProjects = db.rawQuery("SELECT _id FROM ref_Projects", null); List<Long> projectIDs = new ArrayList<>(); if (cursorProjects != null) { try { if (cursorProjects.moveToFirst()) { while (!cursorProjects.isAfterLast()) { projectIDs.add(cursorProjects.getLong(0)); cursorProjects.moveToNext(); } } } finally { cursorProjects.close(); } } ContentValues cv = new ContentValues(); for (long id : projectIDs) { cv.clear(); cv.put(DBHelper.C_REF_PROJECTS_COLOR, String.format("#%06X", (0xFFFFFF & ColorUtils.getColor(context)))); db.update(DBHelper.T_REF_PROJECTS, cv, String.format("_id = %s", String.valueOf(id)), null); } }
Example #5
Source File: DBHelper.java From fingen with Apache License 2.0 | 6 votes |
public synchronized static int getMaxDel(SQLiteDatabase db, String tableName) { Cursor cursor = db.query(tableName, new String[]{String.format("MAX(%s) AS MAXDEL", DBHelper.C_SYNC_DELETED)}, null, null, null, null, null); int maxDel = 0; if (cursor != null) { try { if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { maxDel = cursor.getInt(0); cursor.moveToNext(); } } } finally { cursor.close(); } } return maxDel; }
Example #6
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 6 votes |
@MediumTest @Test public void testCustomFunction() { mDatabase.addCustomFunction("roundFunction", 1, new SQLiteDatabase.CustomFunction() { @Override public String callback(String[] args) { String input = args[0]; double value = Double.parseDouble(input); return String.valueOf(Math.round(value)); } }); Cursor cursor = mDatabase.rawQuery("SELECT roundFunction(3.14)", null); assertTrue(cursor.moveToFirst()); int result = cursor.getInt(0); assertSame(3, result); }
Example #7
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 6 votes |
@MediumTest @Test public void testSupportUpdate() { populateDefaultTable(); ContentValues values = new ContentValues(1); values.put("data", "this is an updated test"); assertEquals(1, mDatabase.update("test", SQLiteDatabase.CONFLICT_NONE, values, "_id=?", new Object[] { 1 })); Cursor c = mDatabase.query("test", null, "_id=1", null, null, null, null); assertNotNull(c); assertEquals(1, c.getCount()); c.moveToFirst(); String value = c.getString(c.getColumnIndexOrThrow("data")); assertEquals("this is an updated test", value); }
Example #8
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 6 votes |
@MediumTest @Test public void testSchemaChange1() throws Exception { SQLiteDatabase db1 = mDatabase; Cursor cursor; db1.execSQL("CREATE TABLE db1 (_id INTEGER PRIMARY KEY, data TEXT);"); cursor = db1.query("db1", null, null, null, null, null, null); assertNotNull("Cursor is null", cursor); db1.execSQL("CREATE TABLE db2 (_id INTEGER PRIMARY KEY, data TEXT);"); assertEquals(0, cursor.getCount()); cursor.close(); }
Example #9
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 6 votes |
@SmallTest @Test public void testSetMaxCacheSize() { mDatabase.execSQL("CREATE TABLE test (i int, j int);"); mDatabase.execSQL("insert into test values(1,1);"); // set cache size int N = SQLiteDatabase.MAX_SQL_CACHE_SIZE; mDatabase.setMaxSqlCacheSize(N); // try reduce cachesize try { mDatabase.setMaxSqlCacheSize(1); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("cannot set cacheSize to a value less than")); } }
Example #10
Source File: FtsDbHelper.java From FairEmail with GNU General Public License v3.0 | 6 votes |
static void insert(SQLiteDatabase db, EntityMessage message, String text) { Log.i("FTS insert id=" + message.id); List<Address> address = new ArrayList<>(); if (message.from != null) address.addAll(Arrays.asList(message.from)); if (message.to != null) address.addAll(Arrays.asList(message.to)); if (message.cc != null) address.addAll(Arrays.asList(message.cc)); if (message.bcc != null) address.addAll(Arrays.asList(message.bcc)); delete(db, message.id); ContentValues cv = new ContentValues(); cv.put("rowid", message.id); cv.put("account", message.account); cv.put("folder", message.folder); cv.put("time", message.received); cv.put("address", MessageHelper.formatAddresses(address.toArray(new Address[0]), true, false)); cv.put("subject", message.subject == null ? "" : message.subject); cv.put("keyword", TextUtils.join(", ", message.keywords)); cv.put("text", text); db.insert("message", SQLiteDatabase.CONFLICT_FAIL, cv); }
Example #11
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 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 #12
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 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 long longForQuery(SQLiteDatabase db, String query, String[] selectionArgs) { SQLiteStatement prog = db.compileStatement(query); try { return longForQuery(prog, selectionArgs); } finally { prog.close(); } }
Example #13
Source File: DatabaseCursorTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { File dbDir = ApplicationProvider.getApplicationContext().getDir("tests", Context.MODE_PRIVATE); mDatabaseFile = new File(dbDir, "database_test.db"); if (mDatabaseFile.exists()) { mDatabaseFile.delete(); } mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null); assertNotNull(mDatabase); mDatabase.setVersion(CURRENT_DATABASE_VERSION); }
Example #14
Source File: DatabaseCursorTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@MediumTest @Test public void testRequeryWithAlteredSelectionArgs() { // Test the ability of a subclass of SQLiteCursor to change its query arguments. populateDefaultTable(); SQLiteDatabase.CursorFactory factory = new SQLiteDatabase.CursorFactory() { public Cursor newCursor( SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) { return new SQLiteCursor(masterQuery, editTable, query) { @Override public boolean requery() { setSelectionArguments(new String[]{"2"}); return super.requery(); } }; } }; Cursor c = mDatabase.rawQueryWithFactory( factory, "SELECT data FROM test WHERE _id <= ?", new String[]{"1"}, null); assertNotNull(c); assertEquals(1, c.getCount()); assertTrue(c.moveToFirst()); assertEquals(sString1, c.getString(0)); // Our hacked requery() changes the query arguments in the cursor. c.requery(); assertEquals(2, c.getCount()); assertTrue(c.moveToFirst()); assertEquals(sString1, c.getString(0)); assertTrue(c.moveToNext()); assertEquals(sString2, c.getString(0)); // Test that setting query args on a deactivated cursor also works. c.deactivate(); c.requery(); }
Example #15
Source File: NewDatabasePerformanceTests.java From sqlite-android with Apache License 2.0 | 5 votes |
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressLint("SdCardPath") @Before public void setUp() { mDatabaseFile = new File("/sdcard", "perf_database_test.db"); if (mDatabaseFile.exists()) { mDatabaseFile.delete(); } mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null); assertTrue(mDatabase != null); mDatabase.setVersion(CURRENT_DATABASE_VERSION); }
Example #16
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@MediumTest @Test public void testNewFunctionNoReturn() { mDatabase.addFunction("emptyFunction2", 1, new SQLiteDatabase.Function() { @Override public void callback(Args args, Result result) { } }); Cursor cursor = mDatabase.rawQuery("SELECT emptyFunction2(3.14)", null); // always empty regardless of if sqlite3_result_null is called or not cursor.moveToFirst(); assertSame(null, cursor.getString(0)); }
Example #17
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@MediumTest @Test public void testCustomFunctionNoReturn() { mDatabase.addCustomFunction("emptyFunction", 1, new SQLiteDatabase.CustomFunction() { @Override public String callback(String[] args) { return null; } }); Cursor cursor = mDatabase.rawQuery("SELECT emptyFunction(3.14)", null); // always empty regardless of if sqlite3_result_null is called or not cursor.moveToFirst(); assertSame(null, cursor.getString(0)); }
Example #18
Source File: DatabaseStatementTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { File dbDir = ApplicationProvider.getApplicationContext().getDir("tests", Context.MODE_PRIVATE); mDatabaseFile = new File(dbDir, "database_test.db"); if (mDatabaseFile.exists()) { mDatabaseFile.delete(); } mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null); assertNotNull(mDatabase); mDatabase.setVersion(CURRENT_DATABASE_VERSION); }
Example #19
Source File: DatabaseGeneralTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { File dbDir = ApplicationProvider.getApplicationContext().getDir(this.getClass().getName(), Context.MODE_PRIVATE); mDatabaseFile = new File(dbDir, "database_test.db"); if (mDatabaseFile.exists()) { mDatabaseFile.delete(); } mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null); assertNotNull(mDatabase); mDatabase.setVersion(CURRENT_DATABASE_VERSION); }
Example #20
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 5 votes |
public static void update33(SQLiteDatabase db) { db.execSQL("DELETE FROM log_Products WHERE TransactionID < 0"); Cursor cursor = db.rawQuery("SELECT _id, Amount FROM log_Transactions " + "WHERE _id not in (SELECT TransactionID FROM log_Products) AND Deleted = 0", null); ContentValues cv = new ContentValues(); if (cursor != null) { try { if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { cv.clear(); cv.put(DBHelper.C_SYNC_FBID, ""); cv.put(DBHelper.C_SYNC_TS, -1); cv.put(DBHelper.C_SYNC_DELETED, 0); cv.put(DBHelper.C_SYNC_DIRTY, 0); cv.put(DBHelper.C_SYNC_LASTEDITED, ""); cv.put(DBHelper.C_LOG_PRODUCTS_TRANSACTIONID, cursor.getLong(0)); cv.put(DBHelper.C_LOG_PRODUCTS_PRODUCTID, 0); cv.put(DBHelper.C_LOG_PRODUCTS_CATEGORY_ID, -1); cv.put(DBHelper.C_LOG_PRODUCTS_PROJECT_ID, -1); cv.put(DBHelper.C_LOG_PRODUCTS_PRICE, cursor.getDouble(1)); cv.put(DBHelper.C_LOG_PRODUCTS_QUANTITY, 1); db.insert(DBHelper.T_LOG_PRODUCTS, null, cv); cursor.moveToNext(); } } } finally { cursor.close(); } } }
Example #21
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 5 votes |
public static void update32(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + DBHelper.T_LOG_TRANSACTIONS + " ADD COLUMN "+DBHelper.C_LOG_TRANSACTIONS_SPLIT+" INTEGER DEFAULT 0;"); db.execSQL(DBHelper.SQL_CREATE_TABLE_REF_PRODUCTS); db.execSQL(DBHelper.SQL_CREATE_TABLE_LOG_PRODUCTS); ContentValues cv = new ContentValues(); cv.put(DBHelper.C_ID, 0); cv.put(DBHelper.C_REF_PRODUCTS_NAME, "default_product"); db.insert(DBHelper.T_REF_PRODUCTS, "", cv); Cursor cursorTransactions = db.rawQuery("SELECT _id, Amount FROM log_Transactions WHERE Deleted = 0", null); if (cursorTransactions != null) { try { if (cursorTransactions.moveToFirst()) { while (!cursorTransactions.isAfterLast()) { cv.clear(); cv.put(DBHelper.C_SYNC_FBID, ""); cv.put(DBHelper.C_SYNC_TS, -1); cv.put(DBHelper.C_SYNC_DELETED, 0); cv.put(DBHelper.C_SYNC_DIRTY, 0); cv.put(DBHelper.C_SYNC_LASTEDITED, ""); cv.put(DBHelper.C_LOG_PRODUCTS_TRANSACTIONID, cursorTransactions.getLong(0)); cv.put(DBHelper.C_LOG_PRODUCTS_PRODUCTID, 0); cv.put(DBHelper.C_LOG_PRODUCTS_CATEGORY_ID, -1); cv.put(DBHelper.C_LOG_PRODUCTS_PROJECT_ID, -1); cv.put(DBHelper.C_LOG_PRODUCTS_PRICE, cursorTransactions.getDouble(1)); cv.put(DBHelper.C_LOG_PRODUCTS_QUANTITY, 1); db.insert(DBHelper.T_LOG_PRODUCTS, null, cv); cursorTransactions.moveToNext(); } } } finally { cursorTransactions.close(); } } db.execSQL("CREATE INDEX [idx_Products] ON [log_Products] ([Deleted], [TransactionID], [ProductID]);"); }
Example #22
Source File: DatabaseErrorHandlerTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { dbDir = ApplicationProvider.getApplicationContext().getDir(this.getClass().getName(), Context.MODE_PRIVATE); mDatabaseFile = new File(dbDir, DB_NAME); if (mDatabaseFile.exists()) { mDatabaseFile.delete(); } mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, new MyDatabaseCorruptionHandler()); assertNotNull(mDatabase); }
Example #23
Source File: DatabaseErrorHandlerTest.java From sqlite-android with Apache License 2.0 | 5 votes |
@Test 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()); // since the database file is now corrupt, doing any sql on this database connection // should trigger call to MyDatabaseCorruptionHandler.onCorruption try { mDatabase.execSQL("select * from t;"); fail("expected exception"); } catch (SQLiteDiskIOException e) { // // this test used to produce a corrupted db. but with new sqlite it instead reports // Disk I/O error. meh.. // need to figure out how to cause corruption in db // // expected if (mDatabaseFile.exists()) { mDatabaseFile.delete(); } } catch (SQLiteException ignored) { } // 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()); }
Example #24
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 5 votes |
public static void update26(SQLiteDatabase db) { Cursor cursorIndexes = db.rawQuery("PRAGMA index_list(log_Transactions)", null); if (cursorIndexes.getCount() == 0) { db.execSQL("CREATE INDEX [idx] ON [log_Transactions] ([Deleted], [DateTime], [SrcAccount], [DestAccount], [Payee], [Category], [Project], [Department], [Location], [SimpleDebt]);"); } cursorIndexes.close(); }
Example #25
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 5 votes |
public static void update24(SQLiteDatabase db) { db.execSQL("CREATE TABLE ref_Accounts_Sets (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, FBID TEXT, TS INTEGER, Deleted INTEGER, Dirty INTEGER, LastEdited TEXT, Name TEXT, UNIQUE (Name, Deleted) ON CONFLICT ABORT);"); db.execSQL("CREATE TABLE log_Accounts_Sets (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, FBID TEXT, TS INTEGER, Deleted INTEGER, Dirty INTEGER, LastEdited TEXT, SetID INTEGER NOT NULL ON CONFLICT ABORT REFERENCES [ref_Accounts_Sets]([_id]) ON DELETE CASCADE ON UPDATE CASCADE,AccountID INTEGER NOT NULL ON CONFLICT ABORT REFERENCES [ref_Accounts]([_id]) ON DELETE CASCADE ON UPDATE CASCADE,UNIQUE (SetID, AccountID, Deleted) ON CONFLICT ABORT);"); ContentValues values = new ContentValues(); values.put("Lat", 0); db.update("log_Transactions", values, "Lat IS NULL", null); values.clear(); values.put("Lon", 0); db.update("log_Transactions", values, "Lon IS NULL", null); values.clear(); values.put("Accuracy", -1); db.update("log_Transactions", values, "Accuracy IS NULL", null); values.clear(); values.put("SimpleDebt", -1); db.update("log_Transactions", values, "SimpleDebt IS NULL", null); values.clear(); values.put("ParentID", -1); db.update("ref_Categories", values, "ParentID IS NULL", null); db.execSQL("CREATE INDEX [idx] ON [log_Transactions] ([Deleted], [DateTime], [SrcAccount], [DestAccount], [Payee], [Category], [Project], [Department], [Location], [SimpleDebt]);"); }
Example #26
Source File: UpdateHelper.java From fingen with Apache License 2.0 | 5 votes |
public static void update23(SQLiteDatabase db) { ContentValues cv = new ContentValues(); cv.put("OrderNumber", 0); db.execSQL("ALTER TABLE ref_Currencies RENAME TO ref_Currencies_old"); db.execSQL("CREATE TABLE ref_Currencies (_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, FBID TEXT, TS INTEGER, Deleted INTEGER, Dirty INTEGER, LastEdited TEXT, Code TEXT NOT NULL, Symbol TEXT NOT NULL, Name TEXT NOT NULL, DecimalCount INTEGER NOT NULL, OrderNumber INTEGER, UNIQUE (Code, Deleted) ON CONFLICT ABORT);"); db.execSQL( "INSERT INTO ref_Currencies (_id, FBID, TS, Deleted, Dirty, LastEdited, Code, Symbol, Name, DecimalCount) " + "SELECT _id, FBID, TS, Deleted, Dirty, LastEdited, Code, Symbol, Name, DecimalCount " + "FROM ref_Currencies_old"); db.execSQL("DROP TABLE ref_Currencies_old"); db.update("ref_Currencies", cv, null, null); }
Example #27
Source File: DBHelper.java From fingen with Apache License 2.0 | 5 votes |
public void rebuildDB() throws IOException { SQLiteDatabase db = getDatabase(); db.beginTransaction(); String tableNames[] = new String[]{T_REF_ACCOUNTS, T_REF_ACCOUNTS_SETS, T_LOG_ACCOUNTS_SETS, T_REF_CATEGORIES, T_REF_PAYEES, T_REF_PROJECTS, T_REF_LOCATIONS, T_REF_DEPARTMENTS, T_REF_SIMPLEDEBTS, T_LOG_TRANSACTIONS, T_LOG_TEMPLATES, T_LOG_INCOMING_SMS, T_LOG_SMS_PARSER_PATTERNS, T_REF_DEBTS, T_LOG_BUDGET, T_LOG_BUDGET_DEBTS, T_REF_SENDERS, T_REF_PRODUCTS, T_LOG_PRODUCTS }; for (String tableName : tableNames) { db.delete(tableName, "Deleted > 0", null); } updateFullNames("ref_Categories", true, db); updateFullNames("ref_Payees", true, db); updateFullNames("ref_Projects", true, db); updateFullNames("ref_Locations", true, db); updateFullNames("ref_Departments", true, db); updateFullNames("ref_Accounts", false, db); updateFullNames("ref_SimpleDebts", false, db); updateFullNames("log_Templates", false, db); updateRunningBalance(db); updateLogProducts(db); db.setTransactionSuccessful(); db.endTransaction(); db.execSQL("VACUUM"); }
Example #28
Source File: DBHelper.java From fingen with Apache License 2.0 | 5 votes |
public void updateRunningBalance(SQLiteDatabase database) throws IOException { String sql[] = readQueryFromAssets("sql/update_running_balance.sql", mContext); for (String s : sql) { if (s != null && !s.isEmpty() && !s.equals("\n")) { android.util.Log.d(TAG, s); database.execSQL(s); } } }
Example #29
Source File: DBHelper.java From fingen with Apache License 2.0 | 5 votes |
public void updateLogProducts(SQLiteDatabase db) throws IOException { db.execSQL("DELETE FROM log_Products WHERE TransactionID < 0"); Cursor cursor = db.rawQuery("SELECT _id, Amount FROM log_Transactions " + "WHERE _id not in (SELECT TransactionID FROM log_Products) AND Deleted = 0", null); ContentValues cv = new ContentValues(); if (cursor != null) { try { if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { cv.clear(); cv.put(DBHelper.C_SYNC_FBID, ""); cv.put(DBHelper.C_SYNC_TS, -1); cv.put(DBHelper.C_SYNC_DELETED, 0); cv.put(DBHelper.C_SYNC_DIRTY, 0); cv.put(DBHelper.C_SYNC_LASTEDITED, ""); cv.put(DBHelper.C_LOG_PRODUCTS_TRANSACTIONID, cursor.getLong(0)); cv.put(DBHelper.C_LOG_PRODUCTS_PRODUCTID, 0); cv.put(DBHelper.C_LOG_PRODUCTS_CATEGORY_ID, -1); cv.put(DBHelper.C_LOG_PRODUCTS_PROJECT_ID, -1); cv.put(DBHelper.C_LOG_PRODUCTS_PRICE, cursor.getDouble(1)); cv.put(DBHelper.C_LOG_PRODUCTS_QUANTITY, 1); db.insert(DBHelper.T_LOG_PRODUCTS, null, cv); cursor.moveToNext(); } } } finally { cursor.close(); } } }
Example #30
Source File: BaseDAO.java From fingen with Apache License 2.0 | 5 votes |
private void init(SQLiteDatabase database, String tableName, int modelType, String allColumns[]) { mDatabase = database; mDaoInheritor = null; mTableName = tableName; mModelType = modelType; mAllColumns = allColumns; mColumnIndexes = new HashMap<>(); Cursor cursor = mDatabase.query(getTableName(), null, C_ID + " < 0", null, null, null, null); if (cursor != null) { for (String column : mAllColumns) { mColumnIndexes.put(column, cursor.getColumnIndex(column)); } } }