Skip to main content
[Edit removed during grace period]
Source Link
nicorellius
  • 4.2k
  • 5
  • 56
  • 81
edited title
Link
nicorellius
  • 4.2k
  • 5
  • 56
  • 81

Python and SQLite Query Strings - Python String Formatting

Source Link
nicorellius
  • 4.2k
  • 5
  • 56
  • 81

Python and SQLite Query Strings - String Formatting

I've been reading up on string formatting, concatenation, etc in Python and ran into an issue. Given a python object, how come this works in SQLite:

for table in tables: query = 'PRAGMA table_info(%s);' % table results = connection.execute(query) . . . 

but this doesn't:

for table in tables: query = 'PRAGMA table_info({0});'.format(table) results = connection.execute(query) 

Error for the second version:

database error: near "(": syntax error