Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid's SQLite, how to turn Cursors into strings?
    primarykey
    data
    text
    <p>Say I have such helper:</p> <pre><code>public class SqlHelper extends SQLiteOpenHelper { public SqlHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE MyTable (ID INTEGER PRIMARY KEY, NAME TEXT, PLACE TEXT)"); db.execSQL("INSERT INTO MyTable (NAME, PLACE) VALUES('ANTHONY','USA')"); db.execSQL("INSERT INTO MyTable (NAME, PLACE) VALUES('BERIMOR','UK')"); db.execSQL("INSERT INTO MyTable (NAME, PLACE) VALUES('IVAN','RUSSIA')"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } } </code></pre> <p>and in my main code I execute a query </p> <pre><code> SqlHelper sqlHelper = new SqlHelper(this, "MyDataBase.db", null, 1); SQLiteDatabase DB = sqlHelper.getReadableDatabase(); Cursor c = DB.query( "MyTable" /* table */, new String[] { "PLACE" } /* columns */, "id = ?" /* where or selection */, new String[] { "RUSSIA" } /* selectionArgs */, null /* groupBy */, null /* having */, null /* orderBy */ ); DB.close(); </code></pre> <p>But I'm not sure what that cursor thing is? Shouldn't it be something like an array? And if so, how do I get original values ( strings ) out of it? Like this query should return 'IVAN'.</p> <p>Thanks!</p> <p>EDIT2 :</p> <p>This ( c.getCount() ) still returns 0, i.e. no results... hmm... maybe then there's something with the helper?</p> <pre><code> Cursor c = DB.query( "MyTable" /* table */, new String[] { "NAME" } /* columns */, "PLACE = 'RUSSIA'" /* where or selection */, null /* selectionArgs */, null /* groupBy */, null /* having */, null /* orderBy */ ); Log.e("DB RETURNS", String.valueOf( c.getCount() ) ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload