Changeset: 63a11eca5310 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=63a11eca5310
Modified Files:
python/monetdb/sql/converters.py
python/monetdb/sql/type_codes.py
python/test/capabilities.py
Branch: default
Log Message:
fixed bug #2520, added support for undocumented field timestamptz
diffs (85 lines):
diff -r 52f391796452 -r 63a11eca5310 python/monetdb/sql/converters.py
--- a/python/monetdb/sql/converters.py Thu May 13 14:20:12 2010 +0200
+++ b/python/monetdb/sql/converters.py Thu May 13 14:52:36 2010 +0200
@@ -48,6 +48,7 @@
type_codes.DATE: self.__date,
type_codes.TIME: self.__time,
type_codes.TIMESTAMP: self.__timestamp,
+ type_codes.TIMESTAMPTZ: self.__timestamptz,
type_codes.INTERVAL: self.__strip,
type_codes.MONTH_INTERVAL: self.__strip,
type_codes.SEC_INTERVAL: self.__strip,
@@ -121,6 +122,26 @@
time = [int(float(x)) for x in splitted[1].split(':')]
return Timestamp(*date+time)
+ def __timestamptz(self, data):
+ if data.find('+')!= -1:
+ (dt, tz) = data.split("+")
+ (tzhour, tzmin) = [int(x) for x in tz.split(':')]
+ elif data.find('-')!= -1:
+ (dt, tz) = data.split("-")
+ (tzhour, tzmin) = [int(x) for x in tz.split(':')]
+ tzhour = tzhour * -1
+ tzmin = tzmin * -1
+ else:
+ raise ProgrammingError("no + or - in %s" % data)
+
+ (datestr, timestr) = dt.split(" ")
+ date = [int(float(x)) for x in datestr.split('-')]
+ time = [int(float(x)) for x in timestr.split(':')]
+ year, month, day = date
+ hour, minute, second = time
+ return Timestamp(year, month, day, hour+tzhour, minute+tzmin, second)
+
+
def __blob(self, x):
""" Converts a monetdb blob in string representation to a python
string.
The input is a string in the format: '(length: char char char char ...
)'
@@ -135,7 +156,10 @@
if data == "NULL":
return None
- return self.mapping[type_code](data)
+ try:
+ return self.mapping[type_code](data)
+ except KeyError:
+ raise ProgrammingError("type %s is not supported by Python API" %
type_code)
class Monetizer:
diff -r 52f391796452 -r 63a11eca5310 python/monetdb/sql/type_codes.py
--- a/python/monetdb/sql/type_codes.py Thu May 13 14:20:12 2010 +0200
+++ b/python/monetdb/sql/type_codes.py Thu May 13 14:52:36 2010 +0200
@@ -45,6 +45,7 @@
MEDIUMINT = 'mediumint'
LONGINT = 'longint'
FLOAT = 'float'
+TIMESTAMPTZ = 'timestamptz'
# full names and aliases, spaces are replaced with underscores
@@ -54,3 +55,4 @@
BINARY_LARGE_OBJECT = BLOB
NUMERIC = DECIMAL
DOUBLE_PRECISION = DOUBLE
+
diff -r 52f391796452 -r 63a11eca5310 python/test/capabilities.py
--- a/python/test/capabilities.py Thu May 13 14:20:12 2010 +0200
+++ b/python/test/capabilities.py Thu May 13 14:52:36 2010 +0200
@@ -300,6 +300,15 @@
('col1 TIMESTAMP',),
generator)
+ def test_TIMESTAMPTZ(self):
+ ticks = time()
+ def generator(row,col):
+ return self.db_module.TimestampFromTicks(ticks+row*86400-col*1313)
+ self.check_data_integrity(
+ ('col1 TIMESTAMPTZ',),
+ generator)
+
+
def test_fractional_TIMESTAMP(self):
ticks = time()
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list