Thanks Igor for your help, it is much appreciated. Now my step two looks like this
//2 . ) create a table sqlite3_stmt** stmt; std::string create_table("CREATE TABLE friend (name TEXT, address TEXT, age INT)"); rc = sqlite3_prepare_v2( db, /* Database handle */ create_table.c_str() , /* SQL statement, UTF-8 encoded */ create_table.length(), /* Maximum length of zSql in bytes. */ stmt, /* OUT: Statement handle */ NULL /* OUT: Pointer to unused portion of zSql */ ); if(rc != SQLITE_OK) { sqlite3_close(db); std::cout << "error prepare_v2" << std::endl; exit(-1); } however, this gives me a run time error that reads *#0 00000000 0x00446642 in ??() (??:??)* What did I do wrong? ----- Original Message ----- From: Igor Tandetnik Sent: 06/17/12 05:41 PM To: sqlite-users@sqlite.org Subject: Re: [sqlite] C++ programming - int sqlite3_prepare_v2() question Arbol One <arbol...@programmer.net> wrote: > rc = sqlite3_open_v2(dbName.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, vfs.data()); Just pass NULL for the last parameter. There is very rarely a need to pass anything else. > *//2 . ) create a table > std::string create_table("CREATE TABLE friend (name TEXT, address TEXT, age INT)"); > rc = sqlite3_prepare_v2( > &db, /* Database handle */ Drop the ampersand. Note that, while sqlite3_open_v2 takes sqlite3** (two stars), sqlite3_prepare_v2 wants sqlite3* (one star). > creat_table.c_str() , /* SQL statement, UTF-8 encoded */ > ??, /* Maximum length of zSql in bytes. */ You can pass creat_table.length(), or simply pass -1 and have SQLite accept all characters up to the terminating NUL. > ??, /* OUT: Statement handle */ Same story as with sqlite3_open_v2 and DB handle. You declare a variable like "sqlite3_stmt* stmt;", then pass &stmt. > ?? /* OUT: Pointer to unused portion of zSql */ Just pass NULL. This is used when y ou have a single string containing multiple statements. Note that sqlite3_prepare_v2 only prepares the statement, but doesn't actually execute it. To run the statement, you would call sqlite3_step. After you are done, call sqlite3_finalize to free resources associated with the statement; and sqlite3_close to close your database connection. -- Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users