tags:

views:

156

answers:

2

I'm using SQLite to store my program's state. sqlite3_exec() accepts the SQL query as a string. So I have a lot of code that builds such queries by concatenating numerous CString instances and a feeling that I'm doing something wrong.

Is there a better way of doing this staying within primitives provided within SQLite and MFC?

+1  A: 

This excellent piece of code provides a nice C++ wrapper around SQLite3. It has a very nice binding methods, which saves a lot of unnecessary lines from your code (in this case, CStrings). Check it out; there's a lot of examples as well.

nhaa123
A: 

I don't think there is a way to take advantage of the MFC facilites to access the SQLite API in a clearer way.

Due to the fact that the SQLite interface is C-oriented, it might be better to encapsulate the access with a wrapper C++ class and you might use normal arrays of chars and sprintf to fill the dynamic values inside this class (though you could go on with CStrings... if you find them clearer).

We, at work, have a class which encapsulates the access and allows us not to have to build any sql statement explicitly.

The example referred by nhaa123 deserves a +1 vote!

David Alfonso