I'm a complete SQL novice, and I'm trying to accomplish the following (pseudo-code) with a single query:
if (a table named "config_data" does not exist)
{ create a table named "config_data" }
if ("config_data" has no rows)
{ add a row to "config_data" with some default data }
return all rows in "config_data"
How would I go about it? Can it be done with a single query? I'm using SQLite3, if that helps.
So far, I know how to create a table, and insert data into it:
CREATE TABLE config_data (key TEXT NOT NULL, value TEXT);
INSERT INTO config_data VALUES ("key_1", "value_1");
INSERT INTO config_data VALUES ("key_2", "value_2");
And also how to retreive all rows:
SELECT * FROM config_data;
It's the fancy combinations that elude me :)