> Unfortunately I'm not able to grasp the new functions, I've read > through > http://www.sqlite.org/capi3.html but I can't picture how I would set > up > these functions. Is there an updated sample or tutorial? Or could > someone > explain the basic routine for extracting the columnnames/amount of > columns/amount of rows and all the data in an array?
You want to: 1. prepare 2. bind 3. step 4. finalize It should be simple to make a wrapper using STL/MFC/OWL to encapsulate this: ---- 1. Prepare: http://sqlite.org/capi3ref.html#sqlite3_prepare "To execute an SQL query, it must first be compiled into a byte-code program using one of the following routines..." int sqlite3_prepare( sqlite3 *db, /* Database handle */ const char *zSql, /* SQL statement, UTF-8 encoded */ int nBytes, /* Length of zSql in bytes. */ sqlite3_stmt **ppStmt, /* OUT: Statement handle */ const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); 2. bind: Tell sqlite where to find parameters used in your sql. "Select * from bob where id = ? and name = ?" The first '?' is paramter #1, etc. http://sqlite.org/capi3ref.html#sqlite3_bind_int int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); int sqlite3_bind_double(sqlite3_stmt*, int, double); int sqlite3_bind_int(sqlite3_stmt*, int, int); int sqlite3_bind_int64(sqlite3_stmt*, int, long long int); int sqlite3_bind_null(sqlite3_stmt*, int); int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 3. Step: Run the sql query, returning one row at a time. http://sqlite.org/capi3ref.html#sqlite3_step int sqlite3_step(sqlite3_stmt*); 4. finalize free the memory used by the query and prepare engine for next use. http://sqlite.org/capi3ref.html#sqlite3_finalize The sqlite3_finalize() function is called to delete a prepared SQL statement obtained by a previous call to sqlite3_prepare() or sqlite3_prepare16(). If the statement was executed successfully, or not executed at all, then SQLITE_OK is returned. If execution of the statement failed then an error code is returned. All prepared statements must finalized before sqlite3_close() is called or else the close will fail with a return code of SQLITE_BUSY. --- C++ example: string sql = "SELECT name, sql" " FROM sqlite_master" " WHERE type = 'table'"; // connect to database rc = sqlite3_open( dbNameInput.c_str(), &dbInput ); if ( rc ) throw "Can't open source database"; if ( sqlite3_prepare( dbInput, sql.c_str(), sql.size(), &pStmt, NULL ) != SQLITE_OK ) throw "Cannot prepare sql"; Loop = true; while ( Loop ) switch ( sqlite3_step( pStmt ) ) { case SQLITE_ROW: { char* p; string Name; // get results ( 0 based index!!! ) p = (char *) sqlite3_column_text( pStmt, 0 ); if ( ! p ) throw "blank table names in source database"; Name = p; p = (char *) sqlite3_column_text( pStmt, 1 ); if ( ! p ) throw "blank sql in source database"; sql = p; // copy table to list tables.push_back( table( Name, sql ) ); } break; case SQLITE_DONE: Loop = false; break; default: throw "Cannot execute sql"; break; } // clean up when finished sqlite3_finalize( pStmt ); sqlite3_close( dbInput ); --------------------------------- You a Gamer? If you're near Kansas City, ask me about the Recruits and Conquest conventions. --------------------------------- The Castles of Dereth Calendar: a tour of the art and architecture of Asheron's Call http://www.lulu.com/content/77264 __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com