gpt4 book ai didi

android - SQLite建表出错

转载 作者:行者123 更新时间:2023-11-29 17:30:49 25 4
gpt4 key购买 nike

我的 SQL 代码有什么问题?当我运行时,应用程序崩溃了。我已经搜索了很长时间,但仍然无法找出问题所在。

     db.execSQL("create table "+TABLE_WORKDETAILS +"(ID INTEGER PRIMARY KEY , Project TEXT, WorkDescription TEXT, Per Text, TimeIn DATETIME,
TimeOut DATETIME,TotalHours DATETIME, Twf_id INTEGER, FOREIGN KEY(Twf_id) REFERENCES "+TABLE_WORKFORCE+"(ID1),TableInfo_id INTEGER, FOREIGN KEY(TableInfo_id) REFERENCES "+TABLE_INFO+"(ID))");

错误 LogCat

 Process: com.example.project.project, PID: 2055
android.database.sqlite.SQLiteException: near "TableInfo_id": syntax error (code 1): , while compiling: create table WorkDetails(ID INTEGER PRIMARY KEY , Project TEXT, WorkDescription TEXT, Per Text, TimeIn DATETIME, TimeOut DATETIME,TotalHours DATETIME, Twf_id INTEGER, FOREIGN KEY(Twf_id) REFERENCES WorkForce(ID1),TableInfo_id INTEGER, FOREIGN KEY(TableInfo_id) REFERENCES Information(ID))
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)

最佳答案

在 Sqlite 表定义中,所有列定义都必须放在键定义之前,因为在您的查询中它们混杂在一起。试试这个:

CREATE table WorkDetails(ID INTEGER PRIMARY KEY , 
Project TEXT, WorkDescription TEXT, Per Text,

TimeIn DATETIME, TimeOut DATETIME,TotalHours DATETIME,TableInfo_id INTEGER,
Twf_id INTEGER, FOREIGN KEY(Twf_id) REFERENCES WorkForce(ID1),
FOREIGN KEY(TableInfo_id) REFERENCES Information(ID))

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

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