Richard Stern wrote:
Hi all.

I'm using sqlite in VC++ 2005.
When I started this I knew nothing about sqlite or indeed SQL at all so its
been tough going trying to work out how this all works.

So far I have created a database and a table and added columns and rows
filled with data. But I'm having trouble retrieving that data.

Lets say I have the columns MemberNo, Name and Address.
I want to use a specific MemberNo to retrieve a name and address and store
them in separate variables.

I tried:
sqlite3_exec(AccDataBase,"SELECT Name,Address FROM Accounts WHERE MemberNo =
2;",Callback(cError,10,&result,&Names),test,&cDatabaseError);

Now I don't fully understand how the callback part works so I just made the
variables that seemed appropriate and threw them in. I thought the "result"
one was supposed to get filled by the result of the SELECT, but it wasn't.

When I ran this, no error was returned but the callback didn't seem to do
anything.

So is this the correct command to use? Is there a better/easier way?

Rick,

To use the callback interface you need to define a callback function in your C code. This function MUST have the correct signature so it can be called correctly by sqlite. This signature is defined in sqlite3.h as

/*
** The type for a callback function.
*/
typedef int (*sqlite3_callback)(void*,int,char**, char**);

The sample program at http://www.sqlite.org/quickstart.html shows how to define a callback function.

static int callback(void *user_data, int argc, char **argv, char **azColName)
{
'''
}

Now, when you call sqlite3_exec() you need to pass the address of this function (i.e. its name) to sqlite so that it can call your function when it has a result. Your call will look something like the one on the quickstart page.

rc = *sqlite3_exec*(db, sql_query, callback, my_data, &zErrMsg);


Each time sqlite has a result from your query it will call your callback function and pass it the result data and the column names as parameters. Your function can then do whatever it wants to with this data before it returns. If your query generates 100 result rows, your callback function will be called 100 times.

After you get the sqlite3_exec version working, you should look at the sqlite3_prepare, sqlite3_step, sqlite3_column_* set of APIs which are newer and generally easier to use for queries.

HTH
Dennis Cote

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to