Skip to content

Commit

Permalink
Modified the helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam committed Jul 12, 2019
1 parent 433c53a commit 8041345
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions source/shared/core_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,26 @@ SQLWCHAR* utf16_string_from_mbcs_string( _In_ SQLSRV_ENCODING php_encoding, _In_
return utf16_string;
}

// Converts an input datetime string to a valid zval containing a PHP DateTime object.
// If the input is null, simply returns a NULL zval
// Converts an input (assuming a datetime string) to a zval containing a PHP DateTime object.
// If the input is null, this simply returns a NULL zval. If anything wrong occurs during conversion,
// an exception will be thrown.
void convert_datetime_string_to_zval(_Inout_ sqlsrv_stmt* stmt, _In_opt_ char* input, _In_ SQLLEN length, _Inout_ zval& out_zval)
{
if (input == NULL) {
ZVAL_NULL(&out_zval);
return;
}

zval params[1];
zval value_temp_z;
zval function_z;

// Initialize all zval variables
ZVAL_UNDEF(&out_zval);
ZVAL_UNDEF(&value_temp_z);
ZVAL_UNDEF(&function_z);
ZVAL_UNDEF(params);

if (input == NULL) {
ZVAL_NULL(&out_zval);
return;
}

// Convert the datetime string to a PHP DateTime object
core::sqlsrv_zval_stringl(&value_temp_z, input, length);
core::sqlsrv_zval_stringl(&function_z, "date_create", sizeof("date_create") - 1);
Expand Down
8 changes: 4 additions & 4 deletions source/sqlsrv/stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,11 +1513,11 @@ void convert_to_zval( _Inout_ sqlsrv_stmt* stmt, _In_ SQLSRV_PHPTYPE sqlsrv_php_
Z_TRY_ADDREF( out_zval );
break;
}
case SQLSRV_PHPTYPE_DATETIME:
{
case SQLSRV_PHPTYPE_DATETIME:
{
convert_datetime_string_to_zval(stmt, static_cast<char*>(in_val), field_len, out_zval);
break;
}
break;
}

case SQLSRV_PHPTYPE_NULL:
ZVAL_NULL(&out_zval);
Expand Down

0 comments on commit 8041345

Please sign in to comment.