[Sqlalchemy-tickets] [sqlalchemy] #1748: func.now() does not work with multi-inserts
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2010-03-26 04:07:55
|
#1748: func.now() does not work with multi-inserts
--------------------+-------------------------------------------------------
Reporter: guest | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone:
Component: engine | Severity: no triage selected yet
Keywords: | Status_field: awaiting triage
--------------------+-------------------------------------------------------
If I use the following code execute inserts one at a time where one of the
values is func.now(), I get the expected result:
{{{
qi_sess_t = table.pl_QueryInvocation_Session
for qi_pg in queryInvocationsAndPages:
if ( not isinstance( qi_pg, tuple ) ):
continue
stmt = qi_sess_t.insert().values( {
'queryInvocation_id': qi_pg[ 0 ].id,
'session_id': session.id,
'createdAt': func.now(),
} )
session.bind.echo = True
session.execute( stmt )
session.bind.echo = False
}}}
Output:
{{{
2010-03-25 20:57:53,923: INFO
sqlalchemy.engine.base.Engine.0x...bccL INSERT INTO
`pl_QueryInvocation_Session` (`queryInvocation_id`, session_id,
`createdAt`) VALUES (%s, %s, now())
2010-03-25 20:57:53,924: INFO
sqlalchemy.engine.base.Engine.0x...bccL [30076L, 3211L]
}}}
However, if I try to use the executemany form, func.now() doesn't seem to
be handled (compiled?) correctly:
{{{
qi_sess_t = table.pl_QueryInvocation_Session
stmt = qi_sess_t.insert()
values = [{
'queryInvocation_id': qi_pg[ 0 ].id,
'session_id': session.id,
'createdAt': func.now(),
}
for qi_pg in queryInvocationsAndPages
if ( isinstance( qi_pg, tuple ) )
]
session.bind.echo = True
session.execute( stmt, values )
session.bind.echo = False
}}}
Output:
{{{
2010-03-25 20:57:53,925: INFO
sqlalchemy.engine.base.Engine.0x...bccL INSERT INTO
`pl_QueryInvocation_Session` (`queryInvocation_id`, session_id,
`createdAt`) VALUES (%s, %s, %s)
2010-03-25 20:57:53,926: INFO
sqlalchemy.engine.base.Engine.0x...bccL [[30061L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673f6ac; now>], [30062L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673ff4c; now>], [30063L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673f0ac; now>], [30064L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673f4ec; now>], [30065L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6706c4c; now>], [30066L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6706bac; now>], [30067L, 3211L,
<sqlalchemy.sql.functions.now at 0xb67060cc; now>], [30068L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670696c; now>], [30069L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670672c; now>], [30070L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6742c2c; now>], [30071L, 3211L,
<sqlalchemy.sql.functions.now at 0xb674246c; now>], [30072L, 3211L,
<sqlalchemy.sql.functions.now at 0xb67428ac; now>], [30073L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6759e6c; now>], [30074L, 3211L,
<sqlalchemy.sql.functions.now at 0xb67591ac; now>], [30075L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670f64c; now>], [30076L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670fb8c; now>]]
2010-03-25 20:57:53,926: INFO
sqlalchemy.engine.base.Engine.0x...bccL [[30061L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673f6ac; now>], [30062L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673ff4c; now>], [30063L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673f0ac; now>], [30064L, 3211L,
<sqlalchemy.sql.functions.now at 0xb673f4ec; now>], [30065L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6706c4c; now>], [30066L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6706bac; now>], [30067L, 3211L,
<sqlalchemy.sql.functions.now at 0xb67060cc; now>], [30068L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670696c; now>], [30069L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670672c; now>], [30070L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6742c2c; now>], [30071L, 3211L,
<sqlalchemy.sql.functions.now at 0xb674246c; now>], [30072L, 3211L,
<sqlalchemy.sql.functions.now at 0xb67428ac; now>], [30073L, 3211L,
<sqlalchemy.sql.functions.now at 0xb6759e6c; now>], [30074L, 3211L,
<sqlalchemy.sql.functions.now at 0xb67591ac; now>], [30075L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670f64c; now>], [30076L, 3211L,
<sqlalchemy.sql.functions.now at 0xb670fb8c; now>]]
/lib/python2.6/site-
packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/MySQLdb/cursors.py:89:
DeprecationWarning: functions overriding warnings.showwarning() must
support the 'line' argument
/lib/python2.6/site-
packages/MySQL_python-1.2.3c1-py2.6-linux-i686.egg/MySQLdb/cursors.py:205:
Warning: Data truncated for column 'createdAt' at row 1
}}}
I'm using python 2.6, sqlalchemy 0.5.6, and mysql 5.1
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/1748>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|