#57 autoCommit missing from mysql

closed-fixed
MySQL (29)
5
2005-03-03
2005-02-23
Anonymous
No

In both sqlobject 0.6.1 and the latest SVN (rev 638)
mysqlconnection.py does not use the autoCommit property
set in dbconnection.py.

The simple fix is to replace the original
makeConnection method in mysqlconnection.py:
def makeConnection(self):
return MySQLdb.connect(host=self.host, db=self.db,
user=self.user, passwd=self.password)

With a new makeConnection method borrowed almost
directly from pgconnection.py:
def makeConnection(self):
try:
conn = self.module.connect(host=self.host,
db=self.db,
user=self.user, passwd=self.password)
except self.module.OperationalError, e:
raise self.module.OperationalError("%s; used
connection string: host=%s, db=%s, user=%s, pwd=%s" %
(e, self.host, self.db, self.user,
self.password))
if hasattr(conn, 'autocommit'):
conn.autocommit(self.autoCommit)
return conn

Tested to work with python 2.4, MySQL 4.1.9, and
MySQL-python-1.2.0.

-Justin (shackletj at yahoo nospam dot com)

Discussion

  • Justin Shacklette

    Logged In: YES
    user_id=617915

    After some more work, here is a patch for mysqlconnection.py:

    --- SQLObject-SVN/sqlobject/mysql/mysqlconnection.py
    (revision 660)
    +++ SQLObject/sqlobject/mysql/mysqlconnection.py (working copy)
    @@ -26,9 +26,20 @@
    host=host or 'localhost', port=port or
    0, **args)
    connectionFromURI = classmethod(connectionFromURI)

    + def _setAutoCommit(self, conn, auto):
    + conn.autocommit(auto)
    +
    def makeConnection(self):
    - return MySQLdb.connect(host=self.host,
    port=self.port, db=self.db,
    - user=self.user,
    passwd=self.password)
    + try:
    + conn = self.module.connect(host=self.host,
    + db=self.db, user=self.user,
    passwd=self.password)
    + except self.module.OperationalError, e:
    + raise self.module.OperationalError(
    + "%s; used connection string: host=%s,
    db=%s, user=%s, pwd=%s" %
    + (e, self.host, self.db, self.user,
    self.password))
    + if hasattr(conn, 'autocommit'):
    + self._setAutoCommit(conn,self.autoCommit)
    + return conn

    def _executeRetry(self, conn, cursor, query):
    while 1:

     
  • Oleg Broytman

    Oleg Broytman - 2005-03-03
    • assigned_to: nobody --> phd
    • status: open --> closed-fixed
     
  • Oleg Broytman

    Oleg Broytman - 2005-03-03

    Logged In: YES
    user_id=4799

    Commited at revision 662.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks