1

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]

2 Answers 2

4

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') ;
Sign up to request clarification or add additional context in comments.

Comments

2

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 ?

7 Comments

thank u for the quick reply. then what can be used with INSERT OR REPLACE instead of WHERE.
What i want to do is to update the user entered data based on Date and Time.
If you are inserting only one row, then INSERT or REPLACE doesn't require any other clause. Remove WHERE clause in the query it should work.
If you have a UNIQUE constraint on DATE and TIME, then your REPLACE statement would handle the CONFLICT.Assuming you have CONSTRAINT defined, any row which has "Wednesday, May 4, 2011", "10:39:10 PM EDT" will now be updated to the new values which you are trying to insert.
This should help then UPDATE CLAIMS SET DATE = "Wednesday, May 4, 2011" AND TIME = "...", AND CITY="..." AND ... WHERE DATE LIKE '..%' AND TIME = "..."
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.