DDBI update

Lars Ivar Igesund larsivar at igesund.net
Thu Oct 30 12:27:59 PDT 2008


bobef wrote:

>> I want feedback! In particular regarding how to fetch values not as
>> strings
> 
> I imagine the db engines return something like this:
> 
> struct {
>   int type;
>   int int_data;
>   char* char_data;
>   bool bool_data;
>   etc etc_data;
> }

Actually, in mysql, you get the results (in normal mode, not prepared) as
strings, so that is the natural way to return them, but this means that the
user would have to convert them, which they may not want to do. For
prepared statements, you bind storage to the result, and so you get those
data directly into your storage.

> So I image Row.get should look like this:
> 
> T get (T=char[])(int idx) {
>   static if(is(T == char[])) {
>     if(fieldtype == string) return field.char_data;
>     else if(fieldtype == int) return toString(field.int_data);
>     else throw new Exception("Don't know how to convert from
>     "~field.typename~" to "~T.stringof);
>   }
>   else static if() etc....
> }

If this is how SQLite returns the data, then this approach is feasible, but
I need to make sure that the interface used is "portable" over the various
dbms.
 
> At least this is what I do with Sciter to work seamlessly with D, and this
> is what I plan to do with sqlite soon, if there is no other project doing
> it :) In my experience this stuff works great.

SQLite support is the next task for me on DDBI.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango


More information about the Digitalmars-d-announce mailing list