Why doesn't MySQLdb provide a function like this: def QuoteSQL(Str, DoWild) : """returns a MySQL string literal which evaluates to Str. Needed for those times when MySQLdb's automatic quoting isn't good enough.""" Result = [] for Ch in str(Str) : if Ch == "\0" : Ch = "\\0" elif Ch == "\010" : Ch = "\\b" elif Ch == "\011" : Ch = "\\t" elif Ch == "\012" : Ch = "\\n" elif Ch == "\015" : Ch = "\\r" elif Ch == "\032" : Ch = "\\z" elif Ch == "'" or Ch == "\"" or Ch == "\\" : Ch = "\\" + Ch elif DoWild and (Ch == "%" or Ch == "_") : Ch = "\\" + Ch #end if Result.append(Ch) #end for return "\"" + "".join(Result) + "\"" #end QuoteSQL
-- http://mail.python.org/mailman/listinfo/python-list