Question about ODBC

Ian Holmes ianholmes01 at lycos.com
Wed Aug 28 11:51:40 CEST 2002


k.weinert at gmx.net (Karsten Weinert) wrote in message news:<fa576652.0208271822.1b4f0155 at posting.google.com>...
> Hi,
> I can not understand the following behavior of the Access ODBC driver 
> and/or Python. The problem is: I open a ODBC connection, do some
> SQL-statements, for example create a new table an put some data in it.
> Then I close the connection. When I open the connection again, the new
> table has disappeared!

Although transacions are autocommited by default (I think) - couldn't
really make sence of the docs - your script is not autocommitting i.e.
the changes you make are not been writtern to the database.

after the for loop add this line

conn.commit()
e.g.
  for i in range(10):
    sqlmsg="INSERT INTO test13 VALUES (%d,%d)" % (i, i*i)
    print(sqlmsg)
    curs.execute(sqlmsg)
  conn.commit()

its partner conn.rollback() can be used if an error occours

Links - mxODBC docs at
http://www.lemburg.com/files/python/mxODBC.html#Transactions



More information about the Python-list mailing list