android - Executing multiple statements with SQLiteDatabase.execSQL -



android - Executing multiple statements with SQLiteDatabase.execSQL -

i've followed standard tutorial building database android. i've created class called dbhelper extends sqliteopenhelper. i've overridden create handler execute string.

@override public void oncreate(sqlitedatabase db) { db.execsql(dbdefinitions.db_create); }

dbdefinitions.db_create static string i've created.

public static final string table_messages = "messages"; public static final string table_friends = "friends"; public static final string state_ok = "state_ok"; public static final string db_create = "create table " + table_messages + " (_id integer primary key, user_id integer not null, created_on integer, subject text not null, summary text not null, messagetext text null, read integer not null, status text not null default '" + state_ok + "'); " + "create table " + table_friends + " (_id integer primary key, user_id integer not null, friend_id integer not null, created_on integer, status text not null default '" + state_ok + "');";

i'd utilize 1 string execute multiple sql statements. how can sqlitedatabase.execsql allows 1 statement?

that's not possible using standard methods comes android. so, if want execute batch of multiple sql statements, have create own utility so. instance, can have this:

public void executebatchsql(string sql){ // utilize stringtokenizer separate sql statements each sql statement{ database.execsql(onestatement); } }

though, i'd this:

string sql1 = "create bla bla bla;"; string sql2 = "create foo bar;"; string[] statements = new string[]{sql1, sql2}; // for(string sql : statements){ database.execsql(sql); }

android database sqlite sqlite3

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -