On Feb 11, 2012, at 8:02 AM, Krishnakant Mane wrote: > Hello all, > I have an interesting problem for which I am sure some simple solution must > be existing. > I have made a Python function which I will paist below. > Basically what the function does is that it takes 3 parameters, namely the > name of a stored procedure, engine instance and a set of parameters. > This function is used to make calls to postgresql based stored procedures in > a modular way. > The function is kept central and all my modules just pass the necessary > parameters and leave it to the function to do the rest. > I got it working perfectly, except that I don't know how to handle special > characters when constructing the query that makes a call to a stored > procedure. So if I have an insert query which has a value with a single > quote ('), it crashes.
This is because the function is not using bound parameters. Dealing with individual datatypes and how they are formatted to the database is something you should let the DBAPI handle. SQLAlchemy includes the capability to call functions built in via the "func" parameter. Your execproc could be written as: from sqlalchemy import create_engine, func engine = create_engine('mysql://root@localhost/test', echo=True) def execproc(procname, engine, queryParams=[]): function = getattr(func, procname) function_with_params = function(*queryParams) return engine.execute(function_with_params.execution_options(autocommit=True)) print execproc("concat", engine, ["dog", " ", "cat"]).scalar() -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.