Binding integers as output parameters with correct C types (#1144)
This commit is contained in:
parent
d4a29fe332
commit
d5e1d8cfbc
|
@ -2079,13 +2079,14 @@ SQLSMALLINT default_c_type( _Inout_ sqlsrv_stmt* stmt, _In_opt_ SQLULEN paramno,
|
|||
sql_c_type = SQL_C_SLONG;
|
||||
break;
|
||||
case IS_LONG:
|
||||
//ODBC 64-bit long and integer type are 4 byte values.
|
||||
if ((Z_LVAL_P(param_z) < INT_MIN) || (Z_LVAL_P(param_z) > INT_MAX)) {
|
||||
sql_c_type = SQL_C_SBIGINT;
|
||||
}
|
||||
else {
|
||||
sql_c_type = SQL_C_SLONG;
|
||||
}
|
||||
// When binding any integer, the zend_long value and its length are used as the buffer
|
||||
// and buffer length. When the buffer is 8 bytes use the corresponding C type for
|
||||
// 8-byte integers
|
||||
#ifdef ZEND_ENABLE_ZVAL_LONG64
|
||||
sql_c_type = SQL_C_SBIGINT;
|
||||
#else
|
||||
sql_c_type = SQL_C_SLONG;
|
||||
#endif
|
||||
break;
|
||||
case IS_DOUBLE:
|
||||
sql_c_type = SQL_C_DOUBLE;
|
||||
|
|
|
@ -65,7 +65,7 @@ if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
|
|||
|
||||
$sql_callSP = $set_no_count . "{call $procName(?)}";
|
||||
|
||||
// Initialize the output parameter to any number
|
||||
// Initialize the output parameter to any positive number
|
||||
$outParam = 1;
|
||||
$params = array(array(&$outParam, SQLSRV_PARAM_OUT));
|
||||
$stmt = sqlsrv_query($conn, $sql_callSP, $params);
|
||||
|
@ -79,6 +79,24 @@ if ($outParam != 123) {
|
|||
echo "The output param value $outParam is unexpected!\n";
|
||||
}
|
||||
|
||||
// Initialize the output parameter to any negative number
|
||||
$outParam = -1;
|
||||
$params = array(array(&$outParam, SQLSRV_PARAM_OUT));
|
||||
$stmt = sqlsrv_prepare($conn, $sql_callSP, $params);
|
||||
if (!$stmt) {
|
||||
fatalError("Error in preparing $procName\n");
|
||||
}
|
||||
$res = sqlsrv_execute($stmt);
|
||||
if (!$res) {
|
||||
fatalError("Error in executing $procName\n");
|
||||
}
|
||||
|
||||
while ($res = sqlsrv_next_result($stmt));
|
||||
|
||||
if ($outParam != 123) {
|
||||
echo "The output param value $outParam is unexpected!\n";
|
||||
}
|
||||
|
||||
dropTable($conn, $tableName1);
|
||||
dropTable($conn, $tableName2);
|
||||
dropProc($conn, $procName);
|
||||
|
|
Loading…
Reference in a new issue