Eric Brunson wrote: > I've got two questions I hope are fairly straight forward: > > 1) I'd like to construct an insert, but specify "on duplicate key > update" (obviously mysql). I've checked out out the manual covering > explicit text, but I'm not sure how to add it to the end of the > statement. Is that even the right way to do it? > > 2) For debugging purposes, I can easily see the text of a statement > I've constructed, but it only contains "%s" tags for where my literals > go. Where can I find the bind parameters so I can print them out, > also? I can see them if the statement throws an exception, but I've > been poring over the attributes of the select, the whereclause and the > booleanexpression and can't find the RHS of my comparisons. >
I apologize if I'm being dense here, but getting completely lost by your visitor pattern. Here's the simple example of what I'm trying to do: t = sa.Table( 'test', md, autoload=True ) s = t.select( t.c.col1 == 'somevalue' ) print select Yields: SELECT test.col1 FROM test WHERE test.col1 = %s I want to print the select statement and the list of string literals that will be bound to any "%s" tokens (i.e. ['somevalue']) I've traced the whereclause through its instantiation in the Select class in sql.py in the append_whereclause, wrapping _append_condition. I follow how the _TextClause parses the statement and I even see where the bind parameters are stored in the _TextClause object and I'm pretty sure the bind parameters are transfered to the whereclause object when the _TextClause accepts the __wherecorrelator as a visitor, but I can't find where the _CorrelatedVisitor class is storing the bind parameters. It seems to inherit its visit_bindparam method from the ClauseVistor class, but there it is defined as "pass". Since I know that the values are displayed when Select.execute() throws and exception, I tried tracing the code backwards from the ClauseElement.execute() method, but the only mention of parameters I can find are the ones passed in as arguments to the execute() method. I've spent about 4 hours going through this code and trying to introspect the select object in running code, but I'm seriously at a loss. I've found where the columns and named bind parameters are stored (select.whereclause.left and right), but I can't find the string literals anywhere in the objects. I'm lost in the layers of abstraction. Someone has to know where these literals are stored and how I can display them. I can't believe I'm the only person that's ever wanted to do this. Thanks for your time, e. P.S. I know I can set MetaData.engine.echo = True, but I don't want all that output, at this point it's practically become a matter of principle. > Thanks for the help, > e. > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
