编译CREATE VIEW时,SQLite错误列(存在)不存在

时间:2015-04-21 08:44:39

标签: android sqlite

我正在尝试创建一个视图,但由于某种原因,它给了我一个列不存在错误。这不是我制作的第一个视图,其他所有视图都在工作,表格在那里,列和所有(我用DBBrowser检查过,除了这一个VIEW不起作用)。

我已经检查了我的空白,这一切都井然有序,但出现了问题,我一直在试着找出什么。有人可以对此有所了解吗?

LogCat

 Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jc.pseudocc/com.example.jc.pseudocc.AccountManager}: android.database.sqlite.SQLiteException: no such column: Companies.CompanyID (code 1): , while compiling: CREATE VIEW ViewCompanies AS SELECT Companies.CompanyID AS _id, Payments.GroupID, Payments.PaymentDue, Payments.DateDue FROM Payments JOIN Accounts ON Payments.GroupID = Accounts.AccountID

表格

COMPANY

db.execSQL("CREATE TABLE " + COMPANY + " (" + colCompID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            colCompClass + " TEXT)");

PAYMENTS

db.execSQL("CREATE TABLE " + PAYMENTS + " (" + colPayID + " INTEGER PRIMARY KEY , " +
            colGroupID + " INTEGER NOT NULL, " +
            colPayBal + " TEXT, " +
            colInterest + " TEXT, " +
            colPayDue + " TEXT, " +
            colDateDue + " TEXT, " +
            colPayDate + " TEXT, " +
            "FOREIGN KEY (" + colGroupID + ") REFERENCES " + ACCOUNTS + " (" + colID + ") ON DELETE CASCADE);");

查看

db.execSQL("CREATE VIEW " + viewComps +
            " AS SELECT " + COMPANY + "." + colCompID + " AS _id," +
            " " + COMPANY + "." + colCompClass + "," +
            " " + PAYMENTS + "." + colGroupID + "," +
            " " + PAYMENTS + "." + colPayDue + "," +
            " " + PAYMENTS + "." + colDateDue + "" +
            " FROM " + PAYMENTS +
            " JOIN " + ACCOUNTS + " ON " + PAYMENTS + "." + colGroupID + " = " + ACCOUNTS + "." + colID );

1 个答案:

答案 0 :(得分:2)

创建视图时,请参考COMPANY和PAYMENTS。您需要在查询的FROM部分指明:

替换

" FROM " + PAYMENTS +

" FROM " + PAYMENTS + ", " + COMPANY +