[sqlalchemy] Re: [Fwd: [sqlalchemy] Re: scalar select: wrong result types]
without seeing a full example, its looking like a mysql bug. SA's datetime implementation for MySQL doesnt do any conversion from return value since MySQLDB handles that task. whereas the sqlite dialect in SA *does* do conversion since sqlite doesnt handle that. Below my small example (It doesn't clarify where the problem is) I hope someone else will check it, with other databases too (postgres, for example) I hope it can help My results: sqlite_engine (True, True) mysql_engine (False, False) My configuration: debian etch sqlite 3 sqlalchemy trunk Revision: 2212 mysql 5.0.30 python 2.4.4 Alessandro PS: I hope this email will keep identation. I have also put this test in http://pastebin.com/861936 import datetime from sqlalchemy import * def check(engine): mytest = Table('mytest', engine, Column('date', DateTime, primary_key=True, \ default=datetime.datetime.now)) try: mytest.drop() except: pass mytest.create() mytest.insert().execute() tt = mytest.alias('tt') selTagged = select([tt.c.date, select([tt.c.date], tt.c.date==mytest.c.date, from_obj=[mytest], limit=1, offset=0, scalar=True).label('last_mod')] ) #Note: 'text' need typemap selText = text(selTagged.__str__(), engine, \ typemap={'last_mod':types.DateTime}) def isdatetime(sel): return isinstance(sel.execute().fetchone().last_mod, \ datetime.datetime) return isdatetime(selTagged), isdatetime(selText) sqlite_engine = create_engine('sqlite:///database_test.db') mysql_engine = create_engine('mysql://[EMAIL PROTECTED]/xxx') print sqlite_engine, check(sqlite_engine) print mysql_engine, check(mysql_engine) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: scalar select: wrong result types
the above query you are issuing straight textual SQL. SA has no clue what types to return and it has no say in it - the inconsistent behavior above originates within your database/DBAPI (which you havent told me which one it is). I'm using Mysql5 A very simple table that give me problems: mytest = Table('mytest', enginedb_test, Column('id', Integer, primary_key=True, nullable=False), Column('creation_date', DateTime, default=datetime.datetime.now), mysql_engine='InnoDB') you can issue textual sql using the typemap parameter to text(): s = text(some sql, typemap={'x':types.DateTime}) It doesn't work; result is a 'str' type res = sq.text( SELECT w2.id, (SELECT w2t.creation_date AS creation_date FROM mytest AS w2t where w2t.id=w2.id LIMIT 1 OFFSET 0) as last_mod FROM mytest AS w2 , enginedb_test, typemap={'last_mod':sq.types.DateTime}).execute().fetchone() special. the text clause above should work better (or at least is intended for this scenario). also the type should be propigated through the label() youre creating above, i thought perhaps it might not but i added a test case in 2206 that shows it does. Yes, the test works fine! I tried to switch db engine: it works for sqlite, it doesn't for mysql... #works enginedb_test = create_engine('sqlite:///database_test.db') = (1, datetime.datetime(2007, 1, 17, 14, 33, 21, 483043)) #doen't work enginedb_test = create_engine('mysql://name:[EMAIL PROTECTED]/dbname') = (1L, '2007-01-17 14:30:20') It is a mysql engine bug? Thanks for your help Alessandro -- Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom http://click.libero.it/infostrada17gen07 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: scalar select: wrong result types
without seeing a full example, its looking like a mysql bug. SA's datetime implementation for MySQL doesnt do any conversion from return value since MySQLDB handles that task. whereas the sqlite dialect in SA *does* do conversion since sqlite doesnt handle that. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---