@@ -523,39 +523,6 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params,
523523 *strLenOrIndPtr = bufferLength;
524524 break ;
525525 }
526- case SQL_C_TYPE_TIMESTAMP: {
527- py::object datetimeType = py::module_::import (" datetime" ).attr (" datetime" );
528- if (!py::isinstance (param, datetimeType)) {
529- ThrowStdException (MakeParamMismatchErrorStr (paramInfo.paramCType , paramIndex));
530- }
531- // Checking if the object has a timezone
532- py::object tzinfo = param.attr (" tzinfo" );
533- if (tzinfo.is_none ()) {
534- ThrowStdException (" Datetime object must have tzinfo for SQL_C_SS_TIMESTAMPOFFSET at paramIndex " + std::to_string (paramIndex));
535- }
536-
537- DateTimeOffset* dtoPtr = AllocateParamBuffer<DateTimeOffset>(paramBuffers);
538-
539- dtoPtr->year = static_cast <SQLSMALLINT>(param.attr (" year" ).cast <int >());
540- dtoPtr->month = static_cast <SQLUSMALLINT>(param.attr (" month" ).cast <int >());
541- dtoPtr->day = static_cast <SQLUSMALLINT>(param.attr (" day" ).cast <int >());
542- dtoPtr->hour = static_cast <SQLUSMALLINT>(param.attr (" hour" ).cast <int >());
543- dtoPtr->minute = static_cast <SQLUSMALLINT>(param.attr (" minute" ).cast <int >());
544- dtoPtr->second = static_cast <SQLUSMALLINT>(param.attr (" second" ).cast <int >());
545- dtoPtr->fraction = static_cast <SQLUINTEGER>(param.attr (" microsecond" ).cast <int >() * 1000 );
546-
547- py::object utcoffset = tzinfo.attr (" utcoffset" )(param);
548- int total_seconds = static_cast <int >(utcoffset.attr (" total_seconds" )().cast <double >());
549- std::div_t div_result = std::div (total_seconds, 3600 );
550- dtoPtr->timezone_hour = static_cast <SQLSMALLINT>(div_result.quot );
551- dtoPtr->timezone_minute = static_cast <SQLSMALLINT>(div (div_result.rem , 60 ).quot );
552-
553- dataPtr = static_cast <void *>(dtoPtr);
554- bufferLength = sizeof (DateTimeOffset);
555- strLenOrIndPtr = AllocateParamBuffer<SQLLEN>(paramBuffers);
556- *strLenOrIndPtr = bufferLength;
557- break ;
558- }
559526 case SQL_C_TYPE_TIMESTAMP: {
560527 py::object datetimeType = py::module_::import (" datetime" ).attr (" datetime" );
561528 if (!py::isinstance (param, datetimeType)) {
@@ -3186,24 +3153,15 @@ SQLRETURN FetchBatchData(SQLHSTMT hStmt, ColumnBuffers& buffers, py::list& colum
31863153 break ;
31873154 }
31883155 case SQL_SS_TIMESTAMPOFFSET: {
3189- // i = current row index in outer loop
31903156 SQLULEN rowIdx = i;
31913157 const DateTimeOffset& dtoValue = buffers.datetimeoffsetBuffers [col - 1 ][rowIdx];
31923158 SQLLEN indicator = buffers.indicators [col - 1 ][rowIdx];
3193-
31943159 if (indicator != SQL_NULL_DATA) {
3195- // Compute total minutes offset
31963160 int totalMinutes = dtoValue.timezone_hour * 60 + dtoValue.timezone_minute ;
3197-
3198- // Import Python datetime module
31993161 py::object datetime = py::module_::import (" datetime" );
3200-
3201- // Construct tzinfo object for the original offset
32023162 py::object tzinfo = datetime.attr (" timezone" )(
32033163 datetime.attr (" timedelta" )(py::arg (" minutes" ) = totalMinutes)
32043164 );
3205-
3206- // Construct Python datetime object with tzinfo
32073165 py::object py_dt = datetime.attr (" datetime" )(
32083166 dtoValue.year ,
32093167 dtoValue.month ,
@@ -3215,7 +3173,6 @@ SQLRETURN FetchBatchData(SQLHSTMT hStmt, ColumnBuffers& buffers, py::list& colum
32153173 tzinfo
32163174 );
32173175 py_dt = py_dt.attr (" astimezone" )(datetime.attr (" timezone" ).attr (" utc" ));
3218- // Append to row
32193176 row.append (py_dt);
32203177 } else {
32213178 row.append (py::none ());
@@ -3342,7 +3299,7 @@ size_t calculateRowSize(py::list& columnNames, SQLUSMALLINT numCols) {
33423299 rowSize += columnSize;
33433300 break ;
33443301 case SQL_SS_TIMESTAMPOFFSET:
3345- rowSize += sizeof (DateTimeOffset); // your custom struct for SQL_C_SS_TIMESTAMPOFFSET
3302+ rowSize += sizeof (DateTimeOffset);
33463303 break ;
33473304 default :
33483305 std::wstring columnName = columnMeta[" ColumnName" ].cast <std::wstring>();
0 commit comments