0

I try to select entries from a table using parametrized queries. They don't return any results. The code is as follows:

var = str.capitalize(var)
selected = db.execute('select a, b, c from table1 where a=(?)', [var])

The var is always a three lowercase character string (e.g. 'xxx'), the 'a' column is of type TEXT in the database, and contains three uppercase character strings (e.g. 'XXX').

I tried also the dreadful:

selected = db.execute('select a, b, c from table1 where a="%s"' % str.capitalize(var)])

because I believed it was a problem with the execute method omitting quotation marks, but it didn't work either. The only thing that got me any results was:

selected = db.execute('select a, b, c from table1 where a="XXX"')

I am using Python 3.6.0 on Windows 10, someone here suggested it might be an issue, but their solution didn't work for me either.

Community
  • 1
  • 1
DCzo
  • 141
  • 2
  • 14

2 Answers2

0

capitalize converts only the first letter into capital. To convert everything into caps, use upper()

Parameter must be passed as tuple/dictionary

Use

selected = db.execute('select a, b, c from table1 where a=?', (var.upper(),))

Or

selected = db.execute('select a, b, c from table1 where a=:var', {"var":var.upper()})

Read more here

Priyesh Kumar
  • 2,837
  • 1
  • 15
  • 29
0

You have to use upper to convert it to all capitalize, try this:

var = var.upper()
selected  =  db.execute('select a, b, c from table1 where a=?', (var,))

this one will work also:

var = var.upper()
selected = db.execute('select a, b, c from table1 where a="%s"'%var]
Tiny.D
  • 6,466
  • 2
  • 15
  • 20