[Development] Fwd: Re: Proposing QSqlQuery syntax sugar
André Somers
andre at familiesomers.nl
Wed Sep 19 11:40:43 CEST 2012
Op 19-9-2012 11:32, Andras Mantia schreef:
> Thiago A. Corrêa wrote:
>
>> Hi,
>>
>> I'd like to propose a templated QSqlQuery::value in the same way
>> QVariant::value works. This syntax suggar allows one to write:
>>
>> QSqlQuery query;
>> ...
>> int myvalue = query.value<int>(0);
>>
>> Instead of the current:
>> int myvalue = query.value(0).toInt();
> QSqlQuery::value() returns a QVariant already, so anything that works for
> QVariant works here as well (the .toInt() there is a QVariant method).
Sure, but then you'd have to use
int myvalue = query.value(0).value<int>();
The double value in that call is not so nice.
I think the suggestion was to overload value in QSqlQuery to directly
allow the template version:
int myvalue = query.value<int>(0);
or
int myvalue = query.value<int>("MyColumnName"); //using the also
proposed string version.
Just a bit of syntactic sugar, of course, but nice. I do think there are
some problems with error checking though. What happens if "MyColumnName"
doesn't contain an int but a string in the above call?
André
More information about the Development
mailing list