ODBC Insert question

Bill Witherspoon basementhead at gmail.com
Thu Jan 12 08:30:13 EST 2006


Hi all,

Am trying to teach myself a bit of Python by creating a small app to track
tasks, and docs associated with the task. I'm using Python 2.4 on Win32 with
an Access 2003 db which I'm attempting to talk to using mxODBC. I can do
Selects without difficulty but a simple Insert has me stumped for days. I
suspect that I am doing something silly, but I can't see it. Searching the
list has shown others with similar problems but trying them did not yield
anything. As an aside, why does [Date] have to have [] around it? I get a
syntax error from the driver if I don't put them in?

My code exits without an error, but doesn't insert anything:

    def AddFiles(self, path, files):
        atime = now()
        thedate = str(atime.month) + "/" + str(atime.day) + "/" + str(
atime.year)

        for thefile in files:
            query_string = "Insert into file (ProjectID, [Date], Filename,
Path) Values (?,?,?,?)"
            values = (self.projectid,thedate,thefile,path)
            ExecuteQuery(query_string, values)

def ExecuteQuery (qrystring, values):
        myconn = connect_db()
        mycursor = myconn.cursor()
        mycursor.execute(qrystring, values)
        myconn.close()
        return

def connect_db ():
        myconn = mx.ODBC.Windows.Connect('trackingdb')  #using mx.ODBC
        return myconn

Any help/pointers would be appreciated!

Thanks,
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060112/889e9cae/attachment.html>


More information about the Python-list mailing list