I have a simple problem which probably has a simple solution, but the solution alludes me…
so I have a simple table i.e. phone that has 4 columns, and I want to add one new column. Since SQLite doesn’t modify tables I have to drop and create.
phone_old
_id integer primary key autoincrement,
name text not null,
value text
phone
_id integer primary key autoincrement,
name text not null,
itemState text not null,
value text
so I do the following :
1. I rename the old table,
2. I create the new one with the extra field (in my case it’s itemState) and
3. I select and insert everything defining a default value for itemstate.
1 ALTER TABLE Phone RENAME TO Phone_OLD;
2 CREATE table Phone(
_id integer primary key autoincrement,
name text not null,
itemState text not null,
value text );
3) INSERT INTO Phone SELECT * , 'Synced' as itemState from Phone_OLD where Phone_OLD. ;
what happends as a result is that the item state (synced) is added as the last field and not in column 3 which is the itemState.
so the column names do not correspond to the row values, meaning the itemstate is added at the end (as the last column in the row and not as position 3 as it’s supposed to )
Just putting the itemstate at the end would solve the problem, but since my table creation statements are generated I would have to rewrite a whole bunch of code to do so, and to be hones it pisses me off that this set of queries returns crap..
any ideas?
Sqlite does support appending columns