On Sep 23, 2010, at 12:53 PM, Chris Withers wrote:
> On 23/09/2010 15:29, Michael Bayer wrote:
>>>>>> repr(engine.execute(select([sequences.c.current],
>>>>>> sequences.c.name=='foo')).scalar())
>>> 'None'
>>>
>>> Why do I get None instead of an exception raised?
>>
>> 'None' is a scalar....you're thinking of 'query.one()' perhaps.
>
> ...but it has no meaning. My understanding of scalar was that it would take
> the row returned and turn that into a single element so you don't have to do:
>
> tuple(engine.execute(...)[0]).someattribute
>
> I guess I'm off base again, what am I misunderstanding?
this is the docstring for the ultimate implementation of scalar() (meaning, the
scalar() that all the other scalars call):
Fetch the first column of the first row, and close the result set.
Returns None if no row is present.
>> The attribute is -1 in case no .execute*() has been
>> performed on the cursor or the rowcount of the last
>> operation is cannot be determined by the interface. [7]
>>
>> I've never seen a DBAPI that implements rowcount for DQL (maybe MySQLdb
>> does...since they load the whole result anyway).
>
> For successful selects, both sqlite and mysql appear to set this. It sounds
> like you're saying this attribute isn't safe to use, though... what is a
> "right" way to find the number of rows returned from a query, independent of
> the database used?
issue the query a second time using "SELECT COUNT", or do a fetchall() and call
len() on the result.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.