I'm crafting a storage module based on SQLite internally. Think about it as 'ini files, but with a database'. Since this is my first touch to SQL, and the number of statements I need is rediculously small, I'd like some kind soul to 'proof-read' these and give comments.


Each SQL block is a single statement, and I precompile them with a certain 'section' name baked into the code. Here goes..

Table creation:

Loc_PrepareSql( db, &stmt,
"CREATE TABLE '%q' ( key TEXT UNIQUE ON CONFLICT REPLACE,"
" val VARIANT );", section );


Q #1: What happens if the table already exists? Should I check for that? How?

Value setting & getting:

    Loc_PrepareSql( db, &ud->sql_set,
                    "UPDATE '%q' SET val=?2 WHERE key='?1';", section );

    Loc_PrepareSql( db, &ud->sql_remove_key,
                    "DELETE FROM '%q' WHERE key='?1';", section );

    Loc_PrepareSql( db, &ud->sql_get,
                    "SELECT val FROM '%q' WHERE key='?1';", section );

Key enumeration (returns 1..N keys):

    Loc_PrepareSql( db, &ud->sql_all_keys,
                    "SELECT key FROM '%q';", section );

Key enumeration with a prefix (ie. "subtable.b."):

Loc_PrepareSql( db, &ud->sql_like_keys,
"SELECT key FROM '%q' WHERE key= LIKE '?1.%';", section );


Similar, returns 1..N key + value pairs:

Loc_PrepareSql( db, &ud->sql_like_dump,
"SELECT key,val FROM '%q' WHERE key= LIKE '?1.%';", section );


    Loc_PrepareSql( db, &ud->sql_transaction_begin, "BEGIN;", NULL );

    Loc_PrepareSql( db, &ud->sql_transaction_commit, "COMMIT;", NULL );


Thanks for help, feedback, and encouragement. :)

-ak



Reply via email to