[std.database]

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 9 11:21:27 PDT 2011


On 10/9/11 11:15 AM, Steve Teale wrote:
> If using variants for a set of out parameters you must have something
> equivalent to:
>
> Variant[3] va;
> va[0] = cast(byte) 0;
> va[1] = 0.0F;
> va[2] = cast(char[]) [];
>
> So you have to have exactly the same information at compile time for the
> Variant array as you do for the struct - you still have to specify a set
> of types.

Not at all, fortunately it's much simpler than that. Far as I can tell, 
a resultset emitted by a DBMS comes in the form of data (either untyped 
buffers or strings) plus column type information, usually in the form of 
an enumeration (e.g. 0 for NULL, 1 for int, 2 for double, 3 for string 
etc). You of course also have the total column count. So all you need to 
do is use that enum to pour the data into the Variants.

See this for example:

http://msdn.microsoft.com/en-us/library/ms131297.aspx

You can glean all needed information from the resultset after having 
issued the query.

> It's probably true to say that the syntax/semantics of the interface will
> suck slightly more in the Variant case than in the struct case.

That's a given. The suckiness won't come, however, in the form of 
additional trips to the database.


Andrei



More information about the Digitalmars-d mailing list