未创建Android数据库表

时间:2014-04-03 06:13:00

标签: android database sqlite sqlexception

在Android中,我很难找到以下查询的问题。编码似乎是正确的。我正在尝试以下代码段:

 DATABASE_TABLES.add("CREATE TABLE PageRights("
                +"RightsId INTEGER NOT NULL,"
                +"PageName varchar(-1) NULL,"
                +"PageId INTEGER NOT NULL,"
                +"UserId INTEGER NOT NULL,"
                +"RoleId INTEGER NOT NULL,"
                +"Add BOOLEAN NOT NULL,"
                +"Edit BOOLEAN NULL,"
                +"Delete BOOLEAN NULL,"
                +"CreatedBy varchar(-1) NULL,"
                +"CreatedDate DATE NOT NULL,"
                +"Views BOOLEAN NULL)");

抛出的错误是;

android.database.sqlite.SQLiteException: near "Add": syntax error (code 1): , while compiling: CREATE TABLE PageRights(RightsId INTEGER NOT NULL,PageName varchar(-1) NULL,PageId INTEGER NOT NULL,UserId INTEGER NOT NULL,RoleId INTEGER NOT NULL,Add BOOLEAN NOT NULL,Edit BOOLEAN NULL,Delete BOOLEAN NULL,CreatedBy varchar(-1) NULL,CreatedDate DATE NOT NULL,Views BOOLEAN NULL)

请通过提出你的想法来帮助我。

2 个答案:

答案 0 :(得分:5)

AddEditDelete是预定义的关键字,请按照以下方式使用,

DATABASE_TABLES.add("CREATE TABLE PageRights("
                +"RightsId INTEGER NOT NULL,"
                +"PageName varchar(-1) NULL,"
                +"PageId INTEGER NOT NULL,"
                +"UserId INTEGER NOT NULL,"
                +"RoleId INTEGER NOT NULL,"
                +"Add_PageRights BOOLEAN NOT NULL,"
                +"Edit_PageRights BOOLEAN NULL,"
                +"Delete_PageRights BOOLEAN NULL,"
                +"CreatedBy varchar(-1) NULL,"
                +"CreatedDate DATE NOT NULL,"
                +"Views BOOLEAN NULL)");

请访问Oracle naming standards tips

答案 1 :(得分:4)

  

android.database.sqlite.SQLiteException:near" Add"

Add是MySQL中的保留字。顺便说一下,EditDelete也是如此。

将这些列的名称更改为其他名称。