sql - android sqlite CREATE TABLE IF NOT EXISTS -


Getting a little problem in creating new tables when I use the CREATE TABLE command should my new table form But when I get out of the activity the app crashes and I have a tablet already in the log-in. If I use the table, then it is not that the new table has not been formed, But just the new row of data in my previous table Adds it and it does not crash. what's wrong with that? I would like to add the table without being present already and I would like to add it without adding the rows in a separate table.

SqliteHelper Class:

  public class MySQLiteHelper SQLiteOpenHelper {public static final String TABLE_NAME = MainActivity.NameName; Public static final string COLUMN_ID = "_id"; Public static final string COLUMN_COMMENT = "comment"; Public static final string COLUMN_LAT = "lat"; Public static final string COLUMN_LONG = "tall"; Public static final string COLUMN_RADI = "radi"; Personal Static Last String DATABASE_NAME = "spraylogs.db"; Personal Static FINAL END DATABASE_VERSION = 1; Public static final String NEWTABLE = "CREATE TABLE" + TABLE_COMMENTS + "(" + COLUMN_ID + "integer primary key autoincrement," + COLUMN_COMMENT + "text is not clear," + COLUMN_LAT + "," + COLUMN_LONG + "," + COLUMN_RADI + ");"; Public static final String SaveIt = "Table does not exist to create" + TABLE_COMMENTS + "(" + COLUMN_ID + "integer primary key autoincrement," + COLUMN_COMMENT + "text is not clear," + COLUMN_LAT + "," + COLUMN_LONG + ", "+ COLUMN_RADI +"); "; MySQLiteHelper (References) {super (context, context.getExternalFilesDir (empty) .getAbsolutePath () + "/" + DATABASE_NAME, empty, DATABASE_VERSION); } @Override public void OnCreate (SQLiteDatabase database) {} @Override public void onUpgrade (SQLiteDatabase db, int oldVersion, integer NewVersion) {Log.w (MySQLiteHelper.class.getName (), "version upgrade database" + oldVersion + " For "new version +", which will destroy all old data "); Db.execSQL ("if empty table exists" + new); OnCreate (database); }}  

In this way it should work. Create Table will throw an exception if the table already exists if the table does not exist, then create the table will create a table if it does not exist, or if it does so Ignore if you want to delete the old table, then use the Delete table before create table . If you want to change the schema, use the optional table , do not use the create table .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -