Changeset: 9677b89dd8fb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9677b89dd8fb
Modified Files:
clients/python2/monetdb/sql/pythonize.py
clients/python2/monetdb/sql/types.py
clients/python2/test/capabilities.py
clients/python3/monetdb/sql/pythonize.py
clients/python3/monetdb/sql/types.py
clients/python3/test/capabilities.py
clients/python3/test/run.sh
Branch: default
Log Message:
fixed and accepted patch submitted by Pete Hollobon (bug #3273)
diffs (truncated from 385 to 300 lines):
diff --git a/clients/python2/monetdb/sql/pythonize.py
b/clients/python2/monetdb/sql/pythonize.py
--- a/clients/python2/monetdb/sql/pythonize.py
+++ b/clients/python2/monetdb/sql/pythonize.py
@@ -26,41 +26,7 @@ from monetdb.sql import types
from monetdb.exceptions import ProgrammingError
-def strip(data):
- """ returns a python string, with chopped off quotes,
- and replaced escape characters"""
- return data[1:-1].decode('string_escape').decode('utf-8')
-
-
-def py_bool(data):
- """ return python boolean """
- return data == "true"
-
-
-def py_time(data):
- """ returns a python Time
- """
- return Time(*[int(float(x)) for x in data.split(':')])
-
-
-def py_date(data):
- """ Returns a python Date
- """
- return Date(*[int(float(x)) for x in data.split('-')])
-
-
-def py_timestamp(data):
- """ Returns a python Timestamp
- """
- splitted = data.split(" ")
- date = [int(float(x)) for x in splitted[0].split('-')]
- time = [int(float(x)) for x in splitted[1].split(':')]
- return Timestamp(*(date + time))
-
-
-def py_timestamptz(data):
- """ Returns a python Timestamp where data contains a tz code
- """
+def _extract_timezone(data):
if data.find('+') != -1:
(dt, tz) = data.split("+")
(tzhour, tzmin) = [int(x) for x in tz.split(':')]
@@ -72,6 +38,53 @@ def py_timestamptz(data):
else:
raise ProgrammingError("no + or - in %s" % data)
+ return dt, tzhour, tzmin
+
+
+def strip(data):
+ """ returns a python string, with chopped off quotes,
+ and replaced escape characters"""
+ return data[1:-1].decode('string_escape').decode('utf-8')
+
+
+def py_bool(data):
+ """ return python boolean """
+ return data == "true"
+
+
+def py_time(data):
+ """ returns a python Time
+ """
+ return Time(*[int(float(x)) for x in data.split(':')])
+
+
+def py_timetz(data):
+ """ returns a python Time where data contains a tz code
+ """
+ dt, tzhour, tzmin = _extract_timezone(data)
+ hour, minute, second = [int(float(x)) for x in dt.split(':')]
+ return Time(hour + tzhour, minute + tzmin, second)
+
+
+def py_date(data):
+ """ Returns a python Date
+ """
+ return Date(*[int(float(x)) for x in data.split('-')])
+
+
+def py_timestamp(data):
+ """ Returns a python Timestamp
+ """
+ splitted = data.split(" ")
+ date = [int(float(x)) for x in splitted[0].split('-')]
+ time = [int(float(x)) for x in splitted[1].split(':')]
+ return Timestamp(*(date + time))
+
+
+def py_timestamptz(data):
+ """ Returns a python Timestamp where data contains a tz code
+ """
+ dt, tzhour, tzmin = _extract_timezone(data)
(datestr, timestr) = dt.split(" ")
date = [int(float(x)) for x in datestr.split('-')]
time = [int(float(x)) for x in timestr.split(':')]
@@ -79,6 +92,7 @@ def py_timestamptz(data):
hour, minute, second = time
return Timestamp(year, month, day, hour + tzhour, minute + tzmin, second)
+
mapping = {
types.CHAR: strip,
types.VARCHAR: strip,
@@ -97,6 +111,7 @@ mapping = {
types.TIME: py_time,
types.TIMESTAMP: py_timestamp,
types.TIMESTAMPTZ: py_timestamptz,
+ types.TIMETZ: py_timetz,
types.INTERVAL: strip,
types.MONTH_INTERVAL: strip,
types.SEC_INTERVAL: strip,
@@ -105,6 +120,8 @@ mapping = {
types.MEDIUMINT: int,
types.LONGINT: int,
types.FLOAT: float,
+ types.URL: strip,
+ types.INET: str,
}
diff --git a/clients/python2/monetdb/sql/types.py
b/clients/python2/monetdb/sql/types.py
--- a/clients/python2/monetdb/sql/types.py
+++ b/clients/python2/monetdb/sql/types.py
@@ -42,12 +42,16 @@ SEC_INTERVAL = 'sec_interval'
WRD = 'wrd'
TINYINT = 'tinyint'
+URL = 'url'
+INET = 'inet'
+
# Not on the website:
SHORTINT = 'shortint'
MEDIUMINT = 'mediumint'
LONGINT = 'longint'
FLOAT = 'float'
TIMESTAMPTZ = 'timestamptz'
+TIMETZ = 'timetz'
# full names and aliases, spaces are replaced with underscores
diff --git a/clients/python2/test/capabilities.py
b/clients/python2/test/capabilities.py
--- a/clients/python2/test/capabilities.py
+++ b/clients/python2/test/capabilities.py
@@ -241,6 +241,14 @@ class DatabaseTest(unittest.TestCase):
('col1 TIME',),
generator)
+ def test_TIME(self):
+ ticks = time()
+ def generator(row,col):
+ return self.db_module.TimeFromTicks(ticks+row*86400-col*1313)
+ self.check_data_integrity(
+ ('col1 TIMETZ',),
+ generator)
+
def test_DATETIME(self):
ticks = time()
def generator(row,col):
@@ -319,6 +327,20 @@ class DatabaseTest(unittest.TestCase):
('col1 BOOL',),
generator)
+ def test_URL(self):
+ def generator(row,col):
+ return "http://example.org/something"
+ self.check_data_integrity(
+ ('col1 URL',),
+ generator)
+
+ def test_INET(self):
+ def generator(row,col):
+ return "192.168.254.101"
+ self.check_data_integrity(
+ ('col1 INET',),
+ generator)
+
def test_description(self):
self.table = self.new_table_name()
shouldbe = [
diff --git a/clients/python3/monetdb/sql/pythonize.py
b/clients/python3/monetdb/sql/pythonize.py
--- a/clients/python3/monetdb/sql/pythonize.py
+++ b/clients/python3/monetdb/sql/pythonize.py
@@ -27,44 +27,7 @@ from monetdb.sql import types
from monetdb.exceptions import ProgrammingError
-def strip(data):
- """ returns a python string, with chopped off quotes,
- and replaced escape characters"""
- return ''.join([w.encode('utf-8').decode('unicode_escape')
- if '\\' in w
- else w
- for w in re.split('([\000-\200]+)', data[1:-1])])
-
-
-def py_bool(data):
- """ return python boolean """
- return data == "true"
-
-
-def py_time(data):
- """ returns a python Time
- """
- return Time(*[int(float(x)) for x in data.split(':')])
-
-
-def py_date(data):
- """ Returns a python Date
- """
- return Date(*[int(float(x)) for x in data.split('-')])
-
-
-def py_timestamp(data):
- """ Returns a python Timestamp
- """
- splitted = data.split(" ")
- date = [int(float(x)) for x in splitted[0].split('-')]
- time = [int(float(x)) for x in splitted[1].split(':')]
- return Timestamp(*(date + time))
-
-
-def py_timestamptz(data):
- """ Returns a python Timestamp where data contains a tz code
- """
+def _extract_timezone(data):
if data.find('+') != -1:
(dt, tz) = data.split("+")
(tzhour, tzmin) = [int(x) for x in tz.split(':')]
@@ -76,6 +39,56 @@ def py_timestamptz(data):
else:
raise ProgrammingError("no + or - in %s" % data)
+ return dt, tzhour, tzmin
+
+
+def strip(data):
+ """ returns a python string, with chopped off quotes,
+ and replaced escape characters"""
+ return ''.join([w.encode('utf-8').decode('unicode_escape')
+ if '\\' in w
+ else w
+ for w in re.split('([\000-\200]+)', data[1:-1])])
+
+
+def py_bool(data):
+ """ return python boolean """
+ return data == "true"
+
+
+def py_time(data):
+ """ returns a python Time
+ """
+ return Time(*[int(float(x)) for x in data.split(':')])
+
+
+def py_timetz(data):
+ """ returns a python Time where data contains a tz code
+ """
+ dt, tzhour, tzmin = _extract_timezone(data)
+ hour, minute, second = [int(float(x)) for x in dt.split(':')]
+ return Time(hour + tzhour, minute + tzmin, second)
+
+
+def py_date(data):
+ """ Returns a python Date
+ """
+ return Date(*[int(float(x)) for x in data.split('-')])
+
+
+def py_timestamp(data):
+ """ Returns a python Timestamp
+ """
+ splitted = data.split(" ")
+ date = [int(float(x)) for x in splitted[0].split('-')]
+ time = [int(float(x)) for x in splitted[1].split(':')]
+ return Timestamp(*(date + time))
+
+
+def py_timestamptz(data):
+ """ Returns a python Timestamp where data contains a tz code
+ """
+ dt, tzhour, tzmin = _extract_timezone(data)
(datestr, timestr) = dt.split(" ")
date = [int(float(x)) for x in datestr.split('-')]
time = [int(float(x)) for x in timestr.split(':')]
@@ -83,6 +96,7 @@ def py_timestamptz(data):
hour, minute, second = time
return Timestamp(year, month, day, hour + tzhour, minute + tzmin, second)
+
mapping = {
types.CHAR: strip,
types.VARCHAR: strip,
@@ -101,6 +115,7 @@ mapping = {
types.TIME: py_time,
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list