On 02/10/2009, at 12:48 PM, Igor Tandetnik wrote:

> BareFeet wrote:
>> The one hurdle I've struck is how to send a multi-statement SQL
>> command. Say for instance I want to process a bunch of text such as:
>>
>> How do I submit it via C functions?
>
> You run the statements one at a time. sqlite3_prepare et al helpfully
> provide a pointer to the first character past the first complete
> statement.

Ahh, I see. I didn't realise that sqlite_prepare_v2 offers the  
uncompiled remainder.

>> It seems that I need to use sqlite3_get_table() to get the result in
>> one hit, rather than sqlite3_prepare_v2 and stepping through each  
>> row.
>> Is that right?
>
> What's wrong with stepping through each row?

I didn't have a particular objection to it. I was just stating my  
understanding of the difference between using sqlite3_get_table and  
sqlite3_prepare or sqlite3_prepare_v2.

I've tested sqlite3_get_table a bit more. It seems to:

1. Be a much simpler approach if you just want to execute or grab the  
results from a statement or multi-command statement.

2. Returns the column headers in the first row of the result table.

3. Doesn't offer any way to return the data types of the result  
columns or values. They appear to all be strings.

4. Fails if multiple select statements return a different number of  
columns.

By contrast (to points 3 and 4), the sqlite3 command line utility  
handles multiple table outputs (with different numbers of columns)  
fine and seems to understand the types of data if using a mode that  
discerns it. eg:

.headers on
begin;
select 'Mickey' as Name, 65 as Age;
select 'Disneyland' as Suburb, 'USA' as Country;
select 'no' as Test;
end;

fails using sqlite3_get_table but the sqlite3 command line utility  
gives:

Name|Age
Mickey|65

Suburb|Country
Disneyland|USA

Test
no

Is there any way to get this same functionality? Is the only way to  
write my own routines using a loop that keeps running  
sqlite3_prepare_v2 and stepping through the rows of each prepare?

Thanks,
Tom
BareFeet

  --
Comparison of SQLite GUI applications:
http://www.tandb.com.au/sqlite/compare/?ml

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

Reply via email to