34 |
from string import lower, join, split |
from string import lower, join, split |
35 |
import sys |
import sys |
36 |
from gnue.common.apps import GDebug, GConfig |
from gnue.common.apps import GDebug, GConfig |
37 |
|
from gnue.common.datasources import Exceptions |
38 |
from gnue.common.datasources.drivers import DBSIG2 |
from gnue.common.datasources.drivers import DBSIG2 |
39 |
from DataObject import * |
from DataObject import * |
40 |
from gnue.common.datasources.drivers.postgresql.Schema.Discovery.Introspection import Introspection |
from gnue.common.datasources.drivers.postgresql.Schema.Discovery.Introspection import Introspection |
46 |
# |
# |
47 |
class Connection(DBSIG2.Connection): |
class Connection(DBSIG2.Connection): |
48 |
|
|
49 |
_defaultBehavior = Introspection |
defaultBehavior = Introspection |
50 |
_supportedDataObjects = { |
supportedDataObjects = { |
51 |
'object': DataObject_Object, |
'object': DataObject_Object, |
52 |
'sql': DataObject_SQL |
'sql': DataObject_SQL |
53 |
} |
} |
55 |
_pg_connectString = 'host=%s dbname=%s user=%s password=%s port=%s' |
_pg_connectString = 'host=%s dbname=%s user=%s password=%s port=%s' |
56 |
_pg_driver = None |
_pg_driver = None |
57 |
|
|
|
_pg_encTable={'ascii' : 'SQL_ASCII', # ASCII |
|
|
'' : 'EUC_JP', # Japanese EUC |
|
|
'' : 'EUC_CN', # Chinese EUC |
|
|
'' : 'EUC_KR', # Korean EUC |
|
|
'' : 'JOHAB', # Korean EUC (Hangle base) |
|
|
'' : 'EUC_TW', # Taiwan EUC |
|
|
'utf-8' : 'UNICODE', # Unicode (UTF-8) |
|
|
'' : 'MULE_INTERNAL', # Mule internal code |
|
|
'iso8859-1' : 'LATIN1', # ISO 8859-1 ECMA-94 Latin Alphabet No.1 |
|
|
'iso8859-2' : 'LATIN2', # ISO 8859-2 ECMA-94 Latin Alphabet No.2 |
|
|
'iso8859-3' : 'LATIN3', # ISO 8859-3 ECMA-94 Latin Alphabet No.3 |
|
|
'iso8859-4' : 'LATIN4', # ISO 8859-4 ECMA-94 Latin Alphabet No.4 |
|
|
'iso8859-9' : 'LATIN5', # ISO 8859-9 ECMA-128 Latin Alphabet No.5 |
|
|
'iso8859-10': 'LATIN6', # ISO 8859-10 ECMA-144 Latin Alphabet No.6 |
|
|
'iso8859-13': 'LATIN7', # ISO 8859-13 Latin Alphabet No.7 |
|
|
'iso8859-14': 'LATIN8', # ISO 8859-14 Latin Alphabet No.8 |
|
|
'iso8859-15': 'LATIN9', # ISO 8859-15 Latin Alphabet No.9 |
|
|
'iso8859-16': 'LATIN10', # ISO 8859-16 ASRO SR 14111 Latin Alphabet No.10 |
|
|
'iso8859-5' : 'ISO-8859-5', # ECMA-113 Latin/Cyrillic |
|
|
'iso8859-6' : 'ISO-8859-6', # ECMA-114 Latin/Arabic |
|
|
'iso8859-7' : 'ISO-8859-7', # ECMA-118 Latin/Greek |
|
|
'iso8859-8' : 'ISO-8859-8', # ECMA-121 Latin/Hebrew |
|
|
'' : 'KOI8', # KOI8-R(U) |
|
|
'' : 'WIN', # Windows CP1251 |
|
|
'' : 'ALT', # Windows CP866 |
|
|
'' : 'WIN1256', # Arabic Windows CP1256 |
|
|
'' : 'TCVN', # Vietnamese TCVN-5712 (Windows CP1258) |
|
|
'' : 'WIN874'} # Thai Windows CP874 |
|
58 |
|
|
59 |
def connect(self , connectData={}): |
def connect(self, connectData): |
60 |
|
|
61 |
print "Postgresql database driver initializing" |
print "Postgresql database driver initializing" |
62 |
|
|
63 |
if not hasattr(self,'_DatabaseError'): |
if not hasattr(self,'_DatabaseError'): |
64 |
self._DatabaseError = self._pg_driver.DatabaseError |
self._DatabaseError = self._pg_driver.DatabaseError |
65 |
|
|
84 |
connectData['_password'], |
connectData['_password'], |
85 |
port))) |
port))) |
86 |
GDebug.printMesg(1,"Exception %s " % value) |
GDebug.printMesg(1,"Exception %s " % value) |
87 |
raise GDataObjects.LoginError, value |
raise Exceptions.LoginError, _("The PostgreSQL driver returned the following error:\n\t%s") % value |
88 |
|
|
89 |
try: |
try: |
90 |
try: |
try: |
91 |
self._encoding = connectData['encoding'] |
self._pg_encoding = pg_encTable[self._encoding] |
|
except KeyError: |
|
|
pass |
|
|
|
|
|
try: |
|
|
self._pg_encoding = self._pg_encTable[self._encoding] |
|
92 |
except KeyError: |
except KeyError: |
93 |
GDebug.printMesg(1,_("Encoding '%s' is not supported by postgresql dbdriver.") % \ |
GDebug.printMesg(1,_("Encoding '%s' is not supported by postgresql dbdriver.") % \ |
94 |
self._encoding + _('Using default encoding.')) |
self._encoding + _('Using default encoding.')) |
95 |
self._pg_encoding = '' |
self._pg_encoding = '' |
96 |
|
|
97 |
if self._pg_encoding not in ("",'DEFAULT'): |
if self._pg_encoding not in ("",'DEFAULT'): |
98 |
GDebug.printMesg(1,'Setting postgresql client_encoding to %s (%s)' % (self._pg_encoding, |
GDebug.printMesg(1,'Setting postgresql client_encoding to %s (%s)' % (self._pg_encoding, |
99 |
self._encoding)) |
self._encoding)) |
154 |
return rv[0] |
return rv[0] |
155 |
except: |
except: |
156 |
return None |
return None |
157 |
|
|
158 |
|
pg_encTable = {'ascii' : 'SQL_ASCII', # ASCII |
159 |
|
'' : 'EUC_JP', # Japanese EUC |
160 |
|
'' : 'EUC_CN', # Chinese EUC |
161 |
|
'' : 'EUC_KR', # Korean EUC |
162 |
|
'' : 'JOHAB', # Korean EUC (Hangle base) |
163 |
|
'' : 'EUC_TW', # Taiwan EUC |
164 |
|
'utf-8' : 'UNICODE', # Unicode (UTF-8) |
165 |
|
'' : 'MULE_INTERNAL', # Mule internal code |
166 |
|
'iso8859-1' : 'LATIN1', # ISO 8859-1 ECMA-94 Latin Alphabet No.1 |
167 |
|
'iso8859-2' : 'LATIN2', # ISO 8859-2 ECMA-94 Latin Alphabet No.2 |
168 |
|
'iso8859-3' : 'LATIN3', # ISO 8859-3 ECMA-94 Latin Alphabet No.3 |
169 |
|
'iso8859-4' : 'LATIN4', # ISO 8859-4 ECMA-94 Latin Alphabet No.4 |
170 |
|
'iso8859-9' : 'LATIN5', # ISO 8859-9 ECMA-128 Latin Alphabet No.5 |
171 |
|
'iso8859-10': 'LATIN6', # ISO 8859-10 ECMA-144 Latin Alphabet No.6 |
172 |
|
'iso8859-13': 'LATIN7', # ISO 8859-13 Latin Alphabet No.7 |
173 |
|
'iso8859-14': 'LATIN8', # ISO 8859-14 Latin Alphabet No.8 |
174 |
|
'iso8859-15': 'LATIN9', # ISO 8859-15 Latin Alphabet No.9 |
175 |
|
'iso8859-16': 'LATIN10', # ISO 8859-16 ASRO SR 14111 Latin Alphabet No.10 |
176 |
|
'iso8859-5' : 'ISO-8859-5', # ECMA-113 Latin/Cyrillic |
177 |
|
'iso8859-6' : 'ISO-8859-6', # ECMA-114 Latin/Arabic |
178 |
|
'iso8859-7' : 'ISO-8859-7', # ECMA-118 Latin/Greek |
179 |
|
'iso8859-8' : 'ISO-8859-8', # ECMA-121 Latin/Hebrew |
180 |
|
'' : 'KOI8', # KOI8-R(U) |
181 |
|
'' : 'WIN', # Windows CP1251 |
182 |
|
'' : 'ALT', # Windows CP866 |
183 |
|
'' : 'WIN1256', # Arabic Windows CP1256 |
184 |
|
'' : 'TCVN', # Vietnamese TCVN-5712 (Windows CP1258) |
185 |
|
'' : 'WIN874'} # Thai Windows CP874 |