2
# This file is part of GNU Enterprise.
4
# GNU Enterprise is free software; you can redistribute it
5
# and/or modify it under the terms of the GNU General Public
6
# License as published by the Free Software Foundation; either
7
# version 2, or (at your option) any later version.
9
# GNU Enterprise is distributed in the hope that it will be
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public
15
# License along with program; see the file COPYING. If not,
16
# write to the Free Software Foundation, Inc., 59 Temple Place
17
# - Suite 330, Boston, MA 02111-1307, USA.
19
# Copyright 2000-2005 Free Software Foundation
25
# Generic implementation of dbdriver using Python DB-SIG v2
29
# The classes below are meant to be extended
34
__all__ = ['ResultSet']
36
from gnue.common.datasources import GConditions, Exceptions
37
from gnue.common.datasources.drivers.Base import ResultSet as BaseResultSet
38
from gnue.common.apps import errors
42
from RecordSet import RecordSet
44
class ResultSet(BaseResultSet):
45
_recordSetClass = RecordSet
46
def __init__(self, *args, **parms):
48
self._fieldOrder = parms['fieldOrder']
49
del parms['fieldOrder']
52
BaseResultSet.__init__(self, *args, **parms)
57
for t in self._cursor.description:
60
if not isinstance (t[0], types.UnicodeType):
61
name = unicode (name, self._dataObject._connection._encoding)
63
gDebug (8, "Field from Cursordescription: %s new %s" % (t[0], name))
65
self._fieldNames.append (name)
66
self._dataObject._fieldReferences [name] = ""
68
gDebug (8, "DBSIG2::Fields from cursor set to %s" % self._fieldNames)
70
self._recordCount = self._cursor.rowcount or 0
72
gDebug (8, 'ResultSet created')
74
def _loadNextRecord(self):
78
if self._dataObject._connection._broken_fetchmany:
80
rsets = self._cursor.fetchmany()
85
# Pass arraysize because of mysql fetchmany bug in MySQLdb < 0.9.2
86
rsets = self._cursor.fetchmany (self._cursor.arraysize)
87
except self._dataObject._connection._DatabaseError, err:
88
raise Exceptions.ConnectionError, errors.getException()[2]
90
if rsets and len(rsets):
96
if self._dataObject._unicodeMode and type(f)==types.StringType:
97
f = unicode(f,self._dataObject._connection._encoding)
100
name = self._fieldOrder[i]
104
name = string.lower(self._fieldNames[i])
107
self._cachedRecords.append (self._recordSetClass(parent=self,
113
# We no longer need the cursor if we are read only