Author: phd
Date: 2007-05-10 06:35:26 -0600 (Thu, 10 May 2007)
New Revision: 2663
Modified:
SQLObject/branches/0.8/docs/News.txt
SQLObject/branches/0.8/sqlobject/mysql/mysqlconnection.py
Log:
Fixed a bug in MySQL connection in case there is no charset in the DB URI.
Modified: SQLObject/branches/0.8/docs/News.txt
===================================================================
--- SQLObject/branches/0.8/docs/News.txt 2007-05-10 12:34:41 UTC (rev 2662)
+++ SQLObject/branches/0.8/docs/News.txt 2007-05-10 12:35:26 UTC (rev 2663)
@@ -154,6 +154,14 @@
* Fixed aggregators and accumulators with inheritance.
+SQLObject 0.7.7
+===============
+
+Bug Fixes
+---------
+
+* Fixed a bug in MySQL connection in case there is no charset in the DB URI.
+
SQLObject 0.7.6
===============
Modified: SQLObject/branches/0.8/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/mysql/mysqlconnection.py 2007-05-10 12:34:41 UTC (rev 2662)
+++ SQLObject/branches/0.8/sqlobject/mysql/mysqlconnection.py 2007-05-10 12:35:26 UTC (rev 2663)
@@ -57,13 +57,14 @@
connectionFromURI = classmethod(connectionFromURI)
def makeConnection(self):
- from MySQLdb.connections import Connection
- if not hasattr(Connection, 'set_character_set'):
- # monkeypatch pre MySQLdb 1.2.1
- encoding = self.dbEncoding
- def character_set_name(self):
- return encoding + '_' + encoding
- Connection.character_set_name = character_set_name
+ dbEncoding = self.dbEncoding
+ if dbEncoding:
+ from MySQLdb.connections import Connection
+ if not hasattr(Connection, 'set_character_set'):
+ # monkeypatch pre MySQLdb 1.2.1
+ def character_set_name(self):
+ return dbEncoding + '_' + dbEncoding
+ Connection.character_set_name = character_set_name
try:
conn = self.module.connect(host=self.host, port=self.port,
db=self.db, user=self.user, passwd=self.password, **self.kw)
@@ -78,11 +79,12 @@
if hasattr(conn, 'autocommit'):
conn.autocommit(bool(self.autoCommit))
- if hasattr(conn, 'set_character_set'): # MySQLdb 1.2.1 and later
- conn.set_character_set(self.dbEncoding)
- else: # pre MySQLdb 1.2.1
- # works along with monkeypatching code above
- conn.query("SET NAMES %s" % self.dbEncoding)
+ if self.dbEncoding:
+ if hasattr(conn, 'set_character_set'): # MySQLdb 1.2.1 and later
+ conn.set_character_set(self.dbEncoding)
+ else: # pre MySQLdb 1.2.1
+ # works along with monkeypatching code above
+ conn.query("SET NAMES %s" % self.dbEncoding)
return conn
|