2012-01-13 79 views
1

我想在我的應用程序中創建一個SQLite數據庫,將其導出到SD卡。我收到錯誤SQLite錯誤1無列SQLite插入錯誤

12月1日至13日:31:39.621:I /數據庫(3828):sqlite的返回:錯誤碼= 1,味精=表庫存沒有列命名的位置

SQLite的插入錯誤

這是我創建數據庫的代碼...我似乎無法找到問題。

@Override 
    public void onCreate(SQLiteDatabase db) { 
     db.execSQL("CREATE TABLE inventory (" 
       + "_id INTEGER PRIMARY KEY," + "serialnum TEXT," 
       + "modelnum TEXT," + "manufact TEXT," + "description TEXT," 
       + "time DATETIME" + ");"); 
    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     if (oldVersion < 2) { 
      Log.d("SW","Upgrading database from version " + oldVersion + " to " + newVersion); 
      db.execSQL("ALTER TABLE inventory ADD location TEXT"); 
     } 
     if (oldVersion < 3) { 
      Log.d("SW","Upgrading database from version " + oldVersion + " to " + newVersion); 
      db.execSQL("ALTER TABLE inventory ADD other TEXT"); 
     } 

    } 
+0

通過開放源代碼項目,我的工作是關閉的方式http://code.google.com/p/simplescan/source/checkout謝謝 – KDEx 2012-01-13 20:11:45

回答

0

正確語法添加新列:

ALTER TABLE test1 ADD COLUMN foo;

試試這個:

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    if (oldVersion < 2) { 
     Log.d("SW","Upgrading database from version " + oldVersion + " to " + newVersion); 
     db.execSQL("ALTER TABLE inventory ADD COLUMN location TEXT"); 
    } 
    if (oldVersion < 3) { 
     Log.d("SW","Upgrading database from version " + oldVersion + " to " + newVersion); 
     db.execSQL("ALTER TABLE inventory ADD COLUMN other TEXT"); 
    } 

} 
+0

試過了,沒有工作。查看我評論中關於我正在使用的開源數據的鏈接。謝謝 – KDEx 2012-01-13 20:12:35

+0

這是答案是正確的,這是你如何正確添加一列。我的問題源於不恰當地添加了爲該列創建數據的微調器。 – KDEx 2012-03-22 21:25:31

0

嘗試

ALTER TABLE inventory ADD COLUMN location TEXT 
0

嘗試改變第一個SQL命令:

db.execSQL("CREATE TABLE inventory (" 
      + "_id INTEGER PRIMARY KEY," + "serialnum TEXT," 
      + "modelnum TEXT," + "manufact TEXT," + "description TEXT," 
      + "time DATETIME," + "location TEXT" + ");"); 

- 你的CREATE TABLE語句中不包括位置列。

+0

試過了,沒有雪茄。謝謝 – KDEx 2012-01-13 20:12:10