use of android.database.sqlite.SQLiteDatabase in project newsrob by marianokamp.
the class DB method updateStatesFromTempTable.
public void updateStatesFromTempTable(ArticleDbState state) {
Timing t = new Timing("DB.updateStatesFromTempTable state=" + state, context);
String stateColumn = null;
String statePendingColumn = null;
int targetValueOn = 1;
int targetValueOff = 0;
if (state == ArticleDbState.READ) {
stateColumn = Entries.READ_STATE;
statePendingColumn = Entries.READ_STATE_PENDING;
targetValueOn = 0;
targetValueOff = 1;
} else if (state == ArticleDbState.STARRED) {
stateColumn = Entries.STARRED_STATE;
statePendingColumn = Entries.STARRED_STATE_PENDING;
} else if (state == ArticleDbState.SHARED) {
stateColumn = Entries.SHARED_STATE;
statePendingColumn = Entries.SHARED_STATE_PENDING;
} else if (state == ArticleDbState.LIKED) {
stateColumn = Entries.LIKED_STATE;
statePendingColumn = Entries.LIKED_STATE_PENDING;
}
if (stateColumn == null)
throw new IllegalStateException("stateColumn must not be null here.");
SQLiteDatabase dbase = getDb();
dbase.beginTransaction();
// Mark all articles as read where the read_state is not pending
// and they were not read before
Timing t3 = new Timing("DB.updateStatesFromTempTable - mark existing read", context);
final String markExistingSQL = "UPDATE " + Entries.TABLE_NAME + " SET " + stateColumn + " = " + targetValueOff + " WHERE " + stateColumn + " = " + targetValueOn + " AND " + statePendingColumn + " = 0;";
dbase.execSQL(markExistingSQL);
t3.stop();
// Mark all articles unread that exists in the temp table and are not
// read state pending
Timing t4 = new Timing("DB.updateStatesFromTempTable - mark as x", context);
String sql = context.getString(R.string.sql_mark_as_x);
sql = sql.replaceAll("-STATE-", stateColumn);
sql = sql.replaceAll("-STATE_PENDING-", statePendingColumn);
sql = sql.replaceAll("-SET-", targetValueOn + "");
sql = sql.replaceAll("-CLEAR-", targetValueOff + "");
dbase.execSQL(sql);
t4.stop();
if (state == ArticleDbState.READ) {
Timing t5 = new Timing("DB.updateReadStates - mark as read even when pinned", context);
dbase.execSQL(context.getString(R.string.sql_mark_as_read_even_when_pinned));
t5.stop();
}
dbase.setTransactionSuccessful();
dbase.endTransaction();
t.stop();
}
use of android.database.sqlite.SQLiteDatabase in project newsrob by marianokamp.
the class DB method clearTempTable.
public void clearTempTable() {
Timing t = new Timing("DB.clearTempTable", context);
SQLiteDatabase dbase = getDb();
dbase.beginTransaction();
dbase.execSQL(CLEAR_TEMP_TABLE_SQL);
dbase.setTransactionSuccessful();
dbase.endTransaction();
t.stop();
}
use of android.database.sqlite.SQLiteDatabase in project newsrob by marianokamp.
the class DB method populateTempIds.
public void populateTempIds(TempTable tempTableType, long[] articleIds) {
SQLiteDatabase dbase = getDb();
final String createTableDDL = expandTempTableName(CREATE_TABLE_TEMP_IDS_SQL, tempTableType);
PL.log("Executing sql=" + createTableDDL, context);
dbase.execSQL(createTableDDL);
clearTempTable(tempTableType);
Timing t = new Timing("DB.populateTempIds " + tempTableType + " count=" + articleIds.length, context);
PL.log("DB.populateTempIds(" + tempTableType + "): number of article ids=" + articleIds.length, context);
// offset points at the current element, 0 meaning the first element
int offset = 0;
while (offset < articleIds.length) {
int nextPackSize = Math.min(articleIds.length - offset, 30);
// if (nextPackSize == 0)
// break;
SQLiteStatement stmt = null;
try {
dbase.beginTransaction();
stmt = dbase.compileStatement(expandTempTableName("INSERT INTO temp_ids values(?);", tempTableType));
for (int j = offset; j < offset + nextPackSize && j < articleIds.length; j++) {
long l = articleIds[j];
// "tag:google.com,2005:reader/item/"
String id = EntriesRetriever.TAG_GR_ITEM + U.longToHex(l);
stmt.bindString(1, id);
stmt.execute();
}
offset += nextPackSize;
} finally {
if (stmt != null)
stmt.close();
dbase.setTransactionSuccessful();
dbase.endTransaction();
}
Thread.yield();
}
t.stop();
}
use of android.database.sqlite.SQLiteDatabase in project sqlbrite by square.
the class BriteDatabase method insert.
/**
* Insert a row into the specified {@code table} and notify any subscribed queries.
*
* @see SQLiteDatabase#insertWithOnConflict(String, String, ContentValues, int)
*/
@WorkerThread
public long insert(@NonNull String table, @NonNull ContentValues values, @ConflictAlgorithm int conflictAlgorithm) {
SQLiteDatabase db = getWritableDatabase();
if (logging) {
log("INSERT\n table: %s\n values: %s\n conflictAlgorithm: %s", table, values, conflictString(conflictAlgorithm));
}
long rowId = db.insertWithOnConflict(table, null, values, conflictAlgorithm);
if (logging)
log("INSERT id: %s", rowId);
if (rowId != -1) {
// Only send a table trigger if the insert was successful.
sendTableTrigger(Collections.singleton(table));
}
return rowId;
}
use of android.database.sqlite.SQLiteDatabase in project sqldelight by square.
the class PlayersActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
ButterKnife.bind(this);
SQLiteDatabase db = HockeyOpenHelper.getInstance(this).getReadableDatabase();
long teamId = getIntent().getLongExtra(TEAM_ID, -1);
if (teamId == -1) {
playersCursor = db.rawQuery(Player.SELECT_ALL, new String[0]);
} else {
SqlDelightStatement playerForTeam = Player.FACTORY.for_team(teamId);
playersCursor = db.rawQuery(playerForTeam.statement, playerForTeam.args);
}
players.setAdapter(new PlayersAdapter(this, playersCursor));
}
Aggregations