use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method shouldPassSQLWithoutArgsToExecSQL.
@Test
public void shouldPassSQLWithoutArgsToExecSQL() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
SQLiteDatabase sqLiteDatabase = mock(SQLiteDatabase.class);
when(sqLiteOpenHelper.getWritableDatabase()).thenReturn(sqLiteDatabase);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
RawQuery rawQuery = RawQuery.builder().query("DROP TABLE IF EXISTS someTable").build();
storIOSQLite.lowLevel().executeSQL(rawQuery);
verify(sqLiteOpenHelper).getWritableDatabase();
verify(sqLiteDatabase).execSQL(eq(rawQuery.query()));
verifyNoMoreInteractions(sqLiteOpenHelper, sqLiteDatabase);
}
use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesAndNotifyAboutChangesShouldWorkCorrectly.
@Test
public void observeChangesAndNotifyAboutChangesShouldWorkCorrectly() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
storIOSQLite.observeChanges().subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes = Changes.newInstance("test_table");
storIOSQLite.lowLevel().notifyAboutChanges(changes);
testSubscriber.assertValue(changes);
testSubscriber.assertNoErrors();
testSubscriber.unsubscribe();
}
use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsNullIfSpecifiedSchedulerNull.
@Test
public void defaultSchedulerReturnsNullIfSpecifiedSchedulerNull() {
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).defaultScheduler(null).build();
assertThat(storIOSQLite.defaultScheduler()).isNull();
}
use of android.database.sqlite.SQLiteOpenHelper in project zxingfragmentlib by mitoyarzun.
the class HistoryManager method addHistoryItemDetails.
public void addHistoryItemDetails(String itemID, String itemDetails) {
// As we're going to do an update only we don't need need to worry
// about the preferences; if the item wasn't saved it won't be udpated
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getWritableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, ID_DETAIL_COL_PROJECTION, DBHelper.TEXT_COL + "=?", new String[] { itemID }, null, null, DBHelper.TIMESTAMP_COL + " DESC", "1");
String oldID = null;
String oldDetails = null;
if (cursor.moveToNext()) {
oldID = cursor.getString(0);
oldDetails = cursor.getString(1);
}
if (oldID != null) {
String newDetails;
if (oldDetails == null) {
newDetails = itemDetails;
} else if (oldDetails.contains(itemDetails)) {
newDetails = null;
} else {
newDetails = oldDetails + " : " + itemDetails;
}
if (newDetails != null) {
ContentValues values = new ContentValues();
values.put(DBHelper.DETAILS_COL, newDetails);
db.update(DBHelper.TABLE_NAME, values, DBHelper.ID_COL + "=?", new String[] { oldID });
}
}
} finally {
close(cursor, db);
}
}
use of android.database.sqlite.SQLiteOpenHelper in project zxingfragmentlib by mitoyarzun.
the class HistoryManager method buildHistory.
/**
* <p>Builds a text representation of the scanning history. Each scan is encoded on one
* line, terminated by a line break (\r\n). The values in each line are comma-separated,
* and double-quoted. Double-quotes within values are escaped with a sequence of two
* double-quotes. The fields output are:</p>
*
* <ul>
* <li>Raw text</li>
* <li>Display text</li>
* <li>Format (e.g. QR_CODE)</li>
* <li>Timestamp</li>
* <li>Formatted version of timestamp</li>
* </ul>
*/
CharSequence buildHistory() {
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getWritableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
StringBuilder historyText = new StringBuilder(1000);
while (cursor.moveToNext()) {
historyText.append('"').append(massageHistoryField(cursor.getString(0))).append("\",");
historyText.append('"').append(massageHistoryField(cursor.getString(1))).append("\",");
historyText.append('"').append(massageHistoryField(cursor.getString(2))).append("\",");
historyText.append('"').append(massageHistoryField(cursor.getString(3))).append("\",");
// Add timestamp again, formatted
long timestamp = cursor.getLong(3);
historyText.append('"').append(massageHistoryField(format.format(new Date(timestamp)))).append("\",");
// Above we're preserving the old ordering of columns which had formatted data in position 5
historyText.append('"').append(massageHistoryField(cursor.getString(4))).append("\"\r\n");
}
return historyText;
} finally {
close(cursor, db);
}
}
Aggregations