string class variable to sqlite3
andybrookestar at googlemail.com
andybrookestar at googlemail.com
Sun Oct 18 11:11:35 EDT 2015
cheers Mark,
it was the syntax that was foxing me; I don't like the example of the select statement via the insecure approach because the writer is adding an element of ambiguity since the table has a field called <symbol> and a variable also called <symbol>
#modifying my class to
import sqlite3
class do:
myString1 = 'uranium'
myString2 = ('lead',)
def doConn(self):
self.conn = sqlite3.connect('encyclopedia')
print "Opened database successfully"
myString3 = 'sulphur'
cursor = self.conn.execute("SELECT * from wiki WHERE one LIKE '%s' "% self.myString1)
#cursor = self.conn.execute("SELECT * from wiki WHERE one =?", self.myString2)
#cursor = self.conn.execute("SELECT * from wiki WHERE one LIKE '%s'" % myString3 )
for row in cursor:
print "ID = ", row[0]
print "NAME = ", row[1]
print "Operation done successfully"
self.conn.close()
x = do()
x.doConn()
#all select statements work , the first two strings are defined under class so referencing with 'self' works. other is defined inside method so doesn't need it.
More information about the Python-list
mailing list