列约束或逗号应为TEXT

时间:2019-06-04 16:17:16

标签: android sqlite

我很确定自己已经正确设置了格式,因为它基本上与我正在使用的另一条语句完全相同(效果很好),但是我收到一条错误提示

'(', ')' <column constraint> or comma expected, got 'TEXT'

和“ TEXT”下方的红色下划线:

+ RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_CONTROL_NUMBER + " TEXT NOT NULL, "

就像我说的那样,我基本上可以完全重复此声明。

这是行不通的:

String sSQL;
        sSQL = "CREATE TABLE " + RecentFileWaypointContract.TABLE_NAME + " ("
                + RecentFileWaypointContract.Columns._ID + " INTEGER PRIMARY KEY NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_CONTROL_NUMBER + " TEXT NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_INSURED_NAME + " TEXT NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_CUSTOMER + " TEXT NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_ADDRESS1 + " TEXT NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_ADDRESS2 + " TEXT, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_CITY + " TEXT NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_STATE + " TEXT NOT NULL, "
                + RecentFileWaypointContract.Columns.RECENT_FILE_WAYPOINT_ZIPCODE + " TEXT NOT NULL);";
        db.execSQL(sSQL);

为了进行比较,以下是可以正常工作的示例:

String sSQL;
        sSQL = "CREATE TABLE " + UserWaypointContract.TABLE_NAME + " ("
                + UserWaypointContract.Columns._ID + " INTEGER PRIMARY KEY NOT NULL, "
                + UserWaypointContract.Columns.USER_WAYPOINT_TITLE + " TEXT NOT NULL, "
                + UserWaypointContract.Columns.USER_WAYPOINT_ADDRESS1 + " TEXT NOT NULL, "
                + UserWaypointContract.Columns.USER_WAYPOINT_ADDRESS2 + " TEXT, "
                + UserWaypointContract.Columns.USER_WAYPOINT_CITY + " TEXT NOT NULL, "
                + UserWaypointContract.Columns.USER_WAYPOINT_STATE + " TEXT NOT NULL, "
                + UserWaypointContract.Columns.USER_WAYPOINT_ZIPCODE + " TEXT NOT NULL);";

        db.execSQL(sSQL);

(此外,有两个不同的类,因此在两个地方都使用sSQL并不是问题)

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

您不能在其中包含空格的列名称。将"Control number"替换为"Control_number""ControlNumber""controlNumber"或类似的内容。