Maybe. Here's what I do (in c). DoSql() is a wrapper function. I've
included a callback function (and associated structure) below it.
The call is made thusly:
static char cData[1024];
char query[255];
snprintf(query, QUERY_SIZE, "SELECT * FROM inikeys WHERE inisection =
\"%s\" AND inikey = \"%s\" ",section,key);
if (!DoSql(query, &sql_inirecord_callback, nDoSqlTimeout))
{
FORMAT_TRACE(ERR_DEBUG,"aem.db temporarily locked by another
process. Cannot continue");
return("");
}
int DoSql(char *query, int (*callback) (), int nRetrySeconds)
{
int nResult=0;
nSQLRetry=0;
char *cError;
db=sqlite_open("/var/tmp/solarwave/aem.db", 0, NULL);
sqlite_busy_timeout(db,1000);
printf("DoSql gets query=->%s<-\n",query);
while (nSQLRetry<=nRetrySeconds)
{
nResult=sqlite_exec(db, query, callback, NULL, &cError);
if (nResult==SQLITE_BUSY || nResult==SQLITE_LOCKED)
{
if (nSQLRetry==0)
printf("Sleeping ");
else
printf(".");
sleep(1);
++nSQLRetry;
continue;
}
if (nSQLRetry>0)
printf("\n");
break;
}
if (nResult==SQLITE_BUSY || nResult==SQLITE_LOCKED)
{
FORMAT_TRACE(ERR_CRIT,"DoSql: aem.db temporarily locked by
another process. Cannot continue");
free(cError);
sqlite_close(db);
return(false);
}
if (!(nResult==0))
{
FORMAT_TRACE(ERR_CRIT,"DoSql: query %s returned error %s.
Cannot continue",query, cError);
free(cError);
sqlite_close(db);
return(false);
}
free(cError);
sqlite_close(db);
return(true);
}
struct _inirecord
{
int record_key;
char inisection[30];
char inikey[30];
char iniline[255];
} inirecord[1];
int sql_inirecord_callback(void *args, int numCols, char **results, char
**columnNames)
{
int i;
for (i=0; i<numCols; i++)
{
//printf("sql_inirecord_callback() column %i value
%s\n",i,results[i]);
if (i==0)
inirecord[0].record_key=atoi(results[i]);
if (i==1)
strncpy(inirecord[0].inisection,results[i],30);
if (i==2)
strncpy(inirecord[0].inikey,results[i],30);
if (i==3)
strncpy(inirecord[0].iniline,results[i],255);
}
return(0);
}
Lloyd Thomas wrote:
I know nothing of C++ and therefore need a lilte help editing a C++ app
to insert some records into a database.
This is where I am so far
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------