Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite update query error

Tags:

sqlite

I want to add something into every row in a column, however I have some difficulties with it. There are already some data in the rows, and I don't want to lose those, just add this new one.

Table name is GroupList
Column name is Commands

In the rows of commands data is seperated by a comma.

Here is my mess:

UPDATE GroupList SET Commands = ',stats.highscores', WHERE Commands != ',stats.highscores'

The , before the stats.highscores is a must. I have no idea why it won't work. I tried looking up the error code in google, but I still get the same error.

Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[mozIStorageConnection.createStatement]

I would really appriciate some help with this. Sorry if I wrote something stupid, I'm new with sqlite.

edit: I'm using sqlite manager firefox addon

like image 487
Matthew Avatar asked May 06 '26 10:05

Matthew


1 Answers

You have a comma after the SET statement which makes the SQL you have invalid.

The statement you have will update the Commands column for all existing rows where the Commands column does not have the value ,stats.highscores.

To create a new row you need to use INSERT

INSERT INTO GroupList (Commands) VALUES (',stats.highscores');

EDIT

To update this value when there is no current value use

UPDATE GroupList 
  SET Commands = ',stats.highscores' 
WHERE 
  Commands IS NULL 
  OR Commands = '';
like image 183
Dave Anderson Avatar answered May 08 '26 03:05

Dave Anderson