modified emulate_prepare tests

This commit is contained in:
yitam 2017-05-02 14:05:52 -07:00
parent fb537ab2dd
commit c6be43ad38
6 changed files with 52 additions and 46 deletions

View file

@ -1,13 +1,13 @@
--TEST--
Tests error returned when binding input/output parameter with emulate prepare
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
$database = 'tempdb';
$dsn = "sqlsrv:Server=$serverName ; Database = $database";
require_once("MsSetup.inc");
$dsn = "sqlsrv:Server=$server ; Database = $databaseName";
try {
$dbh = new PDO($dsn, $username, $password);
$dbh = new PDO($dsn, $uid, $pwd);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->query("IF OBJECT_ID('sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE sp_ReverseString");

View file

@ -1,47 +1,47 @@
--TEST--
Tests error returned when binding output parameter with emulate prepare
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require("MsSetup.inc");
$database = "tempdb";
$dsn = "sqlsrv:Server=$serverName ; Database = $database";
$dsn = "sqlsrv:Server=$server ; Database = $databaseName";
try {
$conn = new PDO($dsn, $username, $password);
$conn = new PDO($dsn, $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$count = 0;
$query = "select ? = count(* ) from cd_info";
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam( 1, $count, PDO::PARAM_STR, 10 );
$stmt->execute();
echo "Result: ".$count."\n";
$query = "select bigint_type, int_type, money_type from [test_types] where int_type < 0";
$stmt1 = $conn->prepare($query);
$stmt1->execute();
$row = $stmt1->fetch( PDO::FETCH_ASSOC );
print_r($row);
$query = "select ? = count(* ) from cd_info";
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam( 1, $count, PDO::PARAM_STR, 10 );
$stmt->execute();
echo "Result: ".$count."\n";
$query = "select bigint_type, int_type, money_type from [test_types] where int_type < 0";
$stmt1 = $conn->prepare($query);
$stmt1->execute();
$row = $stmt1->fetch( PDO::FETCH_ASSOC );
print_r($row);
$int = 0;
$bigint = 100;
$query = "select ? = bigint_type, ? = int_type, ? = money_type from [test_types] where int_type < 0";
$stmt2 = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt2->bindparam( 1, $bigint, PDO::PARAM_STR, 256 );
$stmt2->bindParam( 2, $int, PDO::PARAM_INT, 4 );
$stmt2->bindParam( 3, $money, PDO::PARAM_STR, 1024 );
$stmt2->execute();
echo "Big integer: ".$bigint."\n";
echo "Integer: ".$int."\n";
echo "Money: ".$money."\n";
//free the statement and connection
$stmt = null;
$stmt1 = null;
$stmt2 = null;
$conn = null;
$int = 0;
$bigint = 100;
$query = "select ? = bigint_type, ? = int_type, ? = money_type from [test_types] where int_type < 0";
$stmt2 = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt2->bindparam( 1, $bigint, PDO::PARAM_STR, 256 );
$stmt2->bindParam( 2, $int, PDO::PARAM_INT, 4 );
$stmt2->bindParam( 3, $money, PDO::PARAM_STR, 1024 );
$stmt2->execute();
echo "Big integer: ".$bigint."\n";
echo "Integer: ".$int."\n";
echo "Money: ".$money."\n";
//free the statement and connection
$stmt = null;
$stmt1 = null;
$stmt2 = null;
$conn = null;
}
catch(PDOException $e) {

View file

@ -1,17 +1,17 @@
--TEST--
Test emulate prepare utf8 encoding set at the statement level
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$pdo_options = [];
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$pdo_options[PDO::SQLSRV_ATTR_ENCODING] = PDO::SQLSRV_ENCODING_UTF8;
$database = "tempdb";
$connection = new \PDO("sqlsrv:server=$serverName;Database=$database", $username, $password, $pdo_options);
$connection = new PDO("sqlsrv:server=$server;Database=$databaseName", $uid, $pwd, $pdo_options);
$pdo_options = array();
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE;

View file

@ -1,11 +1,12 @@
--TEST--
Test emulate prepare with mix bound param encodings including binary data
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
class MyStatement extends \PDOStatement {
class MyStatement extends PDOStatement {
public function BindValues(array &$values, array &$blobs, $placeholder_prefix, $columnInformation, &$max_placeholder = NULL, $blob_suffix = NULL) {
if (empty($max_placeholder)) {
$max_placeholder = 0;
@ -36,7 +37,7 @@ $connection_options['pdo'] = array();
$connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$database = "tempdb";
$cnn = new PDO("sqlsrv:Server=$serverName;Database=$database", $username, $password, $connection_options['pdo']);
$cnn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd, $connection_options['pdo']);
$cnn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [MyStatement::class]);
// Drop

View file

@ -1,15 +1,16 @@
--TEST--
Test emulate prepare with mix bound param encodings and positional placeholders (i.e., using '?' as placeholders)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$connection_options['pdo'] = array();
$connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$database = "tempdb";
$cnn = new PDO("sqlsrv:Server=$serverName;Database=$database", $username, $password, $connection_options['pdo']);
$databaseName = "tempdb";
$cnn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd, $connection_options['pdo']);
// Drop
try {

View file

@ -31,6 +31,10 @@ def executeSQLscriptUnix(sqlfile, conn_options, dbname):
redirect_string = '(echo :setvar dbname {0}) > {2}; cat {1} >> {2}; '
sqlcmd = 'sqlcmd ' + conn_options + ' -i ' + tmpFileName
print ('display contents of tmpFileName')
show_cmd = 'cat ' + tmpFileName
executeCommmand(show_cmd)
inst_command = redirect_string.format(dbname, sqlfile, tmpFileName) + sqlcmd
executeCommmand(inst_command)
os.remove(tmpFileName)