I'm creating functions for use with a game server. This server uses plugins. I have these functions which use an SQLite database, along with apsw to retrieve items stored by another function. I have 3 questions on this.
Question One: I keep getting the error "SQLError: near "?": syntax error" Since my statement features multiple ?
, it's proving hard to track down what is exactly wrong. So what is wrong?
Question Two: I know about SQL-Injection, but these functions only take input from the runner of the script, and the only stuff he would be damaging is his own. Even so, is there an easy way to make this SQL-injection proof?
Question Three: Is there any way to make this function more efficient?
Here's what it looks like now:
def readdb(self,entry,column,returncolumn = "id,matbefore,matafter,name,date"):
self.memwrite
if isinstance(entry, int) or isinstance(entry, str):
statement = 'SELECT {0} FROM main WHERE {1} IN {2}'.format(returncolumn,column,entry)
self.memcursor.execute(statement)
blockinfo = self.memcursor.fetchall()
return(blockinfo)
if isinstance(entry, tuple) or isinstance(entry, list):
statement = '''SELECT {0} FROM main WHERE {1} IN (%s)'''.format(returncolumn,column)
self.memcursor.execute(statement % ("?," * len(entry))[:-1], entry)
blockinfo = self.memcursor.fetchall()
return(blockinfo