現在我有一個奇怪的問題,我做了各種測試,我相信我看到一些奇怪的東西。未在SQLITE3表中創建列
我SQLiteOpenHelper創建三個表:
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(TABLE_CHANNELS_CREATE);
db.execSQL(TABLE_FEEDS_CREATE);
db.execSQL(TABLE_FEEDMAP_CREATE);
}
catch (SQLiteException e){
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
的CREATE語句的三個表如下:
CREATE TABLE IF NOT EXISTS IRChannels (
ChannelId INTEGER PRIMARY KEY,
ChannelHash TEXT NOT NULL,
ChannelTitle TEXT NOT NULL,
ChannelDesc TEXT, ChannelLink TEXT);
CREATE TABLE IF NOT EXISTS IRFeeds (
FeedId INTEGER PRIMARY KEY,
FeedHash TEXT NOT NULL,
FeedTitle TEXT NOT NULL,
FeedDescription TEXT,
FeedLink TEXT);
CREATE TABLE IF NOT EXISTS IRFeedMap (
ChannelHash_FK TEXT NOT NULL,
FeedHash_FK TEXT NOT NULL,
FOREIGN KEY (ChannelHash_FK) REFERENCES IRChannels (ChannelHash),
FOREIGN KEY (FeedHash_FK) REFERENCES IRFeeds (FeedHash));
的問題顯然是在IRFeeds
FeedHash
而另一些則不會創建列。我正在查看sqlite3命令提示符中的輸出;
sqlite> .schema
CREATE TABLE IRChannels (
ChannelId INTEGER PRIMARY KEY,
ChannelHash TEXT NOT NULL,
ChannelTitle TEXT NOT NULL,
ChannelDesc TEXT,
ChannelLink TEXT);
CREATE TABLE IRFeedMap (
ChannelHash_FK TEXT NOT NULL,
FeedHash_FK TEXT NOT NULL,
FOREIGN KEY (ChannelHash_FK) REFERENCES IRChannels (ChannelHash),
FOREIGN KEY (FeedHash_FK) REFERENCES IRFeeds (FeedHash));
CREATE TABLE IRFeeds (
FeedId INTEGER PRIMARY KEY,
FeedHash TEXT NOT NULL,
FeedTitle TEXT NOT NULL,
FeedDescription TEXT,
FeedLink TEXT);
這並不在IRFeeds
列出FeedHash
列。但是,當我執行時
sqlite> select * from IRFeeds where FeedHash='';
SQL error: no such column: FeedHash
所有其他列不會出現此類錯誤。這種情況導致我的代碼也意外失敗。我可能會錯過什麼?
sqlite> select * from IRFeeds where FeedID=1;
sqlite> select * from IRFeeds where FeedTitle='';
sqlite> select * from IRFeeds where FeedDescription='';
sqlite> select * from IRFeeds where FeedLink='';
當我執行的其他列select
上述聲明沒有錯誤。
有趣的是,'QUESTOID SQLLite Manager' (http://jaxenter.com/manage-sqlite-for-android-11339.html)在嘗試打開我的數據庫時出現以下錯誤:'無法創建視圖:[行1:58]沒有可行的替代方案字符「' CREATE TABLE IRFeeds(FeedId INTEGER PRIMARY KEY,FeedHash TEXT NOT NULL,FeedTitle TEXT NOT NULL,FeedDescription TEXT,FeedLink TEXT)' – 2011-12-28 13:11:50
Found the thread(http://code.google.com/p/android/issues /細節?ID = 1732)。不知道我看到的是相關的,但仍然有幫助。 – 2011-12-28 14:18:33
感嘆!確實很奇怪。如果我手動'刪除irfeeds'和'創建表irfeeds(...)'然後執行我的代碼,一切都按預期工作。想知道這是否與我在SQLiteOpenHelper.onCreate中創建多個表的事實有關。 – 2011-12-28 15:54:23