Nick Collier <nick at src.uchicago.edu> says: >Hi, > >I've been creating SQL statements from dictionaries holding the field >name and the new value to insert or update. As might be expected this >new value is often a number. When turning this number into a string in >order to create the sql statement the number will have a "L" appended if >it is a long. Consequently, the resulting SQL might look like the >following: > >update myTable >set id_num = 23L >where food = 'spam' > >I've been testing if the value is a number whose string representation >ends with "L" and then stripping the "L", but am pretty sure there must >be a better way. If so, any suggestions as to what is? Try (if you're using a module that supports the full Python DB API 1.0): cursor.execute('update myTable set id_num = ? where food = ?', (id_num, food)) This mechanism is much more forgiving than stringifying directly into the query. I've been using this format with great success (including storing binary pickled datastructures and marshalled Python bytecode in the database. Whee!)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4