d-dbapi ALPHA-2 released

Myron Alexander someone at somewhere.com
Mon Jun 11 11:45:30 PDT 2007


Christian Kamm wrote:
> Myron Alexander wrote:
>> code
> 
> If there are no other reasons for it, you could avoid the intervening step
> with the Row!(...) temporary struct:
> 
> T fetchstruc(T) () {   
>   static if (is (T == struct)) {
>     T t;
>         
>     // check if last struct field is bool array 
>     // of correct size to store nullflags
>     static if(is(typeof(t.tupleof[$-1]) == bool[t.tupleof.length - 1]))
>     {
>       foreach (i, v; t.tupleof[0..$-1]) {
>         t.tupleof[i] = getRowElement!(typeof(t.tupleof[i]))(i);
>         t.tupleof[$-1][i] = false; // get correct nullflag
>       }                         
>     }
>     else  // ignore nullflag
>     {
>       foreach (i, v; t.tupleof) {
>         t.tupleof[i] = getRowElement!(typeof(t.tupleof[i]))(i);
>       }
>     }
> 
>     return t;
>   } else {
>     static assert (0);
>   }
> }

Thanks Christian.

I prefer to use the fetchone and Row struct as I plan to offer that 
method on the public interface and I don't want to duplicate the code.

The fetchone method is an alternative to the Box[] fetchone method of 
the current library. Thus I will have three ways to extract data: using 
Box[], using Row struct and passing in a value structure.

The first method is for applications that need to handle data types at 
runtime. The second method is for those cases when the developer does 
not want to create a structure for the query; and the last is for the 
developer that just wants to populate a structure from the database.

Any thoughts?

Best Regards,

Myron.



More information about the Digitalmars-d-announce mailing list