Android SQLite Create Multiple Tables Error -
im having weird crash when creating multiple sqlite tables...
the code works fine if comment out line execute create_movements_table.
the first table created without problem, if try create both, app crashes.
the weird thing is: if test app on phone without creating second table, works fine, ... if test again (with app installed), 2 sql statements, (creating both tables), app works... problem occurs when app not present @ in phone
import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import java.util.arraylist; import java.util.list; public class databasehandler extends sqliteopenhelper { private static final int database_version = 1; private static final string database_name = "clientsmanager"; private static final string clients_table = "clients"; private static final string movements_table = "movements"; //client table columns private static final string key_rowid = "numint"; private static final string key_name = "name"; private static final string key_local = "locality"; private static final string key_addr = "address"; private static final string key_bttlp = "bottle_price"; private static final string key_pblnc = "prev_balance"; private static final string key_blnc = "balance"; private static final string key_bbttls = "bonif_bottles"; private static final string key_pbttls = "prev_bottles"; private static final string key_bttls = "bottles"; private static final string key_sync = "sync_date"; private static final string key_modif = "modif_date"; //movements table columns private static final string mkey_rowid = "numint"; private static final string mkey_id_move = "move_id"; private static final string mkey_client_id = "client_id"; private static final string mkey_pickup = "pickup"; private static final string mkey_deliver = "deliver"; private static final string mkey_payment = "payment"; private static final string mkey_move_date = "move_date"; private static final string mkey_sync_date = "sync_date"; private static final string mkey_flag_sync = "flag_sync"; public databasehandler(context context) { super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase sqlitedatabase) { string create_clients_table = "create table " + clients_table + "(" + key_rowid + " integer primary key autoincrement not null, " + key_name + " text not null, " + key_local + " text not null, " + key_addr + " text not null, " + key_bttlp + " real not null, " + key_pblnc + " real not null, " + key_blnc + " real not null, " + key_bbttls + " integer not null, " + key_pbttls + " integer not null, " + key_bttls + " integer not null, " + key_sync + " text not null, " + key_modif + " text not null )"; string create_movements_table = "create table " + movements_table + "(" + mkey_rowid + " integer primary key autoincrement not null, " + mkey_id_move + "text not null" + mkey_client_id + " integer not null, " + mkey_pickup + " integer not null, " + mkey_deliver + " integer not null, " + mkey_payment + " real not null, " + mkey_move_date + " text not null, " + mkey_sync_date + " text not null, " + mkey_flag_sync + " integer not null )"; sqlitedatabase.execsql(create_clients_table); sqlitedatabase.execsql(create_movements_table); } @override public void onupgrade(sqlitedatabase sqlitedatabase, int oldversion, int newversion) { sqlitedatabase.execsql("drop table if exists " + clients_table); sqlitedatabase.execsql("drop table if exists " + movements_table); oncreate(sqlitedatabase); }
you forgetting put space , comma in +mkey_id_move + "text not null"
string create_movements_table = "create table " + movements_table + "(" + mkey_rowid + " integer primary key autoincrement not null, " + mkey_id_move + " text not null," + mkey_client_id + " integer not null, " + mkey_pickup + " integer not null, " + mkey_deliver + " integer not null, " + mkey_payment + " real not null, " + mkey_move_date + " text not null, " + mkey_sync_date + " text not null, " + mkey_flag_sync + " integer not null )";
also use try catch sqlitedatabase.execsql
try { sqlitedatabase.execsql(create_clients_table); } catch(exception e) { } try { sqlitedatabase.execsql(create_movements_table); } catch(exception e) { }
Comments
Post a Comment