SQLite doesn't work with Android -
i got simple example (inside button onclicklistener, information):
databasehandler dbhandler = new databasehandler( v.getcontext(), v.getcontext().getresources().getstring(r.string.database_name)); dbhandler.getwritabledatabase().execsql("create table if not exists test (abc text);"); dbhandler.getwritabledatabase().rawquery("insert test (abc) values ('blah');", null); cursor test = dbhandler.getreadabledatabase().rawquery("select * test;", null); log.e("test", test.tostring()); log.e("test", string.valueof(test.getcount()));
class:
public class databasehandler extends sqliteopenhelper { private static int database_version = 2; public databasehandler(context context, string dbname) { super(context, dbname, null, database_version); } @override public void oncreate(sqlitedatabase db) { // todo auto-generated method stub } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // todo auto-generated method stub } }
output (its button, clicked 3 times):
04-07 01:31:51.047: e/test(11816): android.database.sqlite.sqlitecursor@42e97400 04-07 01:31:51.047: e/test(11816): 0 04-07 01:31:51.677: e/test(11816): android.database.sqlite.sqlitecursor@42ed3980 04-07 01:31:51.677: e/test(11816): 0 04-07 01:31:52.428: e/test(11816): android.database.sqlite.sqlitecursor@42e755d8 04-07 01:31:52.438: e/test(11816): 0
i don't find whats wrong it. couple of minutes ago got working. don't know why stopped working of sudden though. see mistake?
seems rawquery
not work insert
-statements. using execsql
works.
Comments
Post a Comment