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;
|
sql_c_type = SQL_C_SLONG;
|
||||||
break;
|
break;
|
||||||
case IS_LONG:
|
case IS_LONG:
|
||||||
//ODBC 64-bit long and integer type are 4 byte values.
|
// When binding any integer, the zend_long value and its length are used as the buffer
|
||||||
if ((Z_LVAL_P(param_z) < INT_MIN) || (Z_LVAL_P(param_z) > INT_MAX)) {
|
// and buffer length. When the buffer is 8 bytes use the corresponding C type for
|
||||||
sql_c_type = SQL_C_SBIGINT;
|
// 8-byte integers
|
||||||
}
|
#ifdef ZEND_ENABLE_ZVAL_LONG64
|
||||||
else {
|
sql_c_type = SQL_C_SBIGINT;
|
||||||
sql_c_type = SQL_C_SLONG;
|
#else
|
||||||
}
|
sql_c_type = SQL_C_SLONG;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case IS_DOUBLE:
|
case IS_DOUBLE:
|
||||||
sql_c_type = SQL_C_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(?)}";
|
$sql_callSP = $set_no_count . "{call $procName(?)}";
|
||||||
|
|
||||||
// Initialize the output parameter to any number
|
// Initialize the output parameter to any positive number
|
||||||
$outParam = 1;
|
$outParam = 1;
|
||||||
$params = array(array(&$outParam, SQLSRV_PARAM_OUT));
|
$params = array(array(&$outParam, SQLSRV_PARAM_OUT));
|
||||||
$stmt = sqlsrv_query($conn, $sql_callSP, $params);
|
$stmt = sqlsrv_query($conn, $sql_callSP, $params);
|
||||||
|
@ -79,6 +79,24 @@ if ($outParam != 123) {
|
||||||
echo "The output param value $outParam is unexpected!\n";
|
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, $tableName1);
|
||||||
dropTable($conn, $tableName2);
|
dropTable($conn, $tableName2);
|
||||||
dropProc($conn, $procName);
|
dropProc($conn, $procName);
|
||||||
|
|
Loading…
Reference in a new issue