Re: [pysqlite] [APSW] "SQLError: cannot rollback - no transaction is active"
Michael Schlenker <[email protected]> Mon, 01 Dec 2008 14:41:53 +0100
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Organization | Contact Software GmbH |
| Message-ID | <[email protected]> |
Roger Binns schrieb: > Eric S. Johansson wrote: >> I tend to use >> string substitution when I have a case where I'm generating some SQL because I >> have varying conditions which require very different SQL expressions. > > I still fail to understand why string substitution is easy and using > bindings is hard. With string substitution you have a format string, > the % operator and then the parameters. Bindings are the same thing. One important exception: "SELECT foo WHERE bar IN (%s)" % ",".join(["'%s'" % str(val) for val in l]) this works with string substitution, but: "SELECT foo WHERE bar IN (%)", l does not usually..., Unless pysqlite got really clever in the meantime and I did not notice. You can work around it with some horrible pivot table hacks, and string processing in SQL but its pretty ugly, or you can generate not a single bind parameter but a bunch of them, depending on your list length, also ugly, but a bit less so. Michael -- Michael Schlenker Software Engineer CONTACT Software GmbH Tel.: +49 (421) 20153-80 Wiener Straße 1-3 Fax: +49 (421) 20153-41 28359 Bremen http://www.contact.de/ E-Mail: [email protected] Sitz der Gesellschaft: Bremen Geschäftsführer: Karl Heinz Zachries, Ralf Holtgrefe Eingetragen im Handelsregister des Amtsgerichts Bremen unter HRB 13215