Вопрос

In Android, I'm having difficulties finding out what is the problem with the following query. The coding seems correct. I'm trying the following snippet:

 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)");

The error being thrown is ;

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)

Please help me by giving your idea .

Это было полезно?

Решение 2

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

Add is a reserved word in MySQL. So are Edit and Delete by the way.

Change the names of those columns to something else.

Другие советы

Add,Edit,Delete are pre-defined keywords, use following way,

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)");

Please visit Oracle naming standards tips.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top