dabo Commit
Revision 4844
Date: 2008-12-16 15:19:20 -0800 (Tue, 16 Dec 2008)
Author: Cito
Trac: http://trac.dabodev.com/dabo/changeset/4844
Changed:
U trunk/dabo/biz/RemoteBizobj.py
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/dApp.py
U trunk/dabo/dException.py
U trunk/dabo/db/dBackend.py
U trunk/dabo/db/dCursorMixin.py
U trunk/dabo/db/dDataSet.py
U trunk/dabo/db/dbMsSQL.py
U trunk/dabo/db/dbMySQL.py
U trunk/dabo/db/dbPostgreSQL.py
U trunk/dabo/db/dbSQLite.py
U trunk/dabo/lib/RemoteConnector.py
U trunk/dabo/ui/uiwx/dFormMixin.py
Log:
Implemented #1192 and solved another problem: The fix in #1187 assumed utf-8
error messages. We now use the proper database client encoding to decode the
error message from the database. Also, converted all string exceptions to
proper exception instances.
Diff:
Modified: trunk/dabo/biz/RemoteBizobj.py
===================================================================
--- trunk/dabo/biz/RemoteBizobj.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/biz/RemoteBizobj.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -142,7 +142,8 @@
self.moveToPK(pk)
except dException.RowNotFoundException:
ds = self.DataSource
- raise
dException.WebServerException, _("PK '%(pk)s' not present in dataset for
DataSource '%(ds)s'") % locals()
+ raise
dException.WebServerException(
+ _("PK '%(pk)s'
not present in dataset for DataSource '%(ds)s'") % locals())
for col, vals in rec.items():
if col in (kf,
kons.CURSOR_TMPKEY_FIELD):
continue
@@ -151,7 +152,8 @@
# Check for update conflicts;
abort if found
currval = self.getFieldVal(col)
if currval != oldval:
- raise
dException.WebServerException, _("Update Conflict: the value in column '%s' has
been changed by someone else.") % col
+ raise
dException.WebServerException(
+
_("Update Conflict: the value in column '%s' has been changed by someone
else.") % col)
self.setFieldVal(col, newval)
kids = diff.pop("children", None)
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/biz/dBizobj.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -151,7 +151,7 @@
self._virtualFields = {}
errMsg = self.beforeCreateCursor()
if errMsg:
- raise dException.dException, errMsg
+ raise dException.dException(errMsg)
if not self.dbapiCursorClass:
return
@@ -201,7 +201,7 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
self._CurrentCursor.first()
self.requeryAllChildren()
@@ -220,7 +220,7 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
self._CurrentCursor.prior()
self.requeryAllChildren()
@@ -239,7 +239,7 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
self._CurrentCursor.next()
self.requeryAllChildren()
@@ -258,7 +258,7 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
self._CurrentCursor.last()
self.requeryAllChildren()
@@ -358,19 +358,19 @@
except dException.ConnectionLostException, e:
self.RowNumber = current_row
- raise dException.ConnectionLostException, e
+ raise e
except dException.DBQueryException, e:
# Something failed; reset things.
if startTransaction:
self.rollbackTransaction()
# Pass the exception to the UI
self.RowNumber = current_row
- raise dException.DBQueryException, e
+ raise e
except dException.dException, e:
if startTransaction:
self.rollbackTransaction()
self.RowNumber = current_row
- raise
+ raise e
if current_row >= 0:
try:
@@ -392,10 +392,11 @@
cursor = self._CurrentCursor
errMsg = self.beforeSave()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
if self.KeyField is None:
- raise dException.MissingPKException, _("No key field
defined for table: ") + self.DataSource
+ raise dException.MissingPKException(
+ _("No key field defined for table: ") +
self.DataSource)
# Validate any changes to the data. If there is data that fails
# validation, an Exception will be raised.
@@ -435,14 +436,14 @@
if startTransaction:
self.rollbackTransaction()
# Pass the exception to the UI
- raise dException.DBQueryException, e
+ raise e
except dException.dException, e:
# Something failed; reset things.
if startTransaction:
self.rollbackTransaction()
# Pass the exception to the UI
- raise
+ raise e
# Two hook methods: one specific to Save(), and one which is
called after any change
# to the data (either save() or delete()).
@@ -467,7 +468,7 @@
"""
errMsg = self.beforeCancel()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
if ignoreNoRecords is None:
# Canceling changes when there are no records should
# normally not be a problem.
@@ -486,7 +487,7 @@
cursor = self._CurrentCursor
errMsg = self.beforeDeleteAllChildren()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
startTransaction = startTransaction and self.beginTransaction()
try:
@@ -498,11 +499,11 @@
except dException.DBQueryException, e:
if startTransaction:
self.rollbackTransaction()
- raise dException.DBQueryException, e
+ raise e
except StandardError, e:
if startTransaction:
self.rollbackTransaction()
- raise StandardError, e
+ raise e
self.afterDeleteAllChildren()
@@ -516,16 +517,18 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
if self.KeyField is None:
- raise dException.dException, _("No key field defined
for table: ") + self.DataSource
+ raise dException.dException(
+ _("No key field defined for table: ") +
self.DataSource)
if self.deleteChildLogic == kons.REFINTEG_RESTRICT:
# See if there are any child records
for child in self.__children:
if child.RowCount > 0:
- raise dException.dException,
_("Deletion prohibited - there are related child records.")
+ raise dException.dException(
+ _("Deletion prohibited
- there are related child records."))
startTransaction = startTransaction and self.beginTransaction()
try:
@@ -552,11 +555,11 @@
except dException.DBQueryException, e:
if startTransaction:
self.rollbackTransaction()
- raise dException.DBQueryException, e
+ raise e
except StandardError, e:
if startTransaction:
self.rollbackTransaction()
- raise StandardError, e
+ raise e
def deleteAll(self, startTransaction=True):
@@ -579,11 +582,11 @@
except dException.DBQueryException, e:
if startTransaction:
self.rollbackTransaction()
- raise dException.DBQueryException, e
+ raise e
except StandardError, e:
if startTransaction:
self.rollbackTransaction()
- raise StandardError, e
+ raise e
def execute(self, sql, params=None):
@@ -798,7 +801,7 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
self._CurrentCursor.new()
self._onNew()
@@ -842,7 +845,7 @@
return rp.requery()
errMsg = self.beforeRequery()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
if self.KeyField is None:
errMsg = _("No Primary Key defined in the Bizobj for
%s") % self.DataSource
raise dException.MissingPKException, errMsg
@@ -865,20 +868,18 @@
try:
cursor.requery(params)
- except dException.ConnectionLostException, e:
- raise dException.ConnectionLostException, e
+ except dException.ConnectionLostException:
+ raise
- except dException.DBQueryException, e:
- # Pass the exception to the UI
- raise dException.DBQueryException, e
+ except dException.DBQueryException:
+ raise
except dException.NoRecordsException:
# Pass the exception to the UI
uiException = dException.NoRecordsException
- except dException.dException, e:
- # Pass the exception to the UI
- raise dException.dException, e
+ except dException.dException:
+ raise
if self.RestorePositionOnRequery:
self._positionUsingPK(currPK)
@@ -974,7 +975,7 @@
if message:
errMsg += message
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
def validateRecord(self):
@@ -1012,7 +1013,7 @@
if message:
errMsg += message
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
else:
raise dException.BusinessRulePassed
@@ -1315,7 +1316,7 @@
errMsg = self.beforeChildRequery()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
for child in self.__children:
# Let the child know the current dependent PK
@@ -1329,7 +1330,8 @@
def getPK(self):
""" Return the value of the PK field."""
if self.KeyField is None:
- raise dException.dException, _("No key field defined
for table: ") + self.DataSource
+ raise dException.dException(
+ _("No key field defined for table: ") +
self.DataSource)
cc = self._CurrentCursor
return cc.getFieldVal(self.KeyField)
@@ -2098,7 +2100,7 @@
if not errMsg:
errMsg = self.beforePointerMove()
if errMsg:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
self._moveToRowNum(rownum)
self.requeryAllChildren()
self.afterPointerMove()
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/dApp.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -961,7 +961,8 @@
try:
ret = self.dbConnections[connName]
except KeyError:
- raise dException.ConnectionNotFoundException, _("No
connection named '%s' is defined") % connName
+ raise dException.ConnectionNotFoundException(
+ _("No connection named '%s' is
defined") % connName)
return ret
Modified: trunk/dabo/dException.py
===================================================================
--- trunk/dabo/dException.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/dException.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -72,7 +72,7 @@
class DBQueryException(DatabaseException):
def __init__(self, err, sql=None):
- self.err_desc = unicode(str(err), 'utf-8').rstrip()
+ self.err_desc = err.rstrip()
self.sql = sql and sql.strip() or None
def __str__(self):
Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dBackend.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -108,14 +108,14 @@
""" Most backends will return a non-zero number if there are
updates.
Some do not, so this will have to be customized in those cases.
"""
- raise dException.dException, _("No records updated")
+ raise dException.dException(_("No records updated"))
def noResultsOnDelete(self):
""" Most backends will return a non-zero number if there are
deletions.
Some do not, so this will have to be customized in those cases.
"""
- raise dException.dException, _("No records deleted")
+ raise dException.dException(_("No records deleted"))
def flush(self, cursor):
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dCursorMixin.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -315,15 +315,20 @@
raise errorClass, e
paramStr = ["%s" % p for p in params]
dabo.dbActivityLog.write("FAILED SQL: %s, PARAMS: %s" %
(sql.replace("\n", " "), ", ".join(paramStr)))
+ # Database errors need to be decoded from database
encoding.
+ try:
+ errMsg = str(e).decode(self.Encoding)
+ except UnicodeError:
+ errMsg = unicode(e)
# If this is due to a broken connection, let the user
know.
# Different backends have different messages, but they
# should all contain the string 'connect' in them.
- if "connect" in str(e).lower():
- raise dException.ConnectionLostException, e
- if "access" in str(e).lower():
- raise dException.DBNoAccessException(e)
+ if "connect" in errMsg.lower():
+ raise dException.ConnectionLostException(errMsg)
+ elif "access" in errMsg.lower():
+ raise dException.DBNoAccessException(errMsg)
else:
- raise dException.DBQueryException(e, sql)
+ raise dException.DBQueryException(errMsg, sql)
# Some backend programs do odd things to the description
# This allows each backend to handle these quirks individually.
@@ -483,7 +488,8 @@
# Make sure that the specified column is a column in the result
set
if not [True for t in self.DataStructure if t[0] == col] and
col not in self.VirtualFields:
- raise dException.dException, _("Invalid column
specified for sort: ") + col
+ raise dException.dException(
+ _("Invalid column specified for sort:
") + col)
newCol = col
if col == currCol:
@@ -501,7 +507,8 @@
if ord.upper() in ("ASC", "DESC", ""):
newOrd = ord.upper()
else:
- raise dException.dException, _("Invalid
Sort direction specified: ") + ord
+ raise dException.dException(
+ _("Invalid Sort
direction specified: ") + ord)
else:
# Different column specified.
@@ -512,7 +519,8 @@
if ord.upper() in ("ASC", "DESC", ""):
newOrd = ord.upper()
else:
- raise dException.dException, _("Invalid
Sort direction specified: ") + ord
+ raise dException.dException(
+ _("Invalid Sort
direction specified: ") + ord)
self.__sortRows(newCol, newOrd, caseSensitive)
# Save the current sort values
@@ -786,7 +794,8 @@
"""
ret = None
if self.RowCount <= 0:
- raise dException.NoRecordsException, _("No records in
the data set.")
+ raise dException.NoRecordsException(
+ _("No records in the data set."))
rec = self._records[self.RowNumber]
recKey = self.pkExpression()
if (recKey in self._newRecords) and self.AutoPopulatePK:
@@ -842,8 +851,8 @@
_rowChangeCallback(row)
return vf["func"]()
except KeyError:
- raise
dException.FieldNotFoundException, "%s '%s' %s" % (
- _("Field"), fld,
_("does not exist in the data set"))
+ raise
dException.FieldNotFoundException("%s '%s' %s" % (
+ _("Field"), fld,
_("does not exist in the data set")))
def _fldTypeFromDB(self, fld):
@@ -891,8 +900,8 @@
if fld in self.VirtualFields:
# ignore
return
- ss = _("Field '%s' does not exist in the data set.") %
(fld,)
- raise dException.FieldNotFoundException, ss
+ raise dException.FieldNotFoundException(
+ _("Field '%s' does not exist in the
data set.") % (fld,))
try:
fldType = self._types[fld]
@@ -1143,7 +1152,7 @@
if self.RowCount > 0:
self.RowNumber = 0
else:
- raise dException.NoRecordsException, _("No records in
data set")
+ raise dException.NoRecordsException(_("No records in
data set"))
def prior(self):
@@ -1152,9 +1161,11 @@
if self.RowNumber > 0:
self.RowNumber -= 1
else:
- raise dException.BeginningOfFileException,
_("Already at the beginning of the data set.")
+ raise dException.BeginningOfFileException(
+ _("Already at the beginning of
the data set."))
else:
- raise dException.NoRecordsException, _("No records in
data set")
+ raise dException.NoRecordsException(
+ _("No records in data set"))
def next(self):
@@ -1163,9 +1174,10 @@
if self.RowNumber < (self.RowCount-1):
self.RowNumber += 1
else:
- raise dException.EndOfFileException, _("Already
at the end of the data set.")
+ raise dException.EndOfFileException(
+ _("Already at the end of the
data set."))
else:
- raise dException.NoRecordsException, _("No records in
data set")
+ raise dException.NoRecordsException(_("No records in
data set"))
def last(self):
@@ -1173,14 +1185,14 @@
if self.RowCount > 0:
self.RowNumber = self.RowCount-1
else:
- raise dException.NoRecordsException, _("No records in
data set")
+ raise dException.NoRecordsException(_("No records in
data set"))
def save(self, allRows=False):
""" Save any changes to the data back to the data store."""
# Make sure that there is data to save
if self.RowCount <= 0:
- raise dException.NoRecordsException, _("No data to
save")
+ raise dException.NoRecordsException(_("No data to
save"))
# Make sure that there is a PK
self.checkPK()
@@ -1190,12 +1202,19 @@
except dException.DBQueryException, e:
# Error was encountered. Raise an exception so
that the
# calling bizobj can rollback the transaction
if necessary
- dabo.dbActivityLog.write(_("DBQueryException
encountered in save(): %s") % e)
- raise dException.DBQueryException, e
+ try:
+ errMsg = str(e).decode(self.Encoding)
+ except UnicodeError:
+ errMsg = unicode(e)
+ dabo.dbActivityLog.write(
+ _("DBQueryException encountered
in save(): %s") % errMsg)
+ raise e
except StandardError, e:
- if "connect" in str(e).lower():
- dabo.dbActivityLog.write(_("Connection
Lost exception encountered in saverow(): %s") % e)
- raise
dException.ConnectionLostException, e
+ errMsg = str(e)
+ if "connect" in errMsg.lower():
+ dabo.dbActivityLog.write(
+ _("Connection Lost
exception encountered in saverow(): %s") % errMsg)
+ raise
dException.ConnectionLostException(errMsg)
else:
# Error was encountered. Raise an
exception so that the
# calling bizobj can rollback the
transaction if necessary
@@ -1426,7 +1445,7 @@
# Nothing to do!
return
else:
- raise dException.NoRecordsException, _("No data
to cancel.")
+ raise dException.NoRecordsException(_("No data
to cancel."))
# Faster to deal with 2 specific cases: all rows or just
current row
if allRows:
@@ -1481,7 +1500,7 @@
"""Delete the specified row, or the currently active row."""
if self.RowNumber < 0 or self.RowCount == 0:
# No query has been run yet
- raise dException.NoRecordsException, _("No record to
delete")
+ raise dException.NoRecordsException(_("No record to
delete"))
if delRowNum is None:
# assume that it is the current row that is to be
deleted
delRowNum = self.RowNumber
@@ -1556,7 +1575,8 @@
val = fnc(*prms)
self.setFieldVal(field, val)
else:
- raise dException.FieldNotFoundException,
_("Can't set default value for nonexistent field '%s'.") % field
+ raise dException.FieldNotFoundException(
+ _("Can't set default value for
nonexistent field '%s'.") % field)
if self._nullDefaults:
for field in rec.keys():
@@ -1661,7 +1681,7 @@
and an exception is raised.
"""
if (rownum >= self.RowCount) or (rownum < 0):
- raise dException.dException, _("Invalid row specified.")
+ raise dException.dException(_("Invalid row specified."))
self.RowNumber = rownum
@@ -1683,9 +1703,9 @@
return ret
# Make sure that this is a valid field
if not fld:
- raise dException.FieldNotFoundException, _("No field
specified for seek()")
+ raise dException.FieldNotFoundException(_("No field
specified for seek()"))
if (fld not in self._records[0]) and (fld not in
self.VirtualFields):
- raise dException.FieldNotFoundException,
_("Non-existent field '%s'") % fld
+ raise dException.FieldNotFoundException(_("Non-existent
field '%s'") % (fld,))
# Copy the specified field vals and their row numbers to a
list, and
# add those lists to the sort list
@@ -1776,7 +1796,8 @@
# First, make sure that there is *something* in the field
kf = self.KeyField
if not kf:
- raise dException.MissingPKException, _("checkPK failed;
no primary key specified")
+ raise dException.MissingPKException(
+ _("checkPK failed; no primary key
specified"))
if isinstance(kf, basestring):
kf = [kf]
@@ -1785,7 +1806,8 @@
for fld in kf:
self._records[0][fld]
except KeyError:
- raise dException.MissingPKException, _("Primary key
field does not exist in the data set: ") + fld
+ raise dException.MissingPKException(
+ _("Primary key field does not exist in
the data set: ") + fld)
def makePkWhere(self, row=None):
Modified: trunk/dabo/db/dDataSet.py
===================================================================
--- trunk/dabo/db/dDataSet.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dDataSet.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -584,7 +584,7 @@
# if len(condList) == 1:
# # No equality specified
# errMsg = _("Bad join: no '==' in join condition: %s") %
condition
-# raise dException.QueryException, errMsg
+# raise dException.QueryException(errMsg)
#
# leftCond = None
# rightCond = None
@@ -613,7 +613,7 @@
# condError += "; "
# condError += _("No join condition specified for alias
'%s'") % rightAlias
# if condError:
-# raise dException.QueryException, condError
+# raise dException.QueryException(condError)
#
# # OK, we now know how to do the join. The plan is this:
# # create an empty result list
Modified: trunk/dabo/db/dbMsSQL.py
===================================================================
--- trunk/dabo/db/dbMsSQL.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dbMsSQL.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -202,7 +202,7 @@
""" Most backends will return a non-zero number if there are
deletions.
Some do not, so this will have to be customized in those cases.
"""
- #raise dException.dException, _("No records deleted")
+ #raise dException.dException(_("No records deleted"))
return
Modified: trunk/dabo/db/dbMySQL.py
===================================================================
--- trunk/dabo/db/dbMySQL.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dbMySQL.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -44,11 +44,15 @@
self._connection = dbapi.connect(host=connectInfo.Host,
user = connectInfo.User, passwd =
connectInfo.revealPW(),
db=connectInfo.Database, port=port,
**kwargs)
- except Exception, e:
- if "access denied" in str(e).lower():
- raise dException.DBNoAccessException(e)
+ except Exception, e:
+ try:
+ errMsg = str(e).decode(self.Encoding)
+ except UnicodeError:
+ errMsg = unicode(e)
+ if "access denied" in errMsg.lower():
+ raise dException.DBNoAccessException(errMsg)
else:
- raise dException.DatabaseException(e)
+ raise dException.DatabaseException(errMsg)
return self._connection
Modified: trunk/dabo/db/dbPostgreSQL.py
===================================================================
--- trunk/dabo/db/dbPostgreSQL.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dbPostgreSQL.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -1,11 +1,61 @@
# -*- coding: utf-8 -*-
+
+import codecs
import datetime
import dabo
from dabo.dLocalize import _
from dBackend import dBackend
+
class Postgres(dBackend):
"""Class providing PostgreSQL connectivity. Uses psycopg."""
+
+
+ _encodings = {
+ # mapping from Python encoding names
+ # to PostgreSQL character set names
+ 'big5': 'BIG5',
+ 'cp866': 'WIN866',
+ 'cp874': 'WIN874',
+ 'cp949': 'UHC',
+ 'cp1250': 'WIN1250',
+ 'cp1251': 'WIN1251',
+ 'cp1252': 'WIN1252',
+ 'cp1253': 'WIN1253',
+ 'cp1254': 'WIN1254',
+ 'cp1255': 'WIN1255',
+ 'cp1256': 'WIN1256',
+ 'cp1257': 'WIN1257',
+ 'cp1258': 'WIN1258',
+ 'euc_jis_2004': 'EUC_JIS_2004',
+ 'euc_jp': 'EUC_JP',
+ 'euc_kr': 'EUC_KR',
+ 'euc_tw': 'EUC_TW',
+ 'gb18030': 'GB18030',
+ 'gb2312': 'EUC_CN',
+ 'gbk': 'GBK',
+ 'iso8859-1': 'LATIN1',
+ 'iso8859-2': 'LATIN2',
+ 'iso8859-3': 'LATIN3',
+ 'iso8859-4': 'LATIN4',
+ 'iso8859-5': 'ISO_8859_5',
+ 'iso8859-6': 'ISO_8859_6',
+ 'iso8859-7': 'ISO_8859_7',
+ 'iso8859-8': 'ISO_8859_8',
+ 'iso8859-9': 'LATIN5',
+ 'iso8859-10': 'LATIN6',
+ 'iso8859-13': 'LATIN7',
+ 'iso8859-14': 'LATIN8',
+ 'iso8859-15': 'LATIN9',
+ 'iso8859-16': 'LATIN10',
+ 'johab': 'JOHAB',
+ 'koi8-r': 'KOI8',
+ 'shift_jis': 'SJIS',
+ 'shift_jis_2004': 'SHIFT_JIS_2004',
+ 'utf-8': 'UTF8'
+ }
+
+
def __init__(self):
""" JFCS 08/23/07 Currently supporting only psycopg2"""
dBackend.__init__(self)
@@ -16,21 +66,33 @@
def getConnection(self, connectInfo, **kwargs):
import psycopg2 as dbapi
self.conn_user = connectInfo.User
- #- jfcs 11/01/04 port needs to be a string
- port = str(connectInfo.Port)
- if not port or port == "None":
- port = "5432"
-
- DSN = "host=%s port=%s dbname=%s user=%s password=%s" %
(connectInfo.Host,
- port, connectInfo.Database, connectInfo.User,
connectInfo.revealPW())
- # Instead of blindly appending kwargs here, it would be
preferable to only accept
- # those that can be used safely.
-# for kw, val in kwargs:
-# DSN += " %s=%s" % (kw, val)
+ DSN = "host=%s port=%d dbname=%s user=%s password=%s" % (
+ connectInfo.Host, connectInfo.Port or 5432,
connectInfo.Database,
+ self.conn_user, connectInfo.revealPW())
self._connection = dbapi.connect(DSN)
+ self.setClientEncoding()
return self._connection
+ def setClientEncoding(self, encoding=None):
+ if not encoding:
+ encoding = self.Encoding
+ try:
+ encoding = codecs.lookup(encoding).name
+ except (AttributeError, LookupError):
+ pass
+ try:
+ encoding = self._encodings[encoding]
+ except KeyError:
+ dabo.dbActivityLog.write("unknown encoding %r" %
encoding)
+ if self._connection.encoding != encoding:
+ try:
+ self._connection.set_client_encoding(encoding)
+ except Exception:
+ dabo.dbActivityLog.write("cannot set database
client encoding")
+ return encoding
+
+
def beginTransaction(self, cursor):
dabo.dbActivityLog.write("SQL: begin (implicit, nothing done)")
return True
Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/db/dbSQLite.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -102,8 +102,12 @@
# There is no transaction active in this case, so
ignore the error.
pass
except Exception, e:
- dabo.dbActivityLog.write("SQL: commit failed: %s" % e)
- raise dException.DBQueryException, e
+ try:
+ errMsg = str(e).decode(self.Encoding)
+ except UnicodeError:
+ errMsg = unicode(e)
+ dabo.dbActivityLog.write("SQL: commit failed: %s" %
errMsg)
+ raise dException.DBQueryException(errMsg)
def rollbackTransaction(self, cursor):
Modified: trunk/dabo/lib/RemoteConnector.py
===================================================================
--- trunk/dabo/lib/RemoteConnector.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/lib/RemoteConnector.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -123,13 +123,13 @@
errText = e.read()
errMsg = "\n".join(errText.splitlines()[4:])
if errcode == 409:
- raise dException.BusinessRuleViolation, errMsg
+ raise dException.BusinessRuleViolation(errMsg)
elif errcode == 500:
- raise dException.ConnectionLostException, errMsg
+ raise dException.ConnectionLostException(errMsg)
elif errcode == 204:
- raise dException.NoRecordsException, errMsg
+ raise dException.NoRecordsException(errMsg)
elif errcode == 400:
- raise dException.DBQueryException, errMsg
+ raise dException.DBQueryException(errMsg)
else:
# If successful, we need to clear the mementos. We
don't need to
# store anything; passing None will just clear the
mementos.
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py 2008-12-16 06:09:33 UTC (rev 4843)
+++ trunk/dabo/ui/uiwx/dFormMixin.py 2008-12-16 23:19:20 UTC (rev 4844)
@@ -373,8 +373,8 @@
NOTE: wxPython does not currently support this. DO NOT USE
this method.
"""
- raise dException.FeatureNotSupportedException, \
- _("The underlying UI toolkit does not support
modal forms. Use a dDialog instead.")
+ raise dException.FeatureNotSupportedException(
+ _("The underlying UI toolkit does not support
modal forms. Use a dDialog instead."))
def release(self):
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]