Skip to content

Commit ce730e9

Browse files
authored
Merge pull request #37 from Fred-si/fix-pre-1858-11-17-date-encoding
Fix for #34 - Pre-1970 dates causes OverflowError
2 parents 6b6cf99 + 2be39f1 commit ce730e9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.10.2] - Unreleased
8+
9+
### Fixed
10+
11+
- #34 - Pre-1970 dates causes OverflowError
12+
713
## [1.10.1] - 2023-12-21
814

915
### Fixed

src/firebird/driver/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3328,7 +3328,7 @@ def _pack_input(self, meta: iMessageMetadata, buffer: bytes,
33283328
in_meta.get_subtype(i), scale)
33293329
memmove(buf_addr + offset, value.to_bytes(length, 'little', signed=True), length)
33303330
elif datatype == SQLDataType.DATE:
3331-
memmove(buf_addr + offset, _util.encode_date(value).to_bytes(length, 'little'), length)
3331+
memmove(buf_addr + offset, _util.encode_date(value).to_bytes(length, 'little', signed=True), length)
33323332
elif datatype == SQLDataType.TIME:
33333333
memmove(buf_addr + offset, _util.encode_time(value).to_bytes(length, 'little'), length)
33343334
elif datatype == SQLDataType.TIME_TZ:

tests/test_driver.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,16 @@ def test_insert_datetime(self):
14751475
self.assertListEqual(rows,
14761476
[(4, datetime.date(2011, 11, 13), datetime.time(15, 0, 1, 200000),
14771477
datetime.datetime(2011, 11, 13, 15, 0, 1, 200000))])
1478+
1479+
# encode date before 1859-11-17 produce a negative number
1480+
now = datetime.datetime(1859, 11, 16, 15, 0, 1, 200000)
1481+
cur.execute('insert into T2 (C1,C6,C7,C8) values (?,?,?,?)', [5, now.date(), now.time(), now])
1482+
self.con.commit()
1483+
cur.execute('select C1,C6,C7,C8 from T2 where C1 = 5')
1484+
rows = cur.fetchall()
1485+
self.assertListEqual(rows,
1486+
[(5, datetime.date(1859, 11, 16), datetime.time(15, 0, 1, 200000),
1487+
datetime.datetime(1859, 11, 16, 15, 0, 1, 200000))])
14781488
def test_insert_blob(self):
14791489
with self.con.cursor() as cur, self.con2.cursor() as cur2:
14801490
cur.execute('insert into T2 (C1,C9) values (?,?)', [4, 'This is a BLOB!'])

0 commit comments

Comments
 (0)