0

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(); 
}

}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Damn it!! Bloody Semicolon
Thanks! @laalto, i checked everything except for ;, now i am ashamed :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.