Reputation: 2641
I am struggling to come up with a query for sqlite table to UPDATE OR INSERT
at rowid. The problem I have is that I have a database where it relies on the rowid but when populating the table there may not be enough rows. So the table may look like this:
rowID data1 data2 data3
------ ------ ----- ------
0 18 1543
1 5
2 35 918
And for my query I want to be able to insert data2 = 453
at rowID = 16 for example. Also just to specify I do not have a column of rowID.
I am thinking that the only way possible would be to insert empty rows from rowID 3 -> 15 before inserting the 16th row. It does not matter for me if rows are empty as they will eventually be populated. I will not be working with more than 50 rows or more than 8 columns so it is a reasonably small table. Anyone know a way forward for me to work?
Also additional thing to note, I am using the query on Titanium, so the programming language is JavaScript.
Upvotes: 2
Views: 156
Reputation: 180270
The documentation says:
The rowid value can be accessed using one of the special case-independent names "rowid", "oid", or "rowid" in place of a column name. [...] An INSERT statement may provide a value to use as the rowid for each row inserted.
So just specify the values you want:
INSERT INTO MyTable(rowid, data2) VALUES(16, 453)
Upvotes: 1