Reputation: 717
I have uninstalled app, created new emulator but problem is still there i have no clue so time for internet to help :). I have a column named "sms_sentdate" in the log this is the column that goes missing, while i have checked values that is ok, problem lies somewhere in schema that i can't figure out.
While you guys are at it, please advice about how can i tell app that schema has been updated if my current method is wrong.
public class SMSdb extends SQLiteOpenHelper{
private final static String DB_NAME = "SMSDB";
private final static int DB_VERSION = 4;
private static final String KEY_ID = "sms_id";
private static final String KEY_Text = "sms_text";
private static final String KEY_SMSReceiver = "sms_reciever";
private static final String KEY_Recurrence = "sms_recurrence_id";
private static final String KEY_SentDate = "sms_sentdate";
private static final String TABLE_SMS = "sms";
private static final String[] COLUMNS = { KEY_ID, KEY_Text, KEY_SMSReceiver, KEY_Recurrence, KEY_SentDate};
public final static String DB_SMSdb_TABLE_CREATE = "create table sms " +
"("+KEY_ID+" integer primary key autoincrement, " +
KEY_Text +" text not null, "+
KEY_SMSReceiver + " text not null,"+
KEY_Recurrence+" integer);"+
KEY_SentDate+" text);";
public SMSdb(Context context)
{
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
// TODO Auto-generated method stub
Log.i("Database", "Database creating");
database.execSQL(DB_SMSdb_TABLE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
database.execSQL("DROP TABLE IF EXISTS sms");
onCreate(database);
}
public void addSms(SMS sms){
Log.d("addSMS", sms.toString());
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_Text, sms.getText());
values.put(KEY_SMSReceiver, sms.getSmsReceiver());
values.put(KEY_Recurrence, sms.getSms_recurrence_id());
values.put(KEY_SentDate, sms.getSmsSentDate());
db.insert(TABLE_SMS,
null,
values);
db.close();
}
}
Upvotes: 0
Views: 137
Reputation: 152927
Replace
KEY_Recurrence+" integer);"+
KEY_SentDate+" text);";
with
KEY_Recurrence+" integer,"+
KEY_SentDate+" text);";
The SQL is terminated on the first ;
and any remaining SQL is not executed so you didn't get a syntax error about the dangling column specifications.
Upvotes: 1