I've made my own wrapper class around sqlite for executing database commands.
Its completely generic and supports the use of binds and parameter substitution
through the use of variable arguments (<stdarg.h>) as well as a printf-style
format string that clues the routine into the types of the arguments. For
example:
bRow=m_db.Select( err, &stmt,
"SELECT "
" NAME, "
" FULLPATH, "
" PARENTID "
"FROM DIR "
" WHERE DIRID=?;",
"D,SSD",
dirRid,
&strName,
&dirStrPath,
&parentRid );
The string "D,SSD" tells the Select function about the types of the variable
arguments, and binds parameters or column values as appropriate. In this
example there is one 64-bit integer parameter (a row ID) and three bound
columns; Two of type utf-16 string and one of type 64-bit int.
I'm pretty sure this is not an original idea so what I would like to know is,
has anyone done anything similar? Or come up with different solutions to the
problem of putting a suitable wrapper around SQlite? Or are there any third
party libraries that have done something like this?
I would love to see other people's approach, I'm hoping to pick up some ideas
that will make this system better. Because while it is a nice improvement over
straight sqlite it is not without its problems. The format string is prone to
making mistakes especially when modifying statements and adding more columns or
parameters. And sometimes it is silly seeing "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ? )" in an INSERT statement. Once in a while I forget to add a ?
and it becomes a hard to track bug.
Thanks!
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users