diff --git a/.travis.yml b/.travis.yml index 9365614..a4f4a03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python python: - "2.7" - - "2.6" env: - NUODB_ROOT=/opt/nuodb NUODB_INCLUDE_DIR=/opt/nuodb/include NUODB_LIB_DIR=/opt/nuodb/lib64 NODE_PATH=/usr/local/bin NUODB_VERSION=1.0.2 diff --git a/Makefile b/Makefile index 8968fae..74d9c52 100644 --- a/Makefile +++ b/Makefile @@ -37,4 +37,8 @@ install: test: python run_tests.py +deploy: + python setup.py register + python setup.py sdist upload + .PHONY: all install test \ No newline at end of file diff --git a/pynuodb/datatype.py b/pynuodb/datatype.py index 209d542..510323c 100644 --- a/pynuodb/datatype.py +++ b/pynuodb/datatype.py @@ -68,7 +68,10 @@ def TimestampFromTicks(ticks, micro = 0): def DateToTicks(value): """Converts a Date object to ticks.""" timeStruct = Date(value.year, value.month, value.day).timetuple() - return int(time.mktime(timeStruct)) + try: + return int(time.mktime(timeStruct)) + except: + raise DataError("Year out of range") def TimeToTicks(value): """Converts a Time object to ticks.""" @@ -79,11 +82,14 @@ def TimeToTicks(value): def TimestampToTicks(value): """Converts a Timestamp object to ticks.""" timeStruct = Timestamp(value.year, value.month, value.day, value.hour, value.minute, value.second).timetuple() - if value.microsecond: - micro = decimal.Decimal(value.microsecond) / decimal.Decimal(1000000) - return (int((decimal.Decimal(int(time.mktime(timeStruct))) + micro) * decimal.Decimal(int(10**(len(str(micro)) - 2)))), len(str(micro)) - 2) - else: - return (int(time.mktime(timeStruct)), 0) + try: + if value.microsecond: + micro = decimal.Decimal(value.microsecond) / decimal.Decimal(1000000) + return (int((decimal.Decimal(int(time.mktime(timeStruct))) + micro) * decimal.Decimal(int(10**(len(str(micro)) - 2)))), len(str(micro)) - 2) + else: + return (int(time.mktime(timeStruct)), 0) + except: + raise DataError("Year out of range") class TypeObject(object): def __init__(self, *values): diff --git a/tests/nuodb_basic_test.py b/tests/nuodb_basic_test.py index 7197bfe..9fa4570 100644 --- a/tests/nuodb_basic_test.py +++ b/tests/nuodb_basic_test.py @@ -717,7 +717,18 @@ def test_all_types(self): try: cursor.execute("drop table typetest if exists") finally: - con.close() + con.close() + + def test_param_date_error(self): + con = self._connect() + cursor = con.cursor() + cursor.execute("drop table typetest if exists") + cursor.execute("create table typetest (id integer GENERATED ALWAYS AS IDENTITY, date_col date)") + + test_vals = (pynuodb.Date(1900, 1, 1),) + + with self.assertRaises(pynuodb.DataError): + cursor.execute("insert into typetest (date_col) values (?)", test_vals) if __name__ == '__main__': unittest.main() \ No newline at end of file