Support Time type.
parent
a40827a0e7
commit
b1d627abf5
|
|
@ -158,6 +158,8 @@ Changelog
|
||||||
|
|
||||||
- Improve robustness of java to python type conversion.
|
- Improve robustness of java to python type conversion.
|
||||||
|
|
||||||
|
- Support Time type.
|
||||||
|
|
||||||
- Add DB-API compliant exception handling.
|
- Add DB-API compliant exception handling.
|
||||||
|
|
||||||
- Minor documentation improvements.
|
- Minor documentation improvements.
|
||||||
|
|
|
||||||
|
|
@ -526,6 +526,12 @@ def _to_datetime(rs, col):
|
||||||
d = d.replace(microsecond=int(str(java_val.getNanos())[:6]))
|
d = d.replace(microsecond=int(str(java_val.getNanos())[:6]))
|
||||||
return str(d)
|
return str(d)
|
||||||
|
|
||||||
|
def _to_time(rs, col):
|
||||||
|
java_val = rs.getTime(col)
|
||||||
|
if not java_val:
|
||||||
|
return
|
||||||
|
return str(java_val)
|
||||||
|
|
||||||
def _to_date(rs, col):
|
def _to_date(rs, col):
|
||||||
java_val = rs.getDate(col)
|
java_val = rs.getDate(col)
|
||||||
if not java_val:
|
if not java_val:
|
||||||
|
|
@ -579,6 +585,7 @@ _DEFAULT_CONVERTERS = {
|
||||||
# http://download.oracle.com/javase/6/docs/api/java/sql/Types.html
|
# http://download.oracle.com/javase/6/docs/api/java/sql/Types.html
|
||||||
# for possible keys
|
# for possible keys
|
||||||
'TIMESTAMP': _to_datetime,
|
'TIMESTAMP': _to_datetime,
|
||||||
|
'TIME': _to_time,
|
||||||
'DATE': _to_date,
|
'DATE': _to_date,
|
||||||
'BINARY': _to_binary,
|
'BINARY': _to_binary,
|
||||||
'DECIMAL': _to_double,
|
'DECIMAL': _to_double,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ create table Account (
|
||||||
"BLOCKING" DECIMAL,
|
"BLOCKING" DECIMAL,
|
||||||
"DBL_COL" DOUBLE,
|
"DBL_COL" DOUBLE,
|
||||||
"OPENED_AT" DATE,
|
"OPENED_AT" DATE,
|
||||||
|
"OPENED_AT_TIME" TIME,
|
||||||
"VALID" BOOLEAN,
|
"VALID" BOOLEAN,
|
||||||
"PRODUCT_NAME" VARCHAR(50),
|
"PRODUCT_NAME" VARCHAR(50),
|
||||||
"STUFF" BLOB,
|
"STUFF" BLOB,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ create table Account (
|
||||||
"BLOCKING" DECIMAL,
|
"BLOCKING" DECIMAL,
|
||||||
"DBL_COL" DOUBLE,
|
"DBL_COL" DOUBLE,
|
||||||
"OPENED_AT" DATE,
|
"OPENED_AT" DATE,
|
||||||
|
"OPENED_AT_TIME" TIME,
|
||||||
"VALID" BOOLEAN,
|
"VALID" BOOLEAN,
|
||||||
"PRODUCT_NAME" VARCHAR(50),
|
"PRODUCT_NAME" VARCHAR(50),
|
||||||
primary key ("ACCOUNT_ID")
|
primary key ("ACCOUNT_ID")
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,27 @@ class IntegrationTestBase(object):
|
||||||
dbl_col, '2008-02-27', valid, product_name )
|
dbl_col, '2008-02-27', valid, product_name )
|
||||||
self.assertEqual(result, exp)
|
self.assertEqual(result, exp)
|
||||||
|
|
||||||
|
def test_execute_type_time(self):
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
stmt = "insert into ACCOUNT (ACCOUNT_ID, ACCOUNT_NO, BALANCE, " \
|
||||||
|
"OPENED_AT_TIME) " \
|
||||||
|
"values (?, ?, ?, ?)"
|
||||||
|
d = self.dbapi
|
||||||
|
account_id = d.Timestamp(2010, 01, 26, 14, 31, 59)
|
||||||
|
account_no = 20
|
||||||
|
balance = 1.2
|
||||||
|
opened_at_time = d.Time(13, 59, 59)
|
||||||
|
parms = (account_id, account_no, balance, opened_at_time)
|
||||||
|
cursor.execute(stmt, parms)
|
||||||
|
stmt = "select ACCOUNT_ID, ACCOUNT_NO, BALANCE, OPENED_AT_TIME " \
|
||||||
|
"from ACCOUNT where ACCOUNT_NO = ?"
|
||||||
|
parms = (20, )
|
||||||
|
cursor.execute(stmt, parms)
|
||||||
|
result = cursor.fetchone()
|
||||||
|
cursor.close()
|
||||||
|
exp = ( '2010-01-26 14:31:59', account_no, balance, '13:59:59' )
|
||||||
|
self.assertEqual(result, exp)
|
||||||
|
|
||||||
def test_execute_different_rowcounts(self):
|
def test_execute_different_rowcounts(self):
|
||||||
cursor = self.conn.cursor()
|
cursor = self.conn.cursor()
|
||||||
stmt = "insert into ACCOUNT (ACCOUNT_ID, ACCOUNT_NO, BALANCE) " \
|
stmt = "insert into ACCOUNT (ACCOUNT_ID, ACCOUNT_NO, BALANCE) " \
|
||||||
|
|
@ -206,6 +227,9 @@ class SqlitePyTest(SqliteTestBase, unittest.TestCase):
|
||||||
import sqlite3
|
import sqlite3
|
||||||
return sqlite3, sqlite3.connect(':memory:')
|
return sqlite3, sqlite3.connect(':memory:')
|
||||||
|
|
||||||
|
def test_execute_type_time(self):
|
||||||
|
"""Time type not supported by PySqlite"""
|
||||||
|
|
||||||
class SqliteXerialTest(SqliteTestBase, unittest.TestCase):
|
class SqliteXerialTest(SqliteTestBase, unittest.TestCase):
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue