0

I have 3 variables:

var1="abc"
var2="def"
sqlPrefix = "select x,y in myTable where myVar in "

I want to create a string of ('abc','def'), so I can directly concatenate that to the end of sqlPrefx, so my final string is select x,y in myTable where myVar in ('abc','def')

user1008636
  • 2,469
  • 10
  • 26
  • 40

1 Answers1

2

Generally speaking, in order to avoid sql injections you shouldn't construct sql queries manually like this.

But, just FYI, here's how you can shouldn't do it:

sqlPrefix = "select x,y in myTable where myVar in ('%s', '%s')" % (var1, var2)

Also, see: How to use variables in SQL statement in Python?

Community
  • 1
  • 1
alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148