[std.database]

Steve Teale steve.teale at britseyeview.com
Mon Oct 10 09:43:16 PDT 2011


On Mon, 10 Oct 2011 10:09:34 -0500, Andrei Alexandrescu wrote:

> On 10/10/11 7:01 AM, Steve Teale wrote:
>>>
>>> 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
>>
>> Maybe in some cases. But at least with MySQL you have to bind before
>> you fetch, and you don't have the meta-data about the columns until
>> after the fetch, so you have to insert a call to
>> mysql_stmt_result_metadata() to set up the Variant types before you
>> bind.
> 
> I'm confused. Isn't binding setting values to parameters prior to
> executing a query? That's a different thing from getting the row of a
> resultset.
> 
> So, you first prepare, bind, and execute a query. Then you call
> mysql_stmt_result_metadata() to get the number of columns in the
> result set and their individual types. At that point you get to allocate
> the Variant[] row appropriately. After that you're ready to iterate
> rows.

I was not making a big deal. I was just comparing operations with a struct 
to operations with an array of Variants. With a struct I can automate the 
construction of the OUT binding parameters before executing the query. If 
the user, with knowledge of the expected results cares to assign 
appropriate values to each array element in the Variant array, that can 
be done prior to execution also, and I guess it is not much more effort 
than defining the struct. But if the initialization of the array is to be 
automated, I first have to get the metadata. I presume that information 
comes from the server - perhaps it doesn't. But if it does, then in the 
Variant array case, there's an extra server call.

>> I also discovered after some time wasted this morning that the MySQL
>> struct used for date/time is too big for Variant.
> 
> That's a bug in std.variant. Large structs should be supported
> automatically by using an indirection and dynamic allocation.

OK, I can work around it for now, since in a sense they are supported 
now. All I had to do was:

alias VariantN!(maxSize!(creal, char[], void delegate(),
                MYSQL_DATETIME ...)) MyVariant;

Steve



More information about the Digitalmars-d mailing list