use of com.squareup.sqldelight.SqlDelightStatement in project sqldelight by square.
the class IntegrationTests method compiledStatementAcrossThread.
@Test
public void compiledStatementAcrossThread() throws InterruptedException {
SqliteKeywords.Insert_stmt statement = new SqliteKeywords.Insert_stmt(database);
statement.bind(11, 21);
statement.program.executeInsert();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
synchronized (statement) {
statement.bind(12, 22);
statement.program.executeInsert();
latch.countDown();
}
}
}).start();
assertTrue(latch.await(10, SECONDS));
SqlDelightStatement selectAll = SqliteKeywords.FACTORY.select_all();
Cursor cursor = database.rawQuery(selectAll.statement, selectAll.args);
long current = 10;
while (cursor.moveToNext()) {
assertThat(cursor.getLong(cursor.getColumnIndexOrThrow(SqliteKeywords.WHERE))).isEqualTo(current++);
}
}
use of com.squareup.sqldelight.SqlDelightStatement in project sqldelight by square.
the class IntegrationTests method compiledStatement.
@Test
public void compiledStatement() {
SqliteKeywords.Insert_stmt statement = new SqliteKeywords.Insert_stmt(database);
statement.bind(11, 21);
statement.program.executeInsert();
statement.bind(12, 22);
statement.program.executeInsert();
SqlDelightStatement selectAll = SqliteKeywords.FACTORY.select_all();
Cursor cursor = database.rawQuery(selectAll.statement, selectAll.args);
long current = 10;
while (cursor.moveToNext()) {
assertThat(cursor.getLong(cursor.getColumnIndexOrThrow(SqliteKeywords.WHERE))).isEqualTo(current++);
}
}
use of com.squareup.sqldelight.SqlDelightStatement in project sqldelight by square.
the class IntegrationTests method indexedArgs.
@Test
public void indexedArgs() {
// ?1 is the only arg
SqlDelightStatement equivalentNames = Person.FACTORY.equivalent_names("Bob");
Cursor cursor = database.rawQuery(equivalentNames.statement, equivalentNames.args);
assertThat(cursor.getCount()).isEqualTo(1);
cursor.moveToFirst();
Person person = Person.FACTORY.equivalent_namesMapper().map(cursor);
assertThat(person).isEqualTo(new AutoValue_Person(4, "Bob", "Bob"));
}
use of com.squareup.sqldelight.SqlDelightStatement in project sqldelight by square.
the class IntegrationTests method indexedArgLastTwo.
@Test
public void indexedArgLastTwo() {
// First arg declared is ?, second arg declared is ?2.
SqlDelightStatement indexedArgLast = Person.FACTORY.indexed_arg_last_2("Alec", "Strong");
Cursor cursor = database.rawQuery(indexedArgLast.statement, indexedArgLast.args);
assertThat(cursor.getCount()).isEqualTo(1);
cursor.moveToFirst();
Person person = Person.FACTORY.equivalent_namesMapper().map(cursor);
assertThat(person).isEqualTo(new AutoValue_Person(1, "Alec", "Strong"));
}
use of com.squareup.sqldelight.SqlDelightStatement in project sqldelight by square.
the class IntegrationTests method sqliteKeywordColumnString.
@Test
public void sqliteKeywordColumnString() {
SqlDelightStatement selectAll = SqliteKeywords.FACTORY.select_all();
Cursor cursor = database.rawQuery(selectAll.statement, selectAll.args);
assertThat(cursor.getCount()).isEqualTo(1);
cursor.moveToFirst();
long where = cursor.getLong(cursor.getColumnIndexOrThrow(SqliteKeywords.WHERE));
assertThat(where).isEqualTo(10);
}
Aggregations