1 |
# |
# |
2 |
# This file is part of GNU Enterprise. |
# This file is part of GNU Enterprise. |
3 |
# |
# |
4 |
# GNU Enterprise is free software; you can redistribute it |
# GNU Enterprise is free software; you can redistribute it |
5 |
# and/or modify it under the terms of the GNU General Public |
# and/or modify it under the terms of the GNU General Public |
6 |
# License as published by the Free Software Foundation; either |
# License as published by the Free Software Foundation; either |
7 |
# version 2, or(at your option) any later version. |
# version 2, or(at your option) any later version. |
8 |
# |
# |
9 |
# GNU Enterprise is distributed in the hope that it will be |
# GNU Enterprise is distributed in the hope that it will be |
10 |
# useful, but WITHOUT ANY WARRANTY; without even the implied |
# useful, but WITHOUT ANY WARRANTY; without even the implied |
11 |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
12 |
# PURPOSE. See the GNU General Public License for more details. |
# PURPOSE. See the GNU General Public License for more details. |
13 |
# |
# |
14 |
# You should have received a copy of the GNU General Public |
# You should have received a copy of the GNU General Public |
15 |
# License along with program; see the file COPYING. If not, |
# License along with program; see the file COPYING. If not, |
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. |
28 |
# NOTES: |
# NOTES: |
29 |
# |
# |
30 |
|
|
31 |
import sys,string,types |
__all__ = ('Connection') |
32 |
|
|
33 |
|
import sys |
34 |
from gnue.common.datasources import GDataObjects, GConditions, GConnections |
from gnue.common.datasources import GDataObjects, GConditions, GConnections |
35 |
from gnue.common.apps import GDebug |
from gnue.common.apps import GDebug |
36 |
from gnue.common.datasources.drivers.postgresql.Base.Driver \ |
from gnue.common.datasources.drivers.postgresql import Base |
|
import PGSQL_RecordSet, PGSQL_ResultSet, PGSQL_DataObject, \ |
|
|
PGSQL_DataObject_SQL, PGSQL_DataObject_Object, \ |
|
|
PGSQL_TriggerExtensions |
|
37 |
|
|
38 |
try: |
try: |
39 |
from pyPgSQL import PgSQL # pyPgSQL 2.0 support |
from pyPgSQL import PgSQL # pyPgSQL 2.0 support |
40 |
except ImportError: |
except ImportError: |
41 |
import PgSQL # pyPgSQL 1.6 support |
import PgSQL # pyPgSQL 1.6 support |
42 |
|
|
43 |
|
|
44 |
class PG_RecordSet(PGSQL_RecordSet): |
|
45 |
pass |
class ResultSet(Base.ResultSet): |
46 |
|
|
|
class PG_ResultSet(PGSQL_ResultSet): |
|
|
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None): |
|
|
PGSQL_ResultSet.__init__(self, dataObject, \ |
|
|
cursor, defaultValues, masterRecordSet) |
|
|
self._recordSetClass = PG_RecordSet |
|
|
|
|
47 |
# TODO: Override the base _loadNextRecord as the fetchmany() from the cursor |
# TODO: Override the base _loadNextRecord as the fetchmany() from the cursor |
48 |
# TODO: returns an exception instead of None. Not sure wazzup with that. |
# TODO: returns an exception instead of None. Not sure wazzup with that. |
49 |
def _loadNextRecord(self): |
def _loadNextRecord(self): |
63 |
i = 0 |
i = 0 |
64 |
dict = {} |
dict = {} |
65 |
for f in (rs): |
for f in (rs): |
66 |
if self._dataObject._unicodeMode and type(f)==types.StringType: |
dict[self._fieldNames[i]] = f |
|
f=unicode(f,self._dataObject._databaseEncoding) |
|
|
dict[string.lower(self._fieldNames[i])] = f |
|
67 |
i += 1 |
i += 1 |
68 |
self._cachedRecords.append (self._recordSetClass(parent=self, \ |
self._cachedRecords.append (self._recordSetClass(parent=self, \ |
69 |
initialData=dict)) |
initialData=dict)) |
75 |
else: |
else: |
76 |
return 0 |
return 0 |
77 |
|
|
|
class PG_DataObject(PGSQL_DataObject): |
|
|
def __init__(self): |
|
|
PGSQL_DataObject.__init__(self, PgSQL, PG_ResultSet) |
|
|
self._connectString = '%s::%s:%s:%s::%s' |
|
78 |
|
|
|
class PG_DataObject_Object(PG_DataObject, \ |
|
|
PGSQL_DataObject_Object): |
|
79 |
|
|
80 |
def __init__(self): |
class DataObject_Object(Base.DataObject_Object): |
81 |
# Call PGSQL init first because PG_DataObject needs to overwrite |
_resultSetClass = ResultSet |
|
# some of its values |
|
|
PG_DataObject.__init__(self) |
|
82 |
|
|
|
def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""): |
|
|
return PGSQL_DataObject_Object._buildQuery(self, conditions,forDetail, |
|
|
additionalSQL) |
|
83 |
|
|
84 |
|
class DataObject_SQL(Base.DataObject_SQL): |
85 |
|
_resultSetClass = ResultSet |
86 |
|
|
|
class PG_DataObject_SQL(PG_DataObject, \ |
|
|
PGSQL_DataObject_SQL): |
|
|
def __init__(self): |
|
|
# Call PGSQL init first because PG_DataObject needs to overwrite |
|
|
# some of its values |
|
|
PG_DataObject.__init__(self) |
|
87 |
|
|
88 |
def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""): |
class Connection(Base.Connection): |
89 |
return PGSQL_DataObject_SQL._buildQuery(self, conditions,forDetail,\ |
_pg_driver = PgSQL |
90 |
additionalSQL) |
_pg_connectString = '%s::%s:%s:%s::%s' |
91 |
|
|
92 |
|
_supportedDataObjects = { |
93 |
|
'object': DataObject_Object, |
94 |
|
'sql': DataObject_SQL |
95 |
|
} |
96 |
|
|
|
# |
|
|
# Extensions to Trigger Namespaces |
|
|
# |
|
|
class TriggerExtensions(PGSQL_TriggerExtensions): |
|
|
pass |
|
97 |
|
|
|
###################################### |
|
|
# |
|
|
# The following hashes describe |
|
|
# this driver's characteristings. |
|
|
# |
|
|
###################################### |
|
|
|
|
|
# |
|
|
# All datasouce "types" and corresponding DataObject class |
|
|
# |
|
|
supportedDataObjects = { |
|
|
'object': PG_DataObject_Object, |
|
|
'sql': PG_DataObject_SQL |
|
|
} |
|