oplaTech About Teaching Archive
Oplatek's external memory

Debugging Sqlite in Android

Is android uncapable creating two tables? UPDATED



Firstly, I want to create 2 tables called objSources and preferences.
Secondly, I failed...:) (I hope only for today)
SOLUTION: DO NOT EXECUTE MULTIPLE COMMANDS AT ONE CALL


String SQL = "create table A ( integer t); create table B ( integer t2 );" ;
// does not work, but does not throw and Exception
Cursor c = mDb.rawQuery(, null);



During the debugging I realise that is could be good to print SQL queries to LogCat


Log.i(TAG,MY_SQL);
Cursor c = mDb.rawQuery(MY_SQL, null);



Unfortunately, Android and Sqlite3 on my Ubuntu 11.10 differs in executing the same queries. I tried both ways by exactly copy and pasting the command (I made the whole circle: Copied from LogCat, pasted in Sqlite3, worked OK so I pasted it back to Android app).



To be concrete following query does not work for me.
Firstly, the more readable version.


create table objSources(
_id integer primary key autoincrement,
title text not null, path text,
resource_id integer default -1,
info text not null
);

create table preferences(
_id integer primary key autoincrement,
preference text not null,
preference_state text not null
);
insert into preferences
(preference,preference_state) values ('db_loaded','no');

The copy pasted one liner:

create table objSources(
_id integer primary key autoincrement, title text not null, path text, resource_id integer default -1, info text not null); create table preferences( _id integer primary key autoincrement, preference text not null, preference_state text not null); insert into preferences (preference,preference_state) values ('db_loaded','no');



Btw. I wrote a snippet to print all tables in my android app


Cursor t =mDb.rawQuery("select name from sqlite_master;",null);
int ind = t.getColumnIndex("name");
t.moveToFirst();
Log.i(TAG, t.getString(ind));
while(t.moveToNext()) {
Log.i(TAG, t.getString(ind));
}