Update of /cvsroot/jtoolkit/jToolkit/data
In directory sc8-pr-cvs1:/tmp/cvs-serv11292/data
Modified Files:
__init__.py database.py dates.py dbtable.py
Log Message:
hate to do this, but a simple update of all the files from sjsoft for the meantime...
Index: __init__.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/data/__init__.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** __init__.py 25 Aug 2003 12:16:45 -0000 1.2
--- __init__.py 25 Sep 2003 17:36:55 -0000 1.3
***************
*** 20,23 ****
# list of modules in this package
! __all__ = ["ADOProviders","ADOTypes","PyADO","database","dates"]
--- 20,23 ----
# list of modules in this package
! __all__ = ["ADOProviders","ADOTypes","PyADO","database","dates","jsuite"]
Index: database.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** database.py 25 Aug 2003 12:16:45 -0000 1.2
--- database.py 25 Sep 2003 17:36:55 -0000 1.3
***************
*** 112,115 ****
--- 112,118 ----
def importdriver(self):
+ if self.DBTYPE == 'oracle' and hasattr(self.instance, 'NLS_LANG'):
+ import os
+ os.environ['NLS_LANG'] = self.instance.NLS_LANG
if self.DBTYPE in ('access', 'oracle', 'sqlserver'):
self.driver, self.dberror = importPyADO()
***************
*** 169,172 ****
--- 172,182 ----
raise
+ def getaddcolumnsql(self, tablename, columnname, columntype):
+ """returns the sql required to add a column of the given name and type to a table"""
+ if self.DBTYPE == 'access':
+ return "alter table %s add column %s %s" % (tablename, columnname, self.dbtypename(columntype))
+ else:
+ return "alter table %s add %s %s" % (tablename, columnname, self.dbtypename(columntype))
+
def dblowerfn(self):
"""return a function that converts text to lower case"""
***************
*** 199,221 ****
raise ValueError, "unknown database type %r in dblowerfn" % (self.DBTYPE)
- def dbreprstr(self, value):
- dbvalue = ""
- for ch in value:
- chnum = ord(ch)
- if (chnum >= 32 and chnum < 128) or chnum in (9,10,13):
- dbvalue += ch
- else:
- # TODO: store them like following, then convert them when reading back...
- # dbvalue += "\\x%x" % chnum
- dbvalue += "-"
- return dbvalue
-
def dbrepr(self, value, formattype = None):
# currently, the griddisplayformat is used to format datetimestrings in logtable. It should NOT be
#configured on string or text objects in categoryconf.
! if formattype is None: formattype = ''
if value is None:
return 'null'
! if (type(value) == str or type(value) == unicode) and formattype in dates.dateparsers:
value = dates.parsedate(value, formattype)
return dates.dbdatestring(value, self.DBTYPE)
--- 209,219 ----
raise ValueError, "unknown database type %r in dblowerfn" % (self.DBTYPE)
def dbrepr(self, value, formattype = None):
# currently, the griddisplayformat is used to format datetimestrings in logtable. It should NOT be
#configured on string or text objects in categoryconf.
! if formattype is None or formattype == 'None': formattype = ''
if value is None:
return 'null'
! if (type(value) == str or type(value) == unicode) and formattype.lower() not in ('', 'attachment'):
value = dates.parsedate(value, formattype)
return dates.dbdatestring(value, self.DBTYPE)
***************
*** 226,232 ****
# we know how to deal with basic strings...
elif type(value) == str:
! return "'" + self.dbreprstr(value.replace("'","''")) + "'"
elif type(value) == unicode:
! return "'" + self.dbreprstr(value.replace("'","''")) + "'"
# we know how to deal with certain objects
elif type(value) == types.InstanceType:
--- 224,230 ----
# we know how to deal with basic strings...
elif type(value) == str:
! return "'" + value.replace("'","''") + "'"
elif type(value) == unicode:
! return "'" + value.replace("'","''") + "'"
# we know how to deal with certain objects
elif type(value) == types.InstanceType:
***************
*** 348,352 ****
cachedrow, description = self.singlerowcache.get(sql, (None, None))
if cachedrow is not None:
- self.errorhandler.logtrace("using singlerowcache for "+sql)
if withdescription:
return cachedrow, description
--- 346,349 ----
***************
*** 371,375 ****
cachedrows, description = self.allrowscache.get(sql, (None, None))
if cachedrows is not None:
- self.errorhandler.logtrace("using allrowscache for "+sql)
if withdescription:
return cachedrows, description
--- 368,371 ----
Index: dates.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/data/dates.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dates.py 25 Aug 2003 12:16:45 -0000 1.2
--- dates.py 25 Sep 2003 17:36:55 -0000 1.3
***************
*** 22,25 ****
--- 22,38 ----
from jToolkit import cidict
import sre
+ import time
+
+ # we have copied _strptime from Python2.3 so that it can be used in earlier versions
+ if not hasattr(time, 'strptime'):
+ from jToolkit.data import _strptime
+ time.strptime = _strptime.strptime
+
+ # pywintypes has an error in time formatting, so we need to be able to detect this type on windows
+ try:
+ import pywintypes
+ errortimetype = pywintypes.TimeType
+ except ImportError:
+ errortimetype = None
date = mxDateTime.DateTime
***************
*** 134,153 ****
def parsedate(value, formattype):
"""parses a date/time string of the given type, returns a datetime object"""
! parser = dateparsers.get(formattype, dateparsers['GENERAL DATE'])
! if type(value) in (str,unicode):
! value = parser.parse(value)
! # elif type(value).__name__ == 'time':
! else:
raise ValueError, "unexpected type in parsedate: %r, %r" % (value, type(value))
! return value
def formatdate(value, formattype):
"""formats a date/time object of the given type, returns a string"""
! dateformat = dateformats.get(formattype, dateformats['GENERAL DATE'])
if hasattr(value,'Format'):
return value.Format(dateformat)
# handle null values
elif value is None or value == '':
return ''
else:
raise ValueError, "unexpected type in formatdate: %r, %r" % (value, type(value))
--- 147,183 ----
def parsedate(value, formattype):
"""parses a date/time string of the given type, returns a datetime object"""
! if type(value) not in (str,unicode):
raise ValueError, "unexpected type in parsedate: %r, %r" % (value, type(value))
! try:
! # we still want to support things like 'GENERAL DATE' for now
! # TODO: remove 'GENERAL DATE' support once people have upgraded
! if formattype in dateformats:
! timevalue = time.strptime(value, dateformats[formattype])
! else:
! timevalue = time.strptime(value, formattype)
! return apply(date, timevalue[:6])
! except ValueError:
! parser = dateparsers.get(formattype, dateparsers['GENERAL DATE'])
! return parser.parse(value)
def formatdate(value, formattype):
"""formats a date/time object of the given type, returns a string"""
! # we still want to support things like 'GENERAL DATE' for now
! # TODO: remove 'GENERAL DATE' support once people have upgraded
! if formattype in dateformats:
! dateformat = dateformats[formattype]
! else:
! dateformat = formattype
if hasattr(value,'Format'):
+ # this is to correct an error in PyTime.Format (always displays weekday as Sunday)
+ # TODO: remove this if the error is fixed
+ if type(value) == errortimetype:
+ value = mxDateTime.DateTime(value.year, value.month, value.day, value.hour, value.minute, value.second)
return value.Format(dateformat)
# handle null values
elif value is None or value == '':
return ''
+ elif type(value) == tuple:
+ return time.strftime(dateformat, value)
else:
raise ValueError, "unexpected type in formatdate: %r, %r" % (value, type(value))
Index: dbtable.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/data/dbtable.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dbtable.py 25 Aug 2003 12:16:45 -0000 1.2
--- dbtable.py 25 Sep 2003 17:36:55 -0000 1.3
***************
*** 23,27 ****
from jToolkit import cidict
! class DBTable:
"""DBTable is an abstraction of a table and its related data"""
def __init__(self, db, tablename, columnlist, rowidcols, orderbycols):
--- 23,27 ----
from jToolkit import cidict
! class DBTable(object):
"""DBTable is an abstraction of a table and its related data"""
def __init__(self, db, tablename, columnlist, rowidcols, orderbycols):
|