SQLite 语法错误

发布于 2024-11-05 07:45:50 字数 1102 浏览 0 评论 0原文

我做了一个sql查询,如下。我也遇到了一个例外。任何帮助表示赞赏。

查询:

INSERT OR REPLACE INTO CLAIMS (DATE ,TIME , ADDRESS , CITY, 
STATE , POSTAL , PHFNAME ,PHLNAME ,PHEMAIL ,PHPHONE ,AGENCY ,POLICY ,VEHICLENAME,
YEAR ,MAKE ,MODEL ,PLATELICENSE ,LSTATE ,VIN ,DRIVERNAME,DRFNAME ,DRLNAME ,
DRPHONE ,DREMAIL ,DRLICENSE) VALUES("Wednesday, May 4, 2011", 
"10:39:10 PM EDT", "400 Chatham","Pune", "Penn", "45223", "John", 
"Richard","[email protected]","+1-11111111111", 
"Three Rivers Insurance","(null)", "(null)", "(null)", 
"(null)", "(null)","(null)", "(null)", "(null)","(null)", 
"(null)", "(null)","(null)", "(null)","(null)") WHERE DATE  LIKE 
'Wednesday, May 4,%' AND TIME = '10:39:10 PM EDT'

错误:

SQLiteManager: Likely SQL syntax error:


 [ near "WHERE": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]

I made a sql query, below. I am getting an exception which I have shown as well. Any help is appreciated.

QUERY:

INSERT OR REPLACE INTO CLAIMS (DATE ,TIME , ADDRESS , CITY, 
STATE , POSTAL , PHFNAME ,PHLNAME ,PHEMAIL ,PHPHONE ,AGENCY ,POLICY ,VEHICLENAME,
YEAR ,MAKE ,MODEL ,PLATELICENSE ,LSTATE ,VIN ,DRIVERNAME,DRFNAME ,DRLNAME ,
DRPHONE ,DREMAIL ,DRLICENSE) VALUES("Wednesday, May 4, 2011", 
"10:39:10 PM EDT", "400 Chatham","Pune", "Penn", "45223", "John", 
"Richard","[email protected]","+1-11111111111", 
"Three Rivers Insurance","(null)", "(null)", "(null)", 
"(null)", "(null)","(null)", "(null)", "(null)","(null)", 
"(null)", "(null)","(null)", "(null)","(null)") WHERE DATE  LIKE 
'Wednesday, May 4,%' AND TIME = '10:39:10 PM EDT'

Error:

SQLiteManager: Likely SQL syntax error:


 [ near "WHERE": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难理解 2024-11-12 07:45:50

对于一次插入和更新的同步表,我遇到了同样的问题,最后我使用了。
要使用插入或替换语句,您需要使用需要主键列来放置 where 子句的合并函数。

COALESCE((SELECT PRIMARY_KEY_COLUMN FROM TABLE_NAME WHERE UNIQUE_COLUMN = 'VALUE'),
(SELECT MAX(PRIMARY_KEY_COLUMN)+1 FROM TABLE_NAME))

它对我有用,例如

INSERT OR  REPLACE INTO TBL_ADDRESSES
(ADDRESS_ID,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS_NAME,CITY,DB_ID) 
VALUES (
    COALESCE((SELECT ADDRESS_ID FROM TBL_ADDRESSES WHERE DB_ID = '111'),
        (SELECT MAX(ADDRESS_ID)+1 FROM TBL_ADDRESSES)),
    'IT 27','Pratap DSFSDSDDSDSF','test add ','IT 27','Jaipur','111') ;

I faced the same issue for sync table for insert and update at a time and finally i use.
To use the insert or replace statement you need to use the coalesce function that required primary key column to put the where clause.

COALESCE((SELECT PRIMARY_KEY_COLUMN FROM TABLE_NAME WHERE UNIQUE_COLUMN = 'VALUE'),
(SELECT MAX(PRIMARY_KEY_COLUMN)+1 FROM TABLE_NAME))

it worked for me e.g

INSERT OR  REPLACE INTO TBL_ADDRESSES
(ADDRESS_ID,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS_NAME,CITY,DB_ID) 
VALUES (
    COALESCE((SELECT ADDRESS_ID FROM TBL_ADDRESSES WHERE DB_ID = '111'),
        (SELECT MAX(ADDRESS_ID)+1 FROM TBL_ADDRESSES)),
    'IT 27','Pratap DSFSDSDDSDSF','test add ','IT 27','Jaipur','111') ;
花之痕靓丽 2024-11-12 07:45:50

INSERT OR REPLACE 不支持 WHERE 子句,请参阅SQLite 插入文档。您可以在 UPDATE 语句中使用 WHERE 子句,请参阅 SQLite 插入文档

如果您能让我们知道您想要什么,可以帮助您吗?

INSERT OR REPLACE doesn't support WHERE clause, see theSQLite Insert doc. You can use a WHERE clause in UPDATE statements, see the SQLite Insert doc

Can help you if you can let us know what you wanted here ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文