Callbacks are deprecated and harder to use in C++.
try something like this:
sqlite3* db;
sqlite3_stmt *pStmt;
int rc;
bool Loop;
char* p;
int i;
// Get configuration information for this website instance
string sql = "create table contacts"
"( ContactName text, ContactMail text, Description text )"
;
// connect to database
rc = sqlite3_open( argv[1], &db );
if ( rc )
throw "Can't open database";
if ( sqlite3_prepare( db, sql.c_str(), sql.size(), &pStmt,
NULL ) != SQLITE_OK )
throw "Cannot prepare sql";
Loop = true;
for ( i = 0; ( i < 10 ) && ( Loop ); i++ )
switch ( sqlite3_step( pStmt ) )
{
// if database busy wait for a short time
// to see if it becomes available
case SQLITE_BUSY:
case SQLITE_LOCKED:
break;
case SQLITE_ROW:
p = (char *) sqlite3_column_text( pStmt, 0 );
// note replacement of null results with blank here:
ContactName = string( p ? p : "" );
p = (char *) sqlite3_column_text( pStmt, 1 );
ContactMail = string( p ? p : "" );
p = (char *) sqlite3_column_text( pStmt, 2 );
Description = string( p ? p : "" );
break;
case SQLITE_DONE:
Loop = false;
break;
default:
string str = "Cannot execute sql: " + sql + ", Error:
" + sqlite3_errmsg(db);
throw str.c_str();
break;
}
// clean up when finished
sqlite3_finalize( pStmt );
sqlite3_close( db );
On 4/16/05, Kiel W. <[EMAIL PROTECTED]> wrote:
> I've been trying to create a table programatically though C++ without
> luck. Here is what I have:
>
> /*
> * The function that acts as a wrapper around sqlite3_exec
> */
> inline int SqliteGatekeeper::ExecuteSql( const string sql,
> sqlite3_callback CallBack = 0, void*
> callbackParam = 0)
> {
> int rc = sqlite3_exec( database, sql.c_str(), CallBack,
> callbackParam, &zErrMsg );
>
> return rc;
> }
>
> /*
> * The line that is calling this function
> */
> std::cout << gatekeeper->ExecuteSql( "CREATE TABLE t1( a INTEGER
> PRIMARY KEY, b INTEGER);" ) << "\n";
>
> zErrMsg is a private class variable in the same class as this
> function. My return value is "21" which significes I'm using the
> library wrong. I'd appreciate it if someone can point me to what I'm
> doing wrong or a resource that explains creating table this way.
>
> -- Kiel
>
--
---
You a Gamer? If you're near Kansas City:
Conquest 36
https://events.reddawn.net
The Castles of Dereth Calendar: a tour of the art and architecture of
Asheron's Call
http://www.lulu.com/content/77264