开发者

SQLite Syntax Error

开发者 https://www.devze.com 2023-03-02 18:22 出处:网络
I made a sql query, below. I am getting an exception which I have shown as well. Any help is appreciated.

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","jsmith@newyahoo.com","+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_开发者_如何学CFAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]


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


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 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消