d-dbapi ALPHA-2 released

Myron Alexander someone at somewhere.com
Sun Jun 10 17:28:28 PDT 2007


Kirk McDonald wrote:
> The tricky part is that, since D is a statically typed language, you 
> must /always/ know the type of something when it comes time to use it. 
> In other words, if you don't know the types involved, you can't extract 
> the data and use it.

For application specific programs, I agree 100% but there are a class of 
utilities where the handling of result types at runtime is required.

Since you make a very good point, I don't see why I can't look into 
changing the interface to use type-safe fetches as well as having the 
option of using Boxes.

I wrote a quick spike to test the case since I am not completely up to 
speed on variadic templates:

> import std.stdio;
> 
> struct Row(T ...) {
>    T              t;
>    bool[T.length] nullFlag;
> }
> 
> Row!(T) fetchOne(T ...) () {
>    Row!(T) r;
>    r.t[0] = 1;
>    r.t[1] = "Hello World";
>    r.t[2] = 5.0;
>    //r.nullFlag = new bool[r.t.length];
>    r.nullFlag[0] = false; 
>    r.nullFlag[1] = true; 
>    r.nullFlag[2] = false; 
>    return r;
> }
> 
> void main () {
>    auto row = fetchOne!(int, char[], double) ();
>    writefln("%d, %s, %#.2f", row.t[0], row.t[1], row.t[2]);
>    writefln("%s, %s, %s", typeid(typeof(row.t[0])), typeid(typeof(row.t[1])), typeid(typeof(row.t[2])));
>    writefln ("%s  --  %s", row.nullFlag.length, typeid(typeof(row.nullFlag)));
>    foreach (n; row.nullFlag) {
>       writefln ("%s", n);
>    }
> }

It works, and it makes sense.

I need to think about how to integrate all the ideas so I can have the 
best of both worlds without it being a complex mess, and conforming to DRY.

Regards,

Myron.



More information about the Digitalmars-d-announce mailing list