SQLiteException:旧设备上没有这样的列

时间:2016-05-20 12:55:13

标签: java android eclipse sqlite

function PrepareToInstall(var NeedsRestart: Boolean): String; var ResultCode: Integer; begin ExtractTemporaryFile('Install.exe'); if FileCopy(ExpandConstant('{tmp}\Install.exe'), ExpandConstant('{app}\Install.exe'), False) then begin if not Exec(ExpandConstant('{app}\Install.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then Result := 'Installation failed. ' + SysErrorMessage(ResultCode); end; end; 引发了以下异常:

  

android.database.sqlite.SQLiteException:没有这样的列:tblAlarmSetup.ASID(代码1):,同时编译: SELECT tblAlarmSetup.ASID AS A,tblContact.CID AS B,tblContact.Contact AS C,tblSubject .SubID AS D,tblSubject.Subject AS E,tblAlarmSetup.IsActive AS F FROM tblSubject INNER JOIN(tblContact INNER JOIN tblAlarmSetup on tblContact.CID = tblAlarmSetup.CID)ON tblSubject.SubID = tblAlarmSetup.SubID WHERE tblContact.CID = 1 AND tblSubject .SubID = 1

但是,当我在旧的三星S2手机上调试应用程序时,我只会遇到此异常。在我的新Xperia Z3上一切正常。

这个SQL语句有什么不对它在旧设备上不起作用?

我有以下3个表格:

  • LogCat CID ,请与
  • 联系
  • tblContact子ID ,主题

两者都与:

相关联
  • tblSubject ASID ,CID,SubId,IsActive

编辑:samsung s2运行android 4.1.2; xperia z3运行android 6.0.1

编辑2:这里有一些相关的代码

tblAlarmSetup

创建数据库:

public class DbHandler extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "ReminderDB.db";
private static final int DATABASE_VERSION = 1;  

private static final String TABLE_CONTACT = "tblContact";
private static final String TABLE_CONTACT_CID_ATTR = "CID";
private static final String TABLE_CONTACT_CID = TABLE_CONTACT + "." + TABLE_CONTACT_CID_ATTR;
private static final String TABLE_CONTACT_CONTACT_ATTR = "Contact";
private static final String TABLE_CONTACT_CONTACT = TABLE_CONTACT + "." + TABLE_CONTACT_CONTACT_ATTR;

private static final String TABLE_SUBJECT = "tblSubject";
private static final String TABLE_SUBJECT_SUBID_ATTR = "SubID";
private static final String TABLE_SUBJECT_SUBID = TABLE_SUBJECT + "." + TABLE_SUBJECT_SUBID_ATTR;
private static final String TABLE_SUBJECT_SUBJECT_ATTR = "Subject";
private static final String TABLE_SUBJECT_SUBJECT = TABLE_SUBJECT + "." + TABLE_SUBJECT_SUBJECT_ATTR;

private static final String TABLE_ALARMSETUP = "tblAlarmSetup";
private static final String TABLE_ALARMSETUP_ASID_ATTR = "ASID";
private static final String TABLE_ALARMSETUP_ASID = TABLE_ALARMSETUP + "." + TABLE_ALARMSETUP_ASID_ATTR;
private static final String TABLE_ALARMSETUP_CID_ATTR = "CID";
private static final String TABLE_ALARMSETUP_CID = TABLE_ALARMSETUP + "." + TABLE_ALARMSETUP_CID_ATTR;
private static final String TABLE_ALARMSETUP_SUBID_ATTR = "SubID";
private static final String TABLE_ALARMSETUP_SUBID = TABLE_ALARMSETUP + "." + TABLE_ALARMSETUP_SUBID_ATTR;
private static final String TABLE_ALARMSETUP_ISACTIVE_ATTR = "IsActive";
private static final String TABLE_ALARMSETUP_ISACTIVE = TABLE_ALARMSETUP + "." + TABLE_ALARMSETUP_ISACTIVE_ATTR;`

查询:

    @Override
    public void onCreate(SQLiteDatabase db) {
        final String CREATE_CONTACT_TABLE = 
                "CREATE TABLE IF NOT EXISTS " + TABLE_CONTACT + " ("
                + TABLE_CONTACT_CID_ATTR + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + TABLE_CONTACT_CONTACT_ATTR + " STRING NOT NULL UNIQUE)";
        //CID (PK, FK) | Contact (unique)

        final String CREATE_SUBJECT_TABLE = 
                "CREATE TABLE IF NOT EXISTS " + TABLE_SUBJECT + " ("
                + TABLE_SUBJECT_SUBID_ATTR + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + TABLE_SUBJECT_SUBJECT_ATTR + " STRING NOT NULL UNIQUE)";
        //SubID (PK, FK) | Subject (unique)

        final String CREATE_ALARMSETUP_TABLE = 
                "CREATE TABLE IF NOT EXISTS " + TABLE_ALARMSETUP + " ("
                + TABLE_ALARMSETUP_ASID_ATTR + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + TABLE_ALARMSETUP_CID_ATTR + " INTEGER NOT NULL, "
                + TABLE_ALARMSETUP_SUBID_ATTR + " INTEGER NOT NULL, "
                + TABLE_ALARMSETUP_ISACTIVE_ATTR + " INTEGER NOT NULL DEFAULT 0, "
                + "UNIQUE (" + TABLE_ALARMSETUP_CID_ATTR + ", " + TABLE_ALARMSETUP_SUBID_ATTR + "), "
                + "FOREIGN KEY (" + TABLE_ALARMSETUP_CID_ATTR + ") REFERENCES " + TABLE_CONTACT + " (" + TABLE_CONTACT_CID_ATTR + "), "
                + "FOREIGN KEY (" + TABLE_ALARMSETUP_SUBID_ATTR + ") REFERENCES " + TABLE_SUBJECT + " (" + TABLE_SUBJECT_SUBID_ATTR + "))";
        //ASID (PK) | CID (Unique in combination with SubID) | SubID

        db.execSQL(CREATE_CONTACT_TABLE); 
        db.execSQL(CREATE_SUBJECT_TABLE);
        db.execSQL(CREATE_ALARMSETUP_TABLE);
}

编辑3:请不要关闭此帖子。你给我的建议没有回答我的问题。触发了 String query = "SELECT " + TABLE_ALARMSETUP_ASID + " AS A, " + TABLE_CONTACT_CID + " AS B, " + TABLE_CONTACT_CONTACT + " AS C, " + TABLE_SUBJECT_SUBID + " AS D, " + TABLE_SUBJECT_SUBJECT + " AS E, " + TABLE_ALARMSETUP_ISACTIVE + " AS F" + " FROM " + TABLE_SUBJECT + " INNER JOIN (" + TABLE_CONTACT + " INNER JOIN " + TABLE_ALARMSETUP + " ON " + TABLE_CONTACT_CID + " = " + TABLE_ALARMSETUP_CID + ")" + " ON " + TABLE_SUBJECT_SUBID + " = " + TABLE_ALARMSETUP_SUBID + " WHERE " + TABLE_CONTACT_CID + " = " + cid + " AND " + TABLE_SUBJECT_SUBID + " = " + subid; Cursor cursor = db.rawQuery(query, null); 并且表存在。我可以对OnCreate这样的单个表进行选择查询,但如果我在我的查询中包含联接,它就无法在我的三星设备上运行。

0 个答案:

没有答案