16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2000-2002 Free Software Foundation |
# Copyright 2000-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# mysql/DBdriver.py |
# mysql/DBdriver.py |
59 |
DBSIG_ResultSet.__init__(self, dataObject, \ |
DBSIG_ResultSet.__init__(self, dataObject, \ |
60 |
cursor, defaultValues, masterRecordSet) |
cursor, defaultValues, masterRecordSet) |
61 |
self._recordSetClass = MySQL_RecordSet |
self._recordSetClass = MySQL_RecordSet |
62 |
|
|
63 |
|
# Compensate for bug in python mysql drivers older than 0.9.2a2 |
64 |
|
if MySQLdb.__version__ >= '0.9.2a2': |
65 |
|
self.fetchBugFix = self._cursor.fetchmany |
66 |
|
else: |
67 |
|
self.__done = 0 |
68 |
|
self.fetchBugFix = self.__mySqlNeedsLotsOfTLC |
69 |
|
|
70 |
|
|
71 |
|
# Compensate for MySQ bug |
72 |
|
def __mySqlNeedsLotsOfTLC(self): |
73 |
|
if self.__done: |
74 |
|
return None |
75 |
|
|
76 |
|
self.__done = 1 |
77 |
|
return self._cursor.fetchall() |
78 |
|
|
79 |
|
|
80 |
def _loadNextRecord(self): |
def _loadNextRecord(self): |
81 |
if self._cursor: |
if self._cursor: |
82 |
rs = None |
rs = None |
83 |
|
|
84 |
try: |
try: |
85 |
# |
# See __init__ for details |
86 |
# rsets = self._cursor.fetchall() |
rsets = self.fetchBugFix() |
87 |
rsets = self._cursor.fetchmany() |
|
88 |
except self._dataObject._DatabaseError, err: |
except self._dataObject._DatabaseError, err: |
89 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError, err |
90 |
|
|
107 |
return 0 |
return 0 |
108 |
|
|
109 |
class MySQL_DataObject(DBSIG_DataObject): |
class MySQL_DataObject(DBSIG_DataObject): |
110 |
def __init__(self): |
def __init__(self): |
111 |
DBSIG_DataObject.__init__(self) |
DBSIG_DataObject.__init__(self) |
112 |
self._DatabaseError = MySQLdb.DatabaseError |
self._DatabaseError = MySQLdb.DatabaseError |
113 |
self._resultSetClass = MySQL_ResultSet |
self._resultSetClass = MySQL_ResultSet |
114 |
|
def connect(self, connectData={}): |
|
|
|
|
def connect(self, connectData={}): |
|
115 |
GDebug.printMesg(1,"Mysql database driver initializing") |
GDebug.printMesg(1,"Mysql database driver initializing") |
116 |
|
|
117 |
try: |
try: |
118 |
self._dataConnection = MySQLdb.connect(user=connectData['_username'], |
self._dataConnection = MySQLdb.connect(user=connectData['_username'], |
119 |
passwd=connectData['_password'], |
passwd=connectData['_password'], |