Skip to content

Fix for #34 - Pre-1970 dates causes OverflowError #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.10.2] - Unreleased

### Fixed

- #34 - Pre-1970 dates causes OverflowError

## [1.10.1] - 2023-12-21

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,7 @@ def _pack_input(self, meta: iMessageMetadata, buffer: bytes,
in_meta.get_subtype(i), scale)
memmove(buf_addr + offset, value.to_bytes(length, 'little', signed=True), length)
elif datatype == SQLDataType.DATE:
memmove(buf_addr + offset, _util.encode_date(value).to_bytes(length, 'little'), length)
memmove(buf_addr + offset, _util.encode_date(value).to_bytes(length, 'little', signed=True), length)
elif datatype == SQLDataType.TIME:
memmove(buf_addr + offset, _util.encode_time(value).to_bytes(length, 'little'), length)
elif datatype == SQLDataType.TIME_TZ:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,16 @@ def test_insert_datetime(self):
self.assertListEqual(rows,
[(4, datetime.date(2011, 11, 13), datetime.time(15, 0, 1, 200000),
datetime.datetime(2011, 11, 13, 15, 0, 1, 200000))])

# encode date before 1859-11-17 produce a negative number
now = datetime.datetime(1859, 11, 16, 15, 0, 1, 200000)
cur.execute('insert into T2 (C1,C6,C7,C8) values (?,?,?,?)', [5, now.date(), now.time(), now])
self.con.commit()
cur.execute('select C1,C6,C7,C8 from T2 where C1 = 5')
rows = cur.fetchall()
self.assertListEqual(rows,
[(5, datetime.date(1859, 11, 16), datetime.time(15, 0, 1, 200000),
datetime.datetime(1859, 11, 16, 15, 0, 1, 200000))])
def test_insert_blob(self):
with self.con.cursor() as cur, self.con2.cursor() as cur2:
cur.execute('insert into T2 (C1,C9) values (?,?)', [4, 'This is a BLOB!'])
Expand Down