-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert long output param to string, then convert back to long if les…
…s than max int
- Loading branch information
1 parent
edac5b2
commit a0e8862
Showing
6 changed files
with
351 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--TEST-- | ||
Test for binding bigint output and inout parameters | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
$conn = connect(); | ||
|
||
// Create the table | ||
$tbname = "bigint_table"; | ||
createTable($conn, $tbname, array("c1_bigint" => "bigint")); | ||
|
||
// Create a Store Procedure | ||
$spname = "selectBigint"; | ||
$spSql = "CREATE PROCEDURE $spname (@c1_bigint bigint OUTPUT) AS | ||
SELECT @c1_bigint = c1_bigint FROM $tbname"; | ||
$conn->query($spSql); | ||
|
||
// Insert a large bigint | ||
insertRow($conn, $tbname, array("c1_bigint" => 922337203685479936)); | ||
|
||
// Call store procedure with output | ||
$outSql = "{CALL $spname (?)}"; | ||
$bigintOut = 0; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $bigintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("Large bigint output:\n" ); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
// Call store procedure with inout | ||
$bigintOut = 0; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $bigintOut, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("Large bigint inout:\n" ); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
$conn->exec("TRUNCATE TABLE $tbname"); | ||
|
||
// Insert a small bigint | ||
insertRow($conn, $tbname, array("c1_bigint" => 922337203)); | ||
|
||
// Call store procedure with output | ||
$bigintOut = 0; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $bigintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("Small bigint output:\n" ); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
// Call store procedure with inout | ||
$bigintOut = 0; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $bigintOut, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("Small bigint inout:\n" ); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
dropProc($conn, $spname); | ||
dropTable($conn, $tbname); | ||
unset($stmt); | ||
unset($conn); | ||
?> | ||
--EXPECT-- | ||
Large bigint output: | ||
string(18) "922337203685479936" | ||
|
||
Large bigint inout: | ||
string(18) "922337203685479936" | ||
|
||
Small bigint output: | ||
int(922337203) | ||
|
||
Small bigint inout: | ||
int(922337203) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--TEST-- | ||
Test for binding boolean output and inout parameters | ||
--SKIPIF-- | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
$conn = connect(); | ||
|
||
// Create the table | ||
$tbname = "bool_table"; | ||
createTable($conn, $tbname, array("c1_bool" => "int")); | ||
|
||
// Create a Store Procedure | ||
$spname = "selectBool"; | ||
$spSql = "CREATE PROCEDURE $spname (@c1_bool int OUTPUT) AS | ||
SELECT @c1_bool = c1_bool FROM $tbname"; | ||
$conn->query($spSql); | ||
|
||
// Insert 1 | ||
insertRow($conn, $tbname, array("c1_bool" => 1)); | ||
|
||
// Call store procedure with output | ||
$outSql = "{CALL $spname (?)}"; | ||
$boolOut = false; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $boolOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("True bool output:\n" ); | ||
var_dump($boolOut); | ||
printf("\n"); | ||
|
||
// Call store procedure with inout | ||
$boolOut = false; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $boolOut, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("True bool inout:\n" ); | ||
var_dump($boolOut); | ||
printf("\n"); | ||
|
||
$conn->exec("TRUNCATE TABLE $tbname"); | ||
|
||
// Insert 0 | ||
insertRow($conn, $tbname, array("c1_bool" => 0)); | ||
|
||
// Call store procedure with output | ||
$boolOut = true; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $boolOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("True bool output:\n" ); | ||
var_dump($boolOut); | ||
printf("\n"); | ||
|
||
// Call store procedure with inout | ||
$boolOut = true; | ||
$stmt = $conn->prepare($outSql); | ||
$stmt->bindParam(1, $boolOut, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); | ||
$stmt->execute(); | ||
printf("True bool inout:\n" ); | ||
var_dump($boolOut); | ||
printf("\n"); | ||
|
||
dropProc($conn, $spname); | ||
dropTable($conn, $tbname); | ||
unset($stmt); | ||
unset($conn); | ||
?> | ||
--EXPECT-- | ||
True bool output: | ||
int(1) | ||
|
||
True bool inout: | ||
int(1) | ||
|
||
True bool output: | ||
int(0) | ||
|
||
True bool inout: | ||
int(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--TEST-- | ||
Test for binding bigint output and inout parameters | ||
--SKIPIF-- | ||
<?php require('skipif_versions_old.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsHelper.inc"); | ||
|
||
$conn = AE\connect(); | ||
|
||
// Create the table | ||
$tbname = "bigint_table"; | ||
AE\createTable($conn, $tbname, array(new AE\ColumnMeta("bigint", "c1_bigint"))); | ||
|
||
|
||
// Create a Store Procedure with output | ||
$spname = "selectBigint"; | ||
$spSql = "CREATE PROCEDURE $spname (@c1_bigint bigint OUTPUT) AS | ||
SELECT @c1_bigint = c1_bigint FROM $tbname"; | ||
sqlsrv_query( $conn, $spSql ); | ||
|
||
// Insert a large bigint | ||
AE\insertRow($conn, $tbname, array("c1_bigint" => 922337203685479936)); | ||
|
||
// Call store procedure with SQLSRV_PARAM_OUT | ||
$outSql = "{CALL $spname (?)}"; | ||
$bigintOut = 0; | ||
$stmt = sqlsrv_prepare($conn, $outSql, array(array(&$bigintOut, SQLSRV_PARAM_OUT))); | ||
sqlsrv_execute($stmt); | ||
printf("Large bigint output:\n"); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
// Call store procedure with SQLSRV_PARAM_INOUT | ||
$bigintOut = 0; | ||
$stmt = sqlsrv_prepare($conn, $outSql, array(array(&$bigintOut, SQLSRV_PARAM_INOUT))); | ||
sqlsrv_execute($stmt); | ||
printf("Large bigint inout:\n"); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
sqlsrv_query($conn, "TRUNCATE TABLE $tbname"); | ||
|
||
// Insert a small bigint | ||
AE\insertRow($conn, $tbname, array("c1_bigint" => 922337203)); | ||
|
||
// Call store procedure with SQLSRV_PARAM_OUT | ||
$bigintOut = 0; | ||
$stmt = sqlsrv_prepare($conn, $outSql, array(array(&$bigintOut, SQLSRV_PARAM_OUT))); | ||
sqlsrv_execute($stmt); | ||
printf("Small bigint output:\n"); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
// Call store procedure with SQLSRV_PARAM_INOUT | ||
$bigintOut = 0; | ||
$stmt = sqlsrv_prepare($conn, $outSql, array(array(&$bigintOut, SQLSRV_PARAM_INOUT))); | ||
sqlsrv_execute($stmt); | ||
printf("Small bigint inout:\n"); | ||
var_dump($bigintOut); | ||
printf("\n"); | ||
|
||
dropProc($conn, $spname); | ||
dropTable($conn, $tbname); | ||
sqlsrv_free_stmt($stmt); | ||
sqlsrv_close($conn); | ||
|
||
?> | ||
--EXPECT-- | ||
Large bigint output: | ||
string(18) "922337203685479936" | ||
|
||
Large bigint inout: | ||
string(18) "922337203685479936" | ||
|
||
Small bigint output: | ||
int(922337203) | ||
|
||
Small bigint inout: | ||
int(922337203) |
Oops, something went wrong.