Well...
At 22:23 11/5/2004 +0100, you wrote:
I've been trying at this for a good few hours now, I'm using sqlite3 and the quick start code at the website.
By using a global "char *buffer[5][220];"
and then doing buffer[i][counter]=argv[i]; I thought I would be able to extract the rows in my table but it does not work. When the program has exited the callback buffer[i][0] equals buffer[i][1] and so on. For some reason all of them will have the values of the last callback execution.
What you do not seem to understand is that the strings passed to the callback function are created (and freed) by SQLite code. You can't keep pointers to them outside of the callback.
For example, you could print out the values using a code like this:
[snip] int counter=0;
static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int k; for(k=0;k<argc;k++) { cout << i << argv[k] << "\t"; } cout << "\n"; return 0; }
rc = sqlite3_exec(db, "SELECT * FROM gg", callback, 0, &zErrMsg); [/snip]
Or, you could keep the values in string; something like:
[snip] int counter=0; std::string values[5][220]; int rows;
static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int k; rows=argc; for(k=0;k<argc;k++) { values[k][counter]= argv[k]; } counter++; return 0; }
rc = sqlite3_exec(db, "SELECT * FROM gg", callback, 0, &zErrMsg); int i,p; for(i=0;i<counter;i++) { for(p=0;p<rows;p++) { cout << i << values[p][i].c_str() << "\t"; } cout << endl; }
[/snip]
Of course, you can use malloc() and free() to create char* instances instead of std::string...
Guy