use of com.pushtorefresh.storio3.sqlite.queries.Query in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method shouldPassSQLWithArgsToExecSQL.
@Test
public void shouldPassSQLWithArgsToExecSQL() {
RawQuery rawQuery = RawQuery.builder().query("DROP TABLE users").args("arg1", "arg2").build();
storIOSQLite.lowLevel().executeSQL(rawQuery);
verify(sqLiteOpenHelper).getWritableDatabase();
verify(sqLiteDatabase).execSQL(eq(rawQuery.query()), eq(new String[] { "arg1", "arg2" }));
verifyNoMoreInteractions(sqLiteOpenHelper, sqLiteDatabase);
}
use of com.pushtorefresh.storio3.sqlite.queries.Query in project storio by pushtorefresh.
the class DefaultStorIOContentResolverTest method shouldThrowExceptionIfContentResolverReturnsNull.
@Test
public void shouldThrowExceptionIfContentResolverReturnsNull() {
ContentResolver contentResolver = mock(ContentResolver.class);
StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(contentResolver).build();
Query query = Query.builder().uri(mock(Uri.class)).build();
when(contentResolver.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())).thenReturn(// Notice, we return null instead of Cursor
null);
try {
storIOContentResolver.lowLevel().query(query);
} catch (IllegalStateException expected) {
assertThat(expected).hasMessage("Cursor returned by content provider is null");
}
}
use of com.pushtorefresh.storio3.sqlite.queries.Query in project storio by pushtorefresh.
the class DefaultPutResolver method performPut.
/**
* {@inheritDoc}
*/
@NonNull
@Override
public PutResult performPut(@NonNull StorIOContentResolver storIOContentResolver, @NonNull T object) {
final UpdateQuery updateQuery = mapToUpdateQuery(object);
final Query query = Query.builder().uri(updateQuery.uri()).where(nullableString(updateQuery.where())).whereArgs((Object[]) nullableArrayOfStringsFromListOfStrings(updateQuery.whereArgs())).build();
final StorIOContentResolver.LowLevel lowLevel = storIOContentResolver.lowLevel();
final Cursor cursor = lowLevel.query(query);
try {
final ContentValues contentValues = mapToContentValues(object);
if (cursor.getCount() == 0) {
final InsertQuery insertQuery = mapToInsertQuery(object);
final Uri insertedUri = lowLevel.insert(insertQuery, contentValues);
return PutResult.newInsertResult(insertedUri, insertQuery.uri());
} else {
final int numberOfRowsUpdated = lowLevel.update(updateQuery, contentValues);
return PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.uri());
}
} finally {
cursor.close();
}
}
use of com.pushtorefresh.storio3.sqlite.queries.Query in project storio by pushtorefresh.
the class GetNumberOfResultsObserveChangesTest method repeatsOperationWithQueryByChangeOfTable.
@Test
public void repeatsOperationWithQueryByChangeOfTable() {
putUserBlocking();
PreparedGetNumberOfResults operation = storIOSQLite.get().numberOfResults().withQuery(query).prepare();
verifyChangesReceived(operation, tableChanges, 1);
}
use of com.pushtorefresh.storio3.sqlite.queries.Query in project storio by pushtorefresh.
the class ExecSQLTest method shouldReturnQueryInGetData.
@Test
public void shouldReturnQueryInGetData() {
final RawQuery query = RawQuery.builder().query(// we don't want to really delete table
"DROP TABLE IF EXISTS no_such_table").build();
final PreparedExecuteSQL operation = storIOSQLite.executeSQL().withQuery(query).prepare();
assertThat(operation.getData()).isEqualTo(query);
}
Aggregations