Search in sources :

Example 6 with SqlDelightStatement

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++);
    }
}
Also used : SqlDelightStatement(com.squareup.sqldelight.SqlDelightStatement) CountDownLatch(java.util.concurrent.CountDownLatch) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 7 with SqlDelightStatement

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++);
    }
}
Also used : SqlDelightStatement(com.squareup.sqldelight.SqlDelightStatement) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 8 with SqlDelightStatement

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"));
}
Also used : SqlDelightStatement(com.squareup.sqldelight.SqlDelightStatement) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 9 with SqlDelightStatement

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"));
}
Also used : SqlDelightStatement(com.squareup.sqldelight.SqlDelightStatement) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 10 with SqlDelightStatement

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);
}
Also used : SqlDelightStatement(com.squareup.sqldelight.SqlDelightStatement) Cursor(android.database.Cursor) Test(org.junit.Test)

Aggregations

SqlDelightStatement (com.squareup.sqldelight.SqlDelightStatement)12 Cursor (android.database.Cursor)11 Test (org.junit.Test)11 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 CountDownLatch (java.util.concurrent.CountDownLatch)1