lundi 25 avril 2016

Add column to sqlite table if not exists

I'm trying to safely add a column to a table by checking if it exists or not. With SQL Server I know I can do the following:
(ps tablename: 'Log' and columnname: 'Usercode'):

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Log' AND COLUMN_NAME = 'Usercode')
THEN 
ALTER TABLE Log
ADD COLUMN Usercode

I figured out that I could the same in Sqlite by using PRAGMA table_info(Log) I'm not quite sure what I'll see in return, because I'm getting a could not prepare statement (23 not authorized) error.

Does anybody know a way for me to safely add a column?

PS: I'm using this in Google Chrome.

Aucun commentaire:

Enregistrer un commentaire