Search in sources :

Example 76 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class DatabaseStatementTest method testExecuteStatement.

@MediumTest
public void testExecuteStatement() throws Exception {
    populateDefaultTable();
    SQLiteStatement statement = mDatabase.compileStatement("DELETE FROM test");
    statement.execute();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    assertEquals(0, c.getCount());
    c.deactivate();
    statement.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 77 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class DatabaseStatementTest method testStatementStringBinding.

@MediumTest
public void testStatementStringBinding() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num TEXT);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (long i = 0; i < 10; i++) {
        statement.bindString(1, Long.toHexString(i));
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int numCol = c.getColumnIndexOrThrow("num");
    c.moveToFirst();
    for (long i = 0; i < 10; i++) {
        String num = c.getString(numCol);
        assertEquals(Long.toHexString(i), num);
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 78 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class DatabaseStatementTest method testStatementClearBindings.

@MediumTest
public void testStatementClearBindings() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (long i = 0; i < 10; i++) {
        statement.bindLong(1, i);
        statement.clearBindings();
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
    int numCol = c.getColumnIndexOrThrow("num");
    assertTrue(c.moveToFirst());
    for (long i = 0; i < 10; i++) {
        assertTrue(c.isNull(numCol));
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 79 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class SimpleCursorAdapterTest method testChangeCursorLive.

/**
     * Test changeCursor() with live cursor
     */
@SmallTest
public void testChangeCursorLive() {
    SimpleCursorAdapter ca = new SimpleCursorAdapter(mContext, mLayout, mCursor2x2, mFrom, mTo);
    // Now see if we can pull 2 rows from the adapter
    assertEquals(2, ca.getCount());
    // now put in a different cursor (5 rows)
    ArrayList<ArrayList> data2 = createTestList(5, 2);
    Cursor c2 = createCursor(mFrom, data2);
    ca.changeCursor(c2);
    // Now see if we can pull 5 rows from the adapter
    assertEquals(5, ca.getCount());
}
Also used : ArrayList(java.util.ArrayList) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 80 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class ListWithDisappearingItemBug method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Toast.makeText(this, "Make sure you rotate screen to see bug", Toast.LENGTH_LONG).show();
    // Get a cursor with all people
    Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
    startManagingCursor(c);
    ListAdapter adapter = new SimpleCursorAdapter(this, // Use a template that displays a text view
    R.layout.list_with_disappearing_item_bug_item, // Give the cursor to the list adatper
    c, // Map the NAME column in the people database to...
    new String[] { People.NAME }, // The "text1" view defined in the XML template
    new int[] { R.id.text1 });
    setListAdapter(adapter);
    AnimationSet set = new AnimationSet(true);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);
    set.addAnimation(animation);
    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(100);
    set.addAnimation(animation);
    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    ListView listView = getListView();
    listView.setLayoutAnimation(controller);
}
Also used : ListView(android.widget.ListView) SimpleCursorAdapter(android.widget.SimpleCursorAdapter) LayoutAnimationController(android.view.animation.LayoutAnimationController) TranslateAnimation(android.view.animation.TranslateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) TranslateAnimation(android.view.animation.TranslateAnimation) Cursor(android.database.Cursor) AnimationSet(android.view.animation.AnimationSet) ListAdapter(android.widget.ListAdapter) AlphaAnimation(android.view.animation.AlphaAnimation)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75