Restore support for binding a date value to datetime variable.

This commit is contained in:
Anthony Tuininga 2018-02-02 15:44:45 -07:00
parent a9cda2a81d
commit 99c019d6c5
2 changed files with 26 additions and 20 deletions

View File

@ -302,31 +302,30 @@ int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue,
} else dbValue->asObject = obj->handle;
return 0;
case CXO_TRANSFORM_DATE:
if (!PyDateTime_Check(pyValue) && !PyDate_Check(pyValue)) {
PyErr_SetString(PyExc_TypeError, "expecting date or datetime");
return -1;
}
memset(&dbValue->asTimestamp, 0, sizeof(dbValue->asTimestamp));
dbValue->asTimestamp.year = PyDateTime_GET_YEAR(pyValue);
dbValue->asTimestamp.month = PyDateTime_GET_MONTH(pyValue);
dbValue->asTimestamp.day = PyDateTime_GET_DAY(pyValue);
return 0;
case CXO_TRANSFORM_DATETIME:
case CXO_TRANSFORM_TIMESTAMP:
case CXO_TRANSFORM_TIMESTAMP_LTZ:
if (!PyDateTime_Check(pyValue)) {
PyErr_SetString(PyExc_TypeError, "expecting datetime");
if (PyDateTime_Check(pyValue)) {
memset(&dbValue->asTimestamp, 0, sizeof(dbValue->asTimestamp));
dbValue->asTimestamp.year = PyDateTime_GET_YEAR(pyValue);
dbValue->asTimestamp.month = PyDateTime_GET_MONTH(pyValue);
dbValue->asTimestamp.day = PyDateTime_GET_DAY(pyValue);
dbValue->asTimestamp.hour = PyDateTime_DATE_GET_HOUR(pyValue);
dbValue->asTimestamp.minute =
PyDateTime_DATE_GET_MINUTE(pyValue);
dbValue->asTimestamp.second =
PyDateTime_DATE_GET_SECOND(pyValue);
dbValue->asTimestamp.fsecond =
PyDateTime_DATE_GET_MICROSECOND(pyValue) * 1000;
} else if (PyDate_Check(pyValue)) {
memset(&dbValue->asTimestamp, 0, sizeof(dbValue->asTimestamp));
dbValue->asTimestamp.year = PyDateTime_GET_YEAR(pyValue);
dbValue->asTimestamp.month = PyDateTime_GET_MONTH(pyValue);
dbValue->asTimestamp.day = PyDateTime_GET_DAY(pyValue);
} else {
PyErr_SetString(PyExc_TypeError, "expecting date or datetime");
return -1;
}
memset(&dbValue->asTimestamp, 0, sizeof(dbValue->asTimestamp));
dbValue->asTimestamp.year = PyDateTime_GET_YEAR(pyValue);
dbValue->asTimestamp.month = PyDateTime_GET_MONTH(pyValue);
dbValue->asTimestamp.day = PyDateTime_GET_DAY(pyValue);
dbValue->asTimestamp.hour = PyDateTime_DATE_GET_HOUR(pyValue);
dbValue->asTimestamp.minute = PyDateTime_DATE_GET_MINUTE(pyValue);
dbValue->asTimestamp.second = PyDateTime_DATE_GET_SECOND(pyValue);
dbValue->asTimestamp.fsecond =
PyDateTime_DATE_GET_MICROSECOND(pyValue) * 1000;
return 0;
case CXO_TRANSFORM_TIMEDELTA:
if (!PyDelta_Check(pyValue)) {

View File

@ -48,6 +48,13 @@ class TestDateTimeVar(BaseTestCase):
value = datetime.datetime(2002, 12, 13, 9, 36, 0))
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
def testBindDateInDateTimeVar(self):
"test binding date in a datetime variable"
var = self.cursor.var(cx_Oracle.DATETIME)
dateVal = datetime.date.today()
var.setvalue(0, dateVal)
self.assertEqual(var.getvalue().date(), dateVal)
def testBindDateAfterString(self):
"test binding in a date after setting input sizes to a string"
self.cursor.setinputsizes(value = 15)