gpt4 book ai didi

android - SQLite 异常 - 创建表

转载 作者:行者123 更新时间:2023-11-29 21:15:56 26 4
gpt4 key购买 nike

我遇到了一个异常,但我不明白为什么会抛出它。当我添加表格消息时出现异常。请看一下,看看是否有我遗漏的错误。提前致谢。

异常(exception):

 Caused by: android.database.sqlite.SQLiteException: near "From": syntax error (code 1): , while compiling: CREATE TABLE Messages (UniqueId TEXT PRIMARY KEY,From TEXT,To TEXT,Subject TEXT,Body TEXT,HandledOn TEXT,IsRead INTEGER,CreatedOn TEXT,UpdatedOn TEXT,DeletedOn TEXT);

引发异常的语句,在SQLiteOpenHelper中:

@Override
public void onCreate(android.database.sqlite.SQLiteDatabase db) {
String CREATE_MESSAGES_TABLE =
"CREATE TABLE " + TABLE_MESSAGES + "("
+ COLUMN_UNIQUEID + " TEXT PRIMARY KEY,"
+ COLUMN_FROM + " TEXT,"
+ COLUMN_TO + " TEXT,"
+ COLUMN_SUBJECT + " TEXT,"
+ COLUMN_BODY + " TEXT,"
+ COLUMN_HANDLEDON + " TEXT,"
+ COLUMN_ISREAD + " INTEGER,"
+ COLUMN_CREATEDON + " TEXT,"
+ COLUMN_UPDATEDON + " TEXT,"
+ COLUMN_DELETEDON + " TEXT"
+ ");";

String CREATE_CONTACTS_TABLE =
"CREATE TABLE " + TABLE_CONTACTS + "("
+ COLUMN_UNIQUEID + " TEXT PRIMARY KEY,"
+ COLUMN_NAME + " TEXT,"
+ COLUMN_EMAIL + " TEXT,"
+ COLUMN_CREATEDON + " TEXT,"
+ COLUMN_UPDATEDON + " TEXT,"
+ COLUMN_DELETEDON + " TEXT"
+ ");";

db.execSQL(CREATE_MESSAGES_TABLE);
db.execSQL(CREATE_CONTACTS_TABLE);
}

最佳答案

您正在使用诸如“from”和“to”之类的 protected 关键字作为表名,这在 SQLite 中是不允许的:

https://www.sqlite.org/lang_keywords.html

关于android - SQLite 异常 - 创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21456144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com