[sqlalchemy] Re: table name bind param
also to clarify, the text actually has :table_name used in many other places: t = metadata.engine.text(LOCK TABLE :table_name WRITE; UPDATE :table_name SET rgt=rgt + 2 WHERE rgt :insert_node_val and parent_id = :parent_id; UPDATE :table_name SET lft=lft + 2 WHERE lft :insert_node_val and parent_id = :parent_id; .. so if i had it as %s, i would have to repeat the same name multiple times in % (name, name, name). I'm ok with this, just curious if there is a better way. thanks. On Mar 15, 9:37 am, tml [EMAIL PROTECTED] wrote: t = metadata.engine.text(LOCK TABLE :table_name WRITE; , bindparams=[bindparam('table_name', type=types.String)]) will not work as the generated statement looks like: LOCK TABLE 'my_table_name' WRITE; Is there any other type I can specify which doesn't quote the string for tablename? The table name isn't input by user. I get it from self.mapper.local_table.name inside a class's method. thanks. --~--~-~--~~~---~--~~ 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: table name bind param
tml wrote: also to clarify, the text actually has :table_name used in many other places: t = metadata.engine.text(LOCK TABLE :table_name WRITE; UPDATE :table_name SET rgt=rgt + 2 WHERE rgt :insert_node_val and parent_id = :parent_id; UPDATE :table_name SET lft=lft + 2 WHERE lft :insert_node_val and parent_id = :parent_id; .. so if i had it as %s, i would have to repeat the same name multiple times in % (name, name, name). I'm ok with this, just curious if there is a better way. I don't think bind parameters can be used for table names, so you are stuck with python format strings, but you can use a dictionary instead of a tuple when formatting strings. Instead of using %s, you use %(name)s, and instead of the tuple (name, name, name) you pass a single dictionary {'name': your_table_name} http://docs.python.org/lib/typesseq-strings.html Hope that helps, Simon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---