SQL problem in python

petr.jakes.tpc at gmail.com petr.jakes.tpc at gmail.com
Sat Mar 8 14:39:34 EST 2008


Maybe you should try SQLObject :-)

from sqlobject import *
from sqlobject.sqlbuilder import Select
#from sqlobject.sqlbuilder import *
from datetime import datetime
# =========== sqlite ==============================
#connection = connectionForURI('sqlite:///dev/shm/ourdata.db')
connection = connectionForURI('sqlite:/:memory:')
sqlhub.processConnection = connection

class MyTable(SQLObject):
    album    = StringCol(length=20, default=None)
    filepath = StringCol(length=50, default=None)

#MyTable.dropTable(ifExists=True)
#MyTable._connection.debug = True # you can switch debuging ON, so you
can see SQL commands generated by SQLObject
MyTable.createTable(ifNotExists=True)

MyTable(album ="Pinkk Floyd", filepath= "qwst" )
MyTable(album ="Pinkk", filepath= "gbfbd" )
MyTable(album ="Floyd", filepath= "fdgf" )

q = MyTable.select()
for row in q:
    print row.album,  row.filepath
for row in MyTable.select(MyTable.q.album == "Pinkk Floyd"):
    print row.album,  row.filepath

HTH

Petr Jakes



More information about the Python-list mailing list