NAME
RunSqlInsertIfDoesNotExist — Do an insert unless an entry already exists.
SYNOPSIS
RunSqlInsertIfDoesNotExist TableName DictValue
DESCRIPTION
Return Value
Id of the record, pre-existing or newly created.
Arguments
TableNameName of the table to do search / insert on.
DictValueDict containing values to search for and insert if not found.
More Info
This command will use the keys / values in the dict to construct a WHERE clause for a SELECT statement and search for the record. If no record is found then it will use that same data to do an INSERT.

Note that for the dicts, you (currently) must put quotes around any values that will go into text columns or receive an error. We may add support in a future release for automatically detecting the column type and quoting values as necessary.

Note that, as with other commands, this command assumes that the table will have a column "id", which is the primary key.

If you want to break the dict down into two dicts, one used to check if the entry exists and the other with the values, then take a look at RunSqlEnter.

Check this page for info about how to set up Gen for using database-related commands.


For information regarding exceptions / errors, see here.
EXAMPLES
% RunSqlCreate my_table {id {integer primary key} desc text notes text}
% QQ [SqlInsertStatement my_table {desc 'one' notes 'uno'}]
% RunSqlInsertIfDoesNotExist my_table {desc 'one' notes 'uno'}
% RunSqlInsertIfDoesNotExist my_table {desc 'two' notes 'dos'}
% QQ [SqlSelectStatement my_table {desc notes}]
one uno two dos
SEE ALSO
RunSqlEnter, SqlInsertStatement
KEYWORDS
sql