void OraclePreparedStatement_setTimestamp(T P, int parameterIndex, time_t time) { assert(P); struct tm ts = {.tm_isdst = -1}; ub4 valid; int i = checkAndSetParameterIndex(parameterIndex, P->paramCount); P->lastError = OCIDescriptorAlloc((dvoid *)P->env, (dvoid **) &(P->params[i].type.date), (ub4) OCI_DTYPE_TIMESTAMP, (size_t) 0, (dvoid **) 0); if (P->lastError != OCI_SUCCESS && P->lastError != OCI_SUCCESS_WITH_INFO) THROW(SQLException, "%s", OraclePreparedStatement_getLastError(P->lastError, P->err)); gmtime_r(&time, &ts); OCIDateTimeConstruct(P->usr, P->err, P->params[i].type.date, //OCIDateTime *datetime, ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, 0/*fsec*/, (OraText*)0, 0); if (OCI_SUCCESS != OCIDateTimeCheck(P->usr, P->err, P->params[i].type.date, &valid) || valid != 0) { THROW(SQLException, "Invalid date/time value"); } P->params[i].length = sizeof(OCIDateTime *); P->lastError = OCIBindByPos(P->stmt, &P->params[i].bind, P->err, parameterIndex, &P->params[i].type.date, P->params[i].length, SQLT_TIMESTAMP, 0, 0, 0, 0, 0, OCI_DEFAULT); if (P->lastError != OCI_SUCCESS && P->lastError != OCI_SUCCESS_WITH_INFO) THROW(SQLException, "%s", OraclePreparedStatement_getLastError(P->lastError, P->err)); } void OraclePreparedStatement_setInt(T P, int parameterIndex, int x) { assert(P); int i = checkAndSetParameterIndex(parameterIndex, P->paramCount); P->params[i].type.integer = x; P->params[i].length = sizeof(x); P->lastError = OCIBindByPos(P->stmt, &P->params[i].bind, P->err, parameterIndex, &P->params[i].type.integer, (int)P->params[i].length, SQLT_INT, 0, 0, 0, 0, 0, OCI_DEFAULT); if (P->lastError != OCI_SUCCESS && P->lastError != OCI_SUCCESS_WITH_INFO) THROW(SQLException, "%s", OraclePreparedStatement_getLastError(P->lastError, P->err)); }
//----------------------------------------------------------------------------- // TimestampVar_SetValue() // Set the value of the variable. //----------------------------------------------------------------------------- static int TimestampVar_SetValue( udt_TimestampVar *var, // variable to set value for unsigned pos, // array position to set PyObject *value) // value to set { sword status; uword valid; // make sure a timestamp is being bound if (!PyDateTime_Check(value)) { PyErr_SetString(PyExc_TypeError, "expecting timestamp data"); return -1; } // store a copy of the value status = OCIDateTimeConstruct(var->environment->handle, var->environment->errorHandle, var->data[pos], (sb2) PyDateTime_GET_YEAR(value), PyDateTime_GET_MONTH(value), PyDateTime_GET_DAY(value), PyDateTime_DATE_GET_HOUR(value), PyDateTime_DATE_GET_MINUTE(value), PyDateTime_DATE_GET_SECOND(value), PyDateTime_DATE_GET_MICROSECOND(value) * 1000, NULL, 0); if (Environment_CheckForError(var->environment, status, "TimestampVar_SetValue(): create structure") < 0) return -1; status = OCIDateTimeCheck(var->environment->handle, var->environment->errorHandle, var->data[pos], &valid); if (Environment_CheckForError(var->environment, status, "TimestampVar_SetValue()") < 0) return -1; if (valid != 0) { PyErr_SetString(g_DataErrorException, "invalid date"); return -1; } return 0; }