Re: [sqlite] Re: sqlite3_get_table and non-strings

2006-09-22 Thread Dennis Cote

Mark Richards wrote:
I suppose this has already been broached when the design of 
sqlite3_get_table was addressed.  

Mark,

Actually this wasn't broached at that time, because when the 
sqlite_get_table API was designed, sqlite was typeless. All data was 
stored as strings, so it was natural to return all data as strings. This 
is why the legacy APIs sqlite_exec and sqlite_get_table only return 
strings. These APIs were maintained in the new versions for backwards 
compatibility. Only legacy programs should be using those APIs, so they 
would be expecting only string data.


New programs that want to store data using other types should use the 
new 
sqlite_prepare/sqlite_bind_*/sqlite_step/slite_column_*/sqlite_finalize 
APIs. It is much easier than trying to undo the string conversions that 
sqlite does using the old APIs.


HTH
Dennis Cote

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] Re: sqlite3_get_table and non-strings

2006-09-22 Thread Mark Richards

> Do you expect sqlite3_get_table to look at char*** pointer and somehow
> guess that it's a structure, and figure out types of individual
> fields? How would you go about implementing something like that?

Ha!  Good question.  I suppose this has already been broached when the 
design of sqlite3_get_table was addressed.  My first thought would be to 
pass sqlite3_get_table a structure that represents the table in 
field-order.  ie:


CREATE TABLE sequence (seq_nr INTEGER NOT NULL PRIMARY KEY, seq_family 
INTEGER, enable INTEGER, verb TEXT(80));	


typedef struct _sequence
{
int seq_nr;
int seq_family;
int enable;
char text[16];
} sequence[10];

Then when each row is parsed each column is populated into the 
associated structure element based on the field type of the column. 
sqlite ought to know that as it's likely an internal value.


I've already written a function like this that works with sqlite_exec to 
a callback.  Packaging it in sqlite3_get_table would simplify some tasks 
but clearly wouldn't offer a generic solution (you'd have to create a 
structure for each table you want to get, and make sure that your SELECT 
statement will generate the columns in the order of your structure).


In C is there such a thing as a structure created dynamically (at runtime)?

--

I'll have a look at sqlite3_prepare, sqlite3_step and sqlite3_column_


/m




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Re: sqlite3_get_table and non-strings

2006-09-22 Thread Igor Tandetnik

Mark Richards <[EMAIL PROTECTED]>
wrote:

Although it does not appear to be mentioned in the documentation, is
it correct to assume that sqlite3_get_table can only handle string
datatypes?


It can read any data type from the database, but it converts everything 
to strings before returning to caller.


Yet another reason to use sqlite3_prepare, sqlite3_step and 
sqlite3_column_* instead.



Is sqlite3_get_table intended to work properly if it is I passed a
structure that represents the data I want it to return?


Do you expect sqlite3_get_table to look at char*** pointer and somehow 
guess that it's a structure, and figure out types of individual fields? 
How would you go about implementing something like that?


Igor Tandetnik 



-
To unsubscribe, send email to [EMAIL PROTECTED]
-