Re: [sqlite] a question on the callback function's return values of sqlite3_exec()

2009-02-24 Thread liubin liu

Thank you very much!

this is my first time to use sqlite3. using prepared statements is a little
difficult. Could I avert to another way(more simple way) to achieve the same
thing?

Or where could I get some example codes on the method of using prepared
statements?


Igor Tandetnik wrote:
> 
> "liubin liu" <7101...@sina.com> wrote in message
> news:22176984.p...@talk.nabble.com
>> the question is on the callback function's return values of
>> sqlite3_exec()
>>
>> when using sqlite3_exec() to do "select * from ...", how to get all
>> the return values by using the callback function?
>>
>> it could print the result, but couldn't return the values. If do like
>> so, just one value could be get.
>> how to get all the values?
> 
> Memory allocated for value[] strings is valid only inside the callback. 
> It is deallocated or reused as soon as the callback returns. So, you 
> can't just store a pointer you receive - it'll soon become invalid. You 
> need to allocate your own memory and make a copy of string contents.
> 
> Also, consider using prepared statements instead of sqlite3_exec - see 
> sqlite3_prepare, sqlite3_step, sqlite3_finalize, sqlite3_column_*. For 
> one thing, values of numeric fields could be retrieved directly as 
> integers, rather than converted to strings and then converted back.
> 
> Igor Tandetnik
> 
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/a-question-on-the-callback-function%27s-return-values-of-sqlite3_exec%28%29-tp22176984p22194312.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] a question on the callback function's return values of sqlite3_exec()

2009-02-24 Thread Igor Tandetnik
"liubin liu" <7101...@sina.com> wrote in message
news:22176984.p...@talk.nabble.com
> the question is on the callback function's return values of
> sqlite3_exec()
>
> when using sqlite3_exec() to do "select * from ...", how to get all
> the return values by using the callback function?
>
> it could print the result, but couldn't return the values. If do like
> so, just one value could be get.
> how to get all the values?

Memory allocated for value[] strings is valid only inside the callback. 
It is deallocated or reused as soon as the callback returns. So, you 
can't just store a pointer you receive - it'll soon become invalid. You 
need to allocate your own memory and make a copy of string contents.

Also, consider using prepared statements instead of sqlite3_exec - see 
sqlite3_prepare, sqlite3_step, sqlite3_finalize, sqlite3_column_*. For 
one thing, values of numeric fields could be retrieved directly as 
integers, rather than converted to strings and then converted back.

Igor Tandetnik



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] a question on the callback function's return values of sqlite3_exec()

2009-02-23 Thread liubin liu

the question is on the callback function's return values of sqlite3_exec()

when using sqlite3_exec() to do "select * from ...", how to get all the
return values by using the callback function?

struct olt_info
{

int olt_index;
int olt_logo;
char* olt_line;
// int nmber;
};

int my_callback(void *olt_temp, int argc, char *value[], char *name[])
{
struct olt_info *pdata = NULL;
pdata = (struct olt_info *)olt_temp; 

int jj;
for (int i = 0; i < argc; i++)
jj = printf("%s == %s\n", name[i], value[i]);

pdata->olt_index = (int)atoi(value[0]);
pdata->olt_logo = (int)atoi(value[1]);
pdata->olt_line = value[2];

return 0;
}

it could print the result, but couldn't return the values. If do like so,
just one value could be get.
how to get all the values?

-- 
View this message in context: 
http://www.nabble.com/a-question-on-the-callback-function%27s-return-values-of-sqlite3_exec%28%29-tp22176984p22176984.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users