Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nuodb/nuodb-python
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Getto committed Jun 11, 2013
2 parents d06dbba + 6fe3b8e commit 05e977d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ install:
test:
python run_tests.py

deploy:
python setup.py register
python setup.py sdist upload

.PHONY: all install test
18 changes: 12 additions & 6 deletions pynuodb/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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):
Expand Down
13 changes: 12 additions & 1 deletion tests/nuodb_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 05e977d

Please sign in to comment.