-
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.
Merge pull request #557 from v-kaywon/refactorPDOTests
Refactor pdo tests
- Loading branch information
Showing
78 changed files
with
5,401 additions
and
3,553 deletions.
There are no files selected for viewing
1,803 changes: 1,803 additions & 0 deletions
1,803
test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,50 +1,54 @@ | ||
--TEST-- | ||
Insert with quoted parameters | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
|
||
// Connect | ||
$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", "$uid", "$pwd" ); | ||
|
||
$param = 'a \' g'; | ||
$param2 = $conn->quote( $param ); | ||
|
||
// Create a temporary table | ||
$tableName = '#tmpTable'; | ||
$query = "CREATE TABLE $tableName (col1 VARCHAR(10), col2 VARCHAR(20))"; | ||
$stmt = $conn->exec($query); | ||
if( $stmt === false ) { die(); } | ||
|
||
// Inserd data | ||
$query = "INSERT INTO $tableName VALUES( ?, '1' )"; | ||
$stmt = $conn->prepare( $query ); | ||
$stmt->execute(array($param)); | ||
|
||
// Inserd data | ||
$query = "INSERT INTO $tableName VALUES( ?, ? )"; | ||
$stmt = $conn->prepare( $query ); | ||
$stmt->execute(array($param, $param2)); | ||
|
||
// Query | ||
$query = "SELECT * FROM $tableName"; | ||
$stmt = $conn->query($query); | ||
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){ | ||
print_r( $row['col1'] ." was inserted\n" ); | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
try { | ||
// Connect | ||
$conn = connect(); | ||
|
||
$param = 'a \' g'; | ||
$param2 = $conn->quote($param); | ||
|
||
// Create a temporary table | ||
$tableName = getTableName(); | ||
$stmt = createTable($conn, $tableName, array("col1" => "varchar(10)", "col2" => "varchar(20)")); | ||
|
||
// Insert data | ||
if (!isColEncrypted()) { | ||
$query = "INSERT INTO $tableName VALUES(?, '1')"; | ||
$stmt = $conn->prepare($query); | ||
$stmt->execute(array($param)); | ||
} else { | ||
insertRow($conn, $tableName, array("col1" => $param, "col2" => "1"), "prepareExecuteBind"); | ||
} | ||
|
||
// Insert data | ||
insertRow($conn, $tableName, array("col1" => $param, "col2" => $param2), "prepareExecuteBind"); | ||
|
||
// Query | ||
$query = "SELECT * FROM $tableName"; | ||
$stmt = $conn->query($query); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
print_r($row['col1'] ." was inserted\n"); | ||
} | ||
|
||
// Revert the inserts | ||
$query = "delete from $tableName where col1 = ?"; | ||
$stmt = $conn->prepare($query); | ||
$stmt->execute(array($param)); | ||
|
||
//free the statement and connection | ||
dropTable($conn, $tableName); | ||
unset($stmt); | ||
unset($conn); | ||
} catch (PDOException $e) { | ||
var_dump($e->errorInfo); | ||
} | ||
|
||
// Revert the inserts | ||
$query = "delete from $tableName where col1 = ?"; | ||
$stmt = $conn->prepare( $query ); | ||
$stmt->execute(array($param)); | ||
|
||
//free the statement and connection | ||
$stmt=null; | ||
$conn=null; | ||
?> | ||
--EXPECT-- | ||
a ' g was inserted | ||
a ' g was inserted | ||
|
||
a ' g was inserted |
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 |
---|---|---|
@@ -1,24 +1,28 @@ | ||
--TEST-- | ||
uses an input/output parameter | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
<?php require('skipif_mid-refactor.inc'); ?> | ||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
require_once("MsCommon_mid-refactor.inc"); | ||
|
||
$dbh = new PDO( "sqlsrv:server=$server; database=$databaseName", "$uid", "$pwd" ); | ||
try { | ||
$dbh = connect(); | ||
|
||
$dbh->query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString"); | ||
$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)"); | ||
$stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?"); | ||
$string = "123456789"; | ||
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048); | ||
$stmt->execute(); | ||
print "Result: ".$string."\n"; // Expect 987654321 | ||
dropProc($dbh, "sp_ReverseString"); | ||
$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)"); | ||
$stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?"); | ||
$string = "123456789"; | ||
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048); | ||
$stmt->execute(); | ||
print "Result: ".$string."\n"; // Expect 987654321 | ||
|
||
//free the statement and connection | ||
$stmt = null; | ||
$dbh = null; | ||
//free the statement and connection | ||
unset($stmt); | ||
unset($conn); | ||
} catch (PDOException $e) { | ||
var_dump($e->errorInfo); | ||
} | ||
?> | ||
--EXPECT-- | ||
Result: 987654321 |
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
Oops, something went wrong.