Bugs item #762523, was opened at 2003-06-28 17:17
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=762523&group_id=78018
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Richard Laager (rlaager)
Assigned to: Nobody/Anonymous (nobody)
Summary: reading SQL dates before the epoch creates strange results
Initial Comment:
Insert* a date before 1970-01-01 00:00:00.000 GMT
into a database and try reading it from Python using the
odbc driver.
* This will probably require using something other than
Python. I haven't tested inserting such dates, only
reading them.
The bug probably exists because mktime returns -1 for
dates that it can't represent. I whipped up the following
untested patch which will turn all unrepresentable dates
into the epoch. This is much better than returning
random data from memory.
I don't know enough about the driver to suggest a
better way to do this.
diff -ur win32-orig/src/odbc.cpp win32/src/odbc.cpp
--- win32-orig/src/odbc.cpp 1997-06-13
10:37:06.000000000 -0500
+++ win32/src/odbc.cpp 2003-06-28
17:00:06.000000000 -0500
@@ -427,7 +427,11 @@
gt.tm_hour = dt->hour;
gt.tm_min = dt->minute;
gt.tm_sec = dt->second;
- return dbiMakeDate(PyInt_FromLong(mktime(>)));
+ time_t t = mktime(>);
+ // Set dates outside of time_t's range to the epoch.
+ if (t == (time_t)-1)
+ t = 0;
+ return dbiMakeDate(PyInt_FromLong(t)));
}
static PyObject *rawCopy(const void *v, int sz)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=762523&group_id=78018
|