Sorry but I don't see any parameters being sent to the before_execute 
listener.

For this code:
...
@event.listens_for(engine, "before_execute", named=True)
def before_execute(**kw):
    print "==>BE ce: {}, mp: {}, p: {}".format(kw['clauseelement'], 
kw['multiparams'], kw['params'])

ins = gen_insert_stmt(Boolean, 1 , engine)
engine.connect().execute(ins)

I see this output note the params key is an empty dictionary:
==>BE ce: INSERT INTO testsqlatd.t (id, x) VALUES (?, ?), mp: (), p: {}

The before_cursor_execute does have a parameters value but before_execute 
seems to be empty.  Sorry if I'm being daft.

On Friday, January 16, 2015 at 5:50:50 PM UTC-8, Lycovian wrote:
>
> For a Teradata SA dialect I had posted an earlier question regarding 
> re-writing a query triggered only on Integer columns with primary_key=True. 
>   Thanks to a comment from Mike B I figured out a workaround.  Today though 
> I discovered thought that this issue is due to a rather nasty bug in 
> Teradata's ODBC implementation.  The short version is that via ODBC (in my 
> case PyODBC and Ubuntu) you can not insert any numeric column as None.  Le 
> sigh.
>
> For example here is the issue showing a table can be inserted:
> # connection stuff here 
> t = Table('test', metadata, Column('id', sqlalchemy.Integer(), 
> primary_key=True), Column('x', sqlalchemy.Integer()))
> ins = t.insert().values(x=2).compile()
> engine.connect().execute(ins)
> # success!
>
> ins = t.insert().values(x=None).compile()
> engine.connect().execute(ins)
>
> ...<stack trace>
>
> /home/etl/build/sqlalchemy/lib/sqlalchemy/engine/default.pyc in 
> do_execute(self, cursor, statement, parameters, context)
>     434
>     435     def do_execute(self, cursor, statement, parameters, 
> context=None):
> --> 436         cursor.execute(statement, parameters)
>     437
>     438     def do_execute_no_params(self, cursor, statement, 
> context=None):
>
> DBAPIError: (pyodbc.Error) ('HY000', '[HY000] [Teradata][ODBC Teradata 
> Driver][Teradata Database] The source parcel length does not match data 
> that was defined.  (-2673) (SQLExecDirectW)') [SQL: u'INSERT INTO 
> testsqlatd.test (id, x) VALUES (?, ?)'] [parameters: (Decimal('2'), None)]
>
> This is a rather serious bug in the driver and possibly it has been fixed 
> in later versions of their products ODBC driver but I unfortunately don't 
> have access to any updates. 
>
> I guess the question is basically the same:
> *How do I remove a bindparameter in my dialect if the underlying datatype 
> is numeric (Float/Integer/Boolean/etc) if the statement is an Insert (and 
> update) and the bind value is None?  *
>
> I've been looking at subclassing visit_insert or possibly visit_bindparam 
> to remove parameters that are attempting to set None any number based 
> parameter without success thus far.  Does that sound reasonable?  Anyone 
> have an example of removing a bind parameter from an INSERT statement based 
> on the bound value and the type?
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to