Re: [sqlite] Extracting values from callback

2004-11-06 Thread aleks ponjavic
Thanks a lot guys, it works great now!
_
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.com/



Re: [sqlite] Extracting values from callback

2004-11-05 Thread Guy Hachlili
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

Re: [sqlite] Extracting values from callback

2004-11-05 Thread Daniel K

> static int callback(void *NotUsed, int argc, char
> **argv, char **azColName){
> int k;
> rows=argc;
> for(k=0;k {
> buffer[k][counter]= argv[k];
> }
> counter++;
> return 0;
> }

The data pointed to by argv[k] only exists for the
duration of the callback. You have to copy the string,
not the pointer. i.e:

buffer[k][counter] = strdup(argv[k]);

(won't work with blobs). Don't forget to free() it
later.



__ 
Do you Yahoo!? 
Check out the new Yahoo! Front Page. 
www.yahoo.com 
 



[sqlite] Extracting values from callback

2004-11-05 Thread aleks ponjavic
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.

int counter=0;
char *buffer[5][220];
int rows;
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
   int k;
   rows=argc;
   for(k=0;k