SQL problem in python
aiwarrior
zubeido at yahoo.com.br
Sat Mar 8 11:57:34 EST 2008
class db:
def __init__(self): #constructor
conn = sqlite3.connect(":memory:")
conn.isolation_level = None
self.cursor = conn.cursor()
self.cursor.execute("CREATE TABLE database (album,filepath)")
def add_entry(self, eone , etwo): #Add entry to database
self.cursor.execute("INSERT INTO database (album,filepath)
VALUES (?,?)", ( eone , etwo ) )
return 1 #TODO: exception handler
def get_mediadb(self, print_db = False):
self.cursor.execute('SELECT * FROM database')
if (print_db == True):
print self.cursor.fetchall()
def get_value( self, column ):
self.cursor.execute( "SELECT (?) FROM database", column )
for n in self.cursor:
print n
def destructor(self):
self.cursor.close()
if __name__ == "__main__":
f = db()
f.add_entry( "Pinkk Floyd", "fdgf" )
f.add_entry( "Pink", "fdgf" )
# f.get_mediadb(print_db=True)
f.get_value(('filepath',))
f.destructor()
When i run it the get_value() returns 'filepath' instead of the
columns. But if i dont use any variable and make the expression static
all goes on as its supposed to. What am i doing wrong?
PS: Dont mind the bad code
More information about the Python-list
mailing list