Android SQLite问题表...没有列名

时间:2013-12-14 19:52:47

标签: android sqlite

我已经卸载了应用程序,创建了新的模拟器,但问题仍然存在,我不知道所以时间互联网帮助:)。 我在日志中有一个名为“sms_sentdate”的列,这是丢失的列,而我已经检查了可以接受的值,问题出现在架构的某处,我无法弄清楚。

当你们参与其中时,如果我当前的方法错误,请告诉我如何告诉app架构已更新。

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 个答案:

答案 0 :(得分:1)

替换

KEY_Recurrence+" integer);"+
KEY_SentDate+" text);";

KEY_Recurrence+" integer,"+
KEY_SentDate+" text);";

SQL在第一个;上终止,并且未执行任何剩余的SQL,因此您没有收到有关悬空列规范的语法错误。