On Fri, 30 Oct 2015 14:08:16 -0400
Ramar Collins <ramar.collins at gmail.com> wrote:
> I'm using C and a small library to get the majority of the work
> done. My question is, do you have any suggestions or know where to
> find more lore on how to nicely embed SQL in a program like this?
I store my SQL in separate files, one per statement. Very handy for
testing & development, too, btw.
At initialization, I read all the SQL into a list. In C it might be an
array of structures like
struct query_t { char *name; char *sql; } *queries;
where name is the filename and sql is the content of the file. With
just a little work and the help of bsearch(3), you can refer to your
queries by name and keep the literal SQL out of your code. As others
mentioned, it's better (and easier) to use prepared queries than
string-slinging for parameters.
If you don't want depend on separate files of SQL at runtime, write a
script to generate a .c file of a static array of query_t, as above.
HTH.
--jkl