Added more tests to the pile

This commit is contained in:
Jenny Tam 2017-11-29 14:40:47 -08:00
parent 0a2e6ad242
commit 489d3e8018
13 changed files with 379 additions and 389 deletions

View file

@ -5,119 +5,118 @@ make sure errors are cleared for each new API call
invalid parameters are reported via sqlsrv_errors, and
sqlsrv_close returns true even if an error happens.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
require('MsCommon.inc');
$conn = sqlsrv_connect( "InvalidServerName", array( "Database" => "test" ));
$conn = sqlsrv_connect("InvalidServerName", array( "Database" => "test" ));
$result = sqlsrv_close($conn);
$errors = sqlsrv_errors();
if( $result !== false ) {
die( "sqlsrv_close succeeded despite an invalid server name." );
if ($result !== false) {
die("sqlsrv_close succeeded despite an invalid server name.");
}
print_r( $errors );
print_r($errors);
$conn = Connect();
if( !$conn ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_create failed." );
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params" );
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_prepare( $conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))" );
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
$f1 = 1;
$f2 = "testtestte";
$f3 = 12.0;
$f4 = fopen( "data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r" );
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$stmt = sqlsrv_prepare( $conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
if( !$stmt ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_prepare failed." );
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
if (!$stmt) {
var_dump(sqlsrv_errors());
die("sqlsrv_prepare failed.");
}
$success = sqlsrv_execute( $stmt );
if( !$success ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_execute failed." );
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
die("sqlsrv_execute failed.");
}
while( $success = sqlsrv_send_stream_data( $stmt )) {
while ($success = sqlsrv_send_stream_data($stmt)) {
}
if( !is_null( $success )) {
sqlsrv_cancel( $stmt );
sqlsrv_free_stmt( $stmt );
die( "sqlsrv_send_stream_data failed." );
if (!is_null($success)) {
sqlsrv_cancel($stmt);
sqlsrv_free_stmt($stmt);
die("sqlsrv_send_stream_data failed.");
}
$f1 = 2;
$f3 = 13.0;
$f4 = fopen( "data://text/plain,This%20is%20some%20more%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r" );
$success = sqlsrv_execute( $stmt );
if( !$success ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_execute failed." );
$f4 = fopen("data://text/plain,This%20is%20some%20more%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
die("sqlsrv_execute failed.");
}
while( $success = sqlsrv_send_stream_data( $stmt )) {
while ($success = sqlsrv_send_stream_data($stmt)) {
}
if( !is_null( $success )) {
sqlsrv_cancel( $stmt );
sqlsrv_free_stmt( $stmt );
die( "sqlsrv_send_stream_data failed." );
if (!is_null($success)) {
sqlsrv_cancel($stmt);
sqlsrv_free_stmt($stmt);
die("sqlsrv_send_stream_data failed.");
}
$result = sqlsrv_free_stmt( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$result = sqlsrv_free_stmt($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_free_stmt( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$result = sqlsrv_free_stmt($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_free_stmt( null );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$result = sqlsrv_free_stmt(null);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_free_stmt( $conn );
if( $result !== false ) {
die( "sqlsrv_free_stmt shouldn't have freed the connection resource" );
$result = sqlsrv_free_stmt($conn);
if ($result !== false) {
die("sqlsrv_free_stmt shouldn't have freed the connection resource");
}
print_r( sqlsrv_errors() );
$result = sqlsrv_free_stmt( 1 );
if( $result !== false ) {
die( "sqlsrv_free_stmt shouldn't have freed a 1" );
print_r(sqlsrv_errors());
$result = sqlsrv_free_stmt(1);
if ($result !== false) {
die("sqlsrv_free_stmt shouldn't have freed a 1");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
sqlsrv_query( $conn, "DROP TABLE test_params" );
dropTable($conn, $tableName);
$result = sqlsrv_close( $conn );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$result = sqlsrv_close($conn);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_close( $conn );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$result = sqlsrv_close($conn);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_close( null );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$result = sqlsrv_close(null);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_close( 1 );
if( $result !== false ) {
die( "sqlsrv_close shouldn't have freed a 1" );
$result = sqlsrv_close(1);
if ($result !== false) {
die("sqlsrv_close shouldn't have freed a 1");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
echo "Test successful.\n";
echo "Test successfully done.\n";
?>
--EXPECTF--
Warning: sqlsrv_close() expects parameter 1 to be resource, boolean given in %Ssqlsrv_errors.php on line %x
@ -187,4 +186,4 @@ Array
)
)
Test successful.
Test successfully done.

View file

@ -1,14 +1,20 @@
--TEST--
Test transactions commit, rollback and aborting in between
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ComplexTransaction($conn, $conn2)
function complexTransaction($conn, $conn2)
{
$tableName = GetTempTableName('testTransaction', false);
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_real] real)");
$tableName = 'testTransaction';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('real', 'c2_real'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
sqlsrv_free_stmt($stmt);
$stmtSelect = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
@ -16,8 +22,8 @@ function ComplexTransaction($conn, $conn2)
// insert ten rows
$numRows = 10;
InsertData($conn, $tableName, $numRows);
FetchData($stmtSelect, $tableName, $numRows);
insertData($conn, $tableName, $numRows);
fetchData($stmtSelect, $tableName, $numRows);
sqlsrv_begin_transaction($conn);
sqlsrv_execute($stmtDelete);
@ -26,14 +32,14 @@ function ComplexTransaction($conn, $conn2)
echo "Committed deleting 3 rows\n";
$numRows = $numRows - $rowsAffected;
FetchData($stmtSelect, $tableName, $numRows);
fetchData($stmtSelect, $tableName, $numRows);
sqlsrv_begin_transaction($conn);
sqlsrv_execute($stmtDelete);
sqlsrv_rollback($conn);
echo "Rolled back\n";
FetchData($stmtSelect, $tableName, $numRows);
fetchData($stmtSelect, $tableName, $numRows);
sqlsrv_begin_transaction($conn);
sqlsrv_execute($stmtDelete);
@ -42,14 +48,14 @@ function ComplexTransaction($conn, $conn2)
echo "Committed deleting 3 rows\n";
$numRows = $numRows - $rowsAffected;
FetchData($stmtSelect, $tableName, $numRows);
fetchData($stmtSelect, $tableName, $numRows);
sqlsrv_begin_transaction($conn);
sqlsrv_execute($stmtDelete);
sqlsrv_rollback($conn);
echo "Rolled back\n";
FetchData($stmtSelect, $tableName, $numRows);
fetchData($stmtSelect, $tableName, $numRows);
sqlsrv_begin_transaction($conn);
sqlsrv_execute($stmtDelete);
@ -59,12 +65,12 @@ function ComplexTransaction($conn, $conn2)
// select table using the second connection
$stmt = sqlsrv_prepare($conn2, "SELECT * FROM $tableName");
FetchData($stmt, $tableName, $numRows);
fetchData($stmt, $tableName, $numRows);
sqlsrv_query($conn2, "DROP TABLE $tableName");
dropTable($conn2, $tableName);
}
function InsertData($conn, $tableName, $count)
function insertData($conn, $tableName, $count)
{
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_real) VALUES (?, ?)", array(&$v1, &$v2));
@ -76,7 +82,7 @@ function InsertData($conn, $tableName, $count)
}
}
function FetchData($stmt, $tableName, $numRows)
function fetchData($stmt, $tableName, $numRows)
{
$numFetched = 0;
sqlsrv_execute($stmt);
@ -90,41 +96,23 @@ function FetchData($stmt, $tableName, $numRows)
}
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_fetch_complex_transactions");
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
echo "\nTest begins...\n";
// Connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// Connect
$conn = AE\connect();
$conn2 = AE\connect();
$conn2 = connect();
if (!$conn2) {
fatalError("Could not connect.\n");
}
complexTransaction($conn, $conn2);
ComplexTransaction($conn, $conn2);
sqlsrv_close($conn2); // $conn should have been closed
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_fetch_complex_transactions");
sqlsrv_close($conn2); // $conn should have been closed
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "\nDone\n";
?>
--EXPECT--
@ -143,4 +131,3 @@ Deletion aborted
Number of rows fetched: 4
Done
Test "sqlsrv_fetch_complex_transactions" completed successfully.

View file

@ -1,7 +1,7 @@
--TEST--
sqlsrv_num_fields and output params without sqlsrv_next_result.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -9,10 +9,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Failed to connect.");
}
$conn = AE\connect();
// test num_fields on a statement that doesn't generate a result set.
$stmt = sqlsrv_prepare($conn, "USE 'tempdb'");
@ -24,12 +21,17 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
echo "$field_count\n";
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare( $conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params" );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
// test sqlsrv_num_fields immediately after a prepare
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))");
// test sqlsrv_num_fields immediately after creating a table
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$field_count = sqlsrv_num_fields($stmt);
if ($field_count === false) {
die(print_r(sqlsrv_errors(), true));
@ -43,7 +45,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
$f3 = 12.0;
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
if (!$stmt) {
fatalError("sqlsrv_prepare failed.");
}
@ -63,7 +65,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
sqlsrv_free_stmt($stmt);
// test num_fields on a valid statement that produces a result set.
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM test_params");
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
@ -91,7 +93,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
// this should return 3, but shorthand output parameters are disabled for now.
echo "$v3\n";
dropTable($conn, 'test_params');
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -1,25 +1,26 @@
--TEST--
Test insertion with floats
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ExecData($withParams)
function execData($withParams)
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
$conn = AE\connect();
$tableName = 'param_floats';
$columns = array(new AE\ColumnMeta('float', 'c1_float'),
new AE\ColumnMeta('real', 'c2_real'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_float] float, [c2_real] real)");
sqlsrv_free_stmt($stmt);
if ($withParams) {
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_float, c2_real) VALUES (?, ?)", array(array(&$v1, SQLSRV_PARAM_IN), array(&$v2, SQLSRV_PARAM_IN)));
} else {
@ -77,25 +78,20 @@ function ExecData($withParams)
}
}
sqlsrv_free_stmt($stmt);
dropTable($conn, $tableName);
sqlsrv_close($conn);
}
function Repro()
{
startTest("sqlsrv_statement_exec_param_floats");
echo "\nTest begins...\n";
echo "\nTest begins...\n";
try {
ExecData(true);
ExecData(false);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_statement_exec_param_floats");
try {
execData(true);
execData(false);
} catch (Exception $e) {
echo $e->getMessage();
}
Repro();
echo "\nDone\n";
?>
--EXPECT--
@ -103,4 +99,3 @@ Repro();
Test begins...
Done
Test "sqlsrv_statement_exec_param_floats" completed successfully.

View file

@ -4,13 +4,15 @@ Test insert various numeric data types and fetch them back as strings
<?php
require_once('MsCommon.inc');
function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
function execDataValue($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_int] int, [c2_smallint] smallint)");
sqlsrv_free_stmt($stmt);
$tableName = 'param_query_value';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('smallint', 'c2_smallint'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("failed to create table $tableName\n");
}
if ($phpType == SQLSRV_PHPTYPE_NULL) {
echo "Insert integers without PHP type\n";
$stmt = sqlsrv_prepare($conn, "INSERT INTO [$tableName] (c1_int, c2_smallint) VALUES (?, ?)", array(array(&$v1), array(&$v2)));
@ -18,12 +20,18 @@ function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
echo "Insert integers as SQLSRV_PHPTYPE_INT\n";
$stmt = sqlsrv_prepare($conn, "INSERT INTO [$tableName] (c1_int, c2_smallint) VALUES (?, ?)", array(array(&$v1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT), array(&$v2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT)));
}
if (!$stmt) {
fatalError("execDataValue: failed to prepare statement!");
}
$value = 1;
for ($i = 0; $i < $numRows; $i++) {
$v1 = $value;
$v2 = $v1 + 1;
sqlsrv_execute($stmt);
$res = sqlsrv_execute($stmt);
if (!$res) {
fatalError("execDataValue: failed to insert $v1, $v2");
}
$value += 10;
}
@ -31,17 +39,22 @@ function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
FetchData($stmt, $numRows);
fetchData($stmt, $numRows);
sqlsrv_free_stmt($stmt);
dropTable($conn, $tableName);
}
function ExecData_Param($conn, $numRows, $withParam = false)
function execDataParam($conn, $numRows, $withParam = false)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_float] float, [c2_real] real)");
sqlsrv_free_stmt($stmt);
$tableName = 'param_query_param';
$columns = array(new AE\ColumnMeta('float', 'c1_float'),
new AE\ColumnMeta('real', 'c2_real'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("failed to create table $tableName\n");
}
if ($withParam) {
echo "Insert floats with direction specified\n";
@ -50,12 +63,18 @@ function ExecData_Param($conn, $numRows, $withParam = false)
echo "Insert floats without direction\n";
$stmt = sqlsrv_prepare($conn, "INSERT INTO [$tableName] (c1_float, c2_real) VALUES (?, ?)", array(&$v1, &$v2));
}
if (!$stmt) {
fatalError("execDataParam: failed to prepare statement!");
}
$value = 1.0;
for ($i = 0; $i < $numRows; $i++) {
$v1 = $value;
$v2 = $v1 + 1.0;
sqlsrv_execute($stmt);
$res = sqlsrv_execute($stmt);
if (!$res) {
fatalError("execDataParam: failed to insert $v1, $v2");
}
$value += 10;
}
@ -63,12 +82,14 @@ function ExecData_Param($conn, $numRows, $withParam = false)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
FetchData($stmt, $numRows);
fetchData($stmt, $numRows);
sqlsrv_free_stmt($stmt);
dropTable($conn, $tableName);
}
function FetchData($stmt, $numRows)
function fetchData($stmt, $numRows)
{
for ($i = 0; $i < $numRows; $i++) {
sqlsrv_fetch($stmt);
@ -81,36 +102,26 @@ function FetchData($stmt, $numRows)
}
}
function Repro()
{
startTest("sqlsrv_param_query_array_inputs");
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// connect
$conn = AE\connect();
$numRows = 5;
$numRows = 5;
ExecData_Value($conn, $numRows);
ExecData_Value($conn, $numRows, SQLSRV_PHPTYPE_INT);
ExecData_Param($conn, $numRows, true);
ExecData_Param($conn, $numRows);
execDataValue($conn, $numRows);
execDataValue($conn, $numRows, SQLSRV_PHPTYPE_INT);
execDataParam($conn, $numRows, true);
execDataParam($conn, $numRows);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_param_query_array_inputs");
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
Repro();
echo "\nDone\n";
?>
--EXPECT--
@ -142,4 +153,3 @@ Insert floats without direction
41.0, 42.0
Done
Test "sqlsrv_param_query_array_inputs" completed successfully.

View file

@ -1,22 +1,22 @@
--TEST--
binding parameters, including output parameters, using the simplified syntax.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Failed to connect.");
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_prepare($conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params");
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))");
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$f1 = 1;
@ -24,7 +24,7 @@ binding parameters, including output parameters, using the simplified syntax.
$f3 = 12.0;
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
if (!$stmt) {
var_dump(sqlsrv_errors());
die("sqlsrv_prepare failed.");
@ -61,7 +61,7 @@ binding parameters, including output parameters, using the simplified syntax.
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM test_params");
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
@ -116,7 +116,7 @@ binding parameters, including output parameters, using the simplified syntax.
// this should return 4, but shorthand output parameters are disabled for now.
echo "$v3\n";
sqlsrv_query($conn, "DROP TABLE test_params");
sqlsrv_query($conn, "DROP TABLE $tableName");
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -1,7 +1,7 @@
--TEST--
sqlsrv_stmt_rows_affected.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -10,34 +10,22 @@ sqlsrv_stmt_rows_affected.
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Failed to connect.");
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(4000)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_prepare($conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params");
$result = sqlsrv_execute($stmt);
if (!$result) {
$errors = sqlsrv_errors();
if ($errors[0]["SQLSTATE"] != "42S02") {
var_dump($errors);
die("sqlsrv_execute(2) failed.");
}
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(4000))");
$result = sqlsrv_execute($stmt);
if (!$result) {
fatalError("sqlsrv_execute(3) failed.");
}
sqlsrv_free_stmt($stmt);
$f1 = 1;
$f2 = "testtestte";
$f3 = 12.0;
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, &$f2, &$f3, &$f4 ));
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, &$f2, &$f3, &$f4 ));
if (!$stmt) {
fatalError("sqlsrv_prepare(4) failed.");
}
@ -65,7 +53,11 @@ sqlsrv_stmt_rows_affected.
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "UPDATE test_params SET [double] = 13.0 FROM test_params WHERE [double] = 12.0");
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, "UPDATE $tableName SET [double] = ? FROM $tableName WHERE [double] = ?", array(13.0, 12.0));
} else {
$stmt = sqlsrv_prepare($conn, "UPDATE $tableName SET [double] = 13.0 FROM $tableName WHERE [double] = 12.0");
}
if (!$stmt) {
fatalError("sqlsrv_prepare(2) failed.");
}
@ -82,7 +74,7 @@ sqlsrv_stmt_rows_affected.
}
echo "rows = $row_count<br/>\n";
sqlsrv_query($conn, "DROP TABLE test_params");
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -2,6 +2,8 @@
Test simple insert and update sql_variants using parameters of some different data types
--DESCRIPTION--
ORDER BY should work with sql_variants
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
@ -22,20 +24,25 @@ class Country
}
}
function CreateVariantTable($conn, $tableName)
function createVariantTable($conn, $tableName)
{
// create a table for testing
$dataType = "[id] sql_variant, [country] sql_variant, [continent] sql_variant";
createTableEx($conn, $tableName, $dataType);
$columns = array(new AE\ColumnMeta('sql_variant', 'id'),
new AE\ColumnMeta('sql_variant', 'country'),
new AE\ColumnMeta('sql_variant', 'continent'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
}
function AddCountry($conn, $tableName, $id, $country, $continent)
function addCountry($conn, $tableName, $id, $country, $continent)
{
$query = "INSERT $tableName ([id], [country], [continent]) VALUES (?, ?, ?)";
// set parameters
$params = array($id, $country, $continent);
$stmt = sqlsrv_query($conn, $query, $params);
$stmt = AE\executeQueryParams($conn, $query, $params);
if ($stmt) {
echo "\nAdded $country in $continent with ID $id.";
@ -44,7 +51,7 @@ function AddCountry($conn, $tableName, $id, $country, $continent)
}
}
function UpdateID($conn, $tableName, $id, $country, $continent)
function updateID($conn, $tableName, $id, $country, $continent)
{
$query = "UPDATE $tableName SET id = ? WHERE country = ? AND continent = ?";
$param1 = $id;
@ -63,7 +70,7 @@ function UpdateID($conn, $tableName, $id, $country, $continent)
}
}
function UpdateCountry($conn, $tableName, $id, $country, $continent)
function updateCountry($conn, $tableName, $id, $country, $continent)
{
$query = "UPDATE $tableName SET country = ? WHERE id = ? AND continent = ?";
$param1 = $country;
@ -82,7 +89,7 @@ function UpdateCountry($conn, $tableName, $id, $country, $continent)
}
}
function Fetch($conn, $tableName)
function fetch($conn, $tableName)
{
$select = "SELECT * FROM $tableName ORDER BY id";
$stmt = sqlsrv_query($conn, $select);
@ -96,59 +103,50 @@ function Fetch($conn, $tableName)
sqlsrv_free_stmt($stmt);
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_simple_update_variants");
try {
setup();
try {
setup();
// connect
$conn = connect();
// connect
$conn = AE\connect();
// Create a temp table that will be automatically dropped once the connection is closed
$tableName = GetTempTableName();
CreateVariantTable($conn, $tableName);
// Create a temp table that will be automatically dropped once the connection is closed
$tableName = 'simple_update_variants';
createVariantTable($conn, $tableName);
// Add three countries
AddCountry($conn, $tableName, 1, 'Canada', 'North America');
AddCountry($conn, $tableName, 3, 'France', 'Europe');
AddCountry($conn, $tableName, 5, 'Australia', 'Australia');
// Add three countries
addCountry($conn, $tableName, 1, 'Canada', 'North America');
addCountry($conn, $tableName, 3, 'France', 'Europe');
addCountry($conn, $tableName, 5, 'Australia', 'Australia');
// Read data
Fetch($conn, $tableName);
// Read data
fetch($conn, $tableName);
// Update id
UpdateID($conn, $tableName, 4, 'Canada', 'North America');
// Update id
updateID($conn, $tableName, 4, 'Canada', 'North America');
// Read data
Fetch($conn, $tableName);
// Read data
fetch($conn, $tableName);
// Update country
UpdateCountry($conn, $tableName, 4, 'Mexico', 'North America');
// Update country
updateCountry($conn, $tableName, 4, 'Mexico', 'North America');
// Read data
Fetch($conn, $tableName);
// Read data
fetch($conn, $tableName);
// Add two more countries
AddCountry($conn, $tableName, 6, 'Brazil', 'South America');
AddCountry($conn, $tableName, 2, 'Egypt', 'Africa');
// Add two more countries
addCountry($conn, $tableName, 6, 'Brazil', 'South America');
addCountry($conn, $tableName, 2, 'Egypt', 'Africa');
// Read data
Fetch($conn, $tableName);
// Read data
fetch($conn, $tableName);
dropTable($conn, $tableName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_simple_update_variants");
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "\nDone\n";
?>
--EXPECT--
@ -175,4 +173,3 @@ ID: 4 Mexico, North America
ID: 5 Australia, Australia
ID: 6 Brazil, South America
Done
Test "sqlsrv_simple_update_variants" completed successfully.

View file

@ -1,21 +1,21 @@
--TEST--
Test stored procedure that returns a varchar
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function StoredProc_varchar()
function storedProcVarchar()
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
$conn = AE\connect();
$procName = GetTempProcName();
$procName = 'sp_varchar';
dropProc($conn, $procName);
$tsql = "CREATE PROC $procName (@p1 VARCHAR(37) OUTPUT, @p2 VARCHAR(21), @p3 VARCHAR(14))
AS
@ -42,23 +42,18 @@ function StoredProc_varchar()
sqlsrv_execute($stmt);
echo("$retValue\n");
sqlsrv_free_stmt($stmt);
dropProc($conn, $procName);
sqlsrv_close($conn);
}
function Repro()
{
startTest("sqlsrv_stored_proc_varchar");
echo "\nTest begins...\n";
try {
StoredProc_varchar();
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_stored_proc_varchar");
echo "\nTest begins...\n";
try {
storedProcVarchar();
} catch (Exception $e) {
echo $e->getMessage();
}
Repro();
echo "\nDone\n";
?>
--EXPECT--
@ -71,4 +66,3 @@ Microsoft SQL Server Driver for PHP
Microsoft SQL Server Driver for PHP
Done
Test "sqlsrv_stored_proc_varchar" completed successfully.

View file

@ -13,15 +13,11 @@ require_once("MsCommon.inc");
// connect
$conn = AE\connect();
if (!$conn) {
fatalError("Connection could not be established.\n");
}
$tableName = 'testLOBTypes_GH231';
$tableName = 'testLOBTypes_GH231_lob';
$columnNames = array("c1", "c2");
for ($k = 1; $k <= 3; $k++) {
$sqlType = sqlType($k);
$sqlType = getFieldType($k);
$columns = array(new AE\ColumnMeta('int', $columnNames[0]),
new AE\ColumnMeta($sqlType, $columnNames[1]));
AE\createTable($conn, $tableName, $columns);
@ -95,7 +91,7 @@ function getData($k)
return $data;
}
function sqlType($k)
function getFieldType($k)
{
switch ($k) {
case 1: return ("text");

View file

@ -1,6 +1,7 @@
--TEST--
GitHub issue #231 - String truncation when binding varchar(max)
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
@ -9,93 +10,104 @@ sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("MsCommon.inc");
// connect
$conn = connect();
if (!$conn) {
printErrors("Connection could not be established.\n");
}
$tableName = GetTempTableName('testDataTypes_GH231');
$columnNames = array( "c1","c2" );
$conn = AE\connect();
$tableName = 'testDataTypes_GH231_VC';
$columnNames = array("c1", "c2");
for ($k = 1; $k <= 8; $k++) {
$sqlType = SqlType($k);
$dataType = "[$columnNames[0]] int, [$columnNames[1]] $sqlType";
$sqlType = getFieldType($k);
$columns = array(new AE\ColumnMeta('int', $columnNames[0]),
new AE\ColumnMeta($sqlType, $columnNames[1]));
AE\createTable($conn, $tableName, $columns);
$sql = "CREATE TABLE [$tableName] ($dataType)";
$stmt1 = sqlsrv_query($conn, $sql);
sqlsrv_free_stmt($stmt1);
// $sql = "CREATE TABLE [$tableName] ($dataType)";
// $stmt1 = sqlsrv_query($conn, $sql);
// sqlsrv_free_stmt($stmt1);
$sql = "INSERT INTO [$tableName] ($columnNames[0], $columnNames[1]) VALUES (?, ?)";
$data = GetData($k);
$phpType = PhpType($k);
$driverType = DriverType($k, strlen($data));
$data = getData($k);
$phpType = getPhpType($k);
$len = AE\isColEncrypted() ? 512 : strlen($data);
$sqlsrvType = getSQLSRVType($k, $len);
$params = array($k, array($data, SQLSRV_PARAM_IN, $phpType, $driverType));
$stmt2 = sqlsrv_prepare($conn, $sql, $params);
sqlsrv_execute($stmt2);
sqlsrv_free_stmt($stmt2);
$params = array($k, array($data, SQLSRV_PARAM_IN, $phpType, $sqlsrvType));
$stmt = sqlsrv_prepare($conn, $sql, $params);
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType);
execProc($conn, $tableName, $columnNames, $k, $data, $sqlType);
$stmt3 = sqlsrv_query($conn, "DROP TABLE [$tableName]");
sqlsrv_free_stmt($stmt3);
dropTable($conn, $tableName);
}
sqlsrv_close($conn);
function ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
function execProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
{
$spArgs = "@p1 int, @p2 $sqlType OUTPUT";
$spCode = "SET @p2 = ( SELECT c2 FROM $tableName WHERE c1 = @p1 )";
$procName = "testBindOutSp";
dropProc($conn, $procName);
$stmt1 = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
sqlsrv_free_stmt($stmt1);
if (!$stmt1) {
fatalError("Failed to create stored procedure $procName");
} else {
sqlsrv_free_stmt($stmt1);
}
echo "\nData Type: ".$sqlType." binding as \n";
$direction = SQLSRV_PARAM_OUT;
echo "Output parameter: \t";
InvokeProc($conn, $procName, $k, $direction, $data);
invokeProc($conn, $procName, $k, $direction, $data);
$direction = SQLSRV_PARAM_INOUT;
echo "InOut parameter: \t";
InvokeProc($conn, $procName, $k, $direction, $data);
invokeProc($conn, $procName, $k, $direction, $data);
$stmt2 = sqlsrv_query($conn, "DROP PROC [$procName]");
sqlsrv_free_stmt($stmt2);
dropProc($conn, $procName);
}
function InvokeProc($conn, $procName, $k, $direction, $data)
function invokeProc($conn, $procName, $k, $direction, $data)
{
$driverType = DriverType($k, strlen($data));
$len = AE\isColEncrypted() ? 512 : strlen($data);
$sqlsrvType = getSQLSRVType($k, $len);
$callArgs = "?, ?";
// Data to initialize $callResult variable. This variable should be shorter than inserted data in the table
// Data to initialize $callResult variable. This variable
// should be shorter than inserted data in the table
$initData = "ShortString";
$callResult = $initData;
// Make sure not to specify the PHP type
$params = array( array( $k, SQLSRV_PARAM_IN ),
array( &$callResult, $direction, null, $driverType ));
$stmt = sqlsrv_query($conn, "{ CALL [$procName] ($callArgs)}", $params);
array( &$callResult, $direction, null, $sqlsrvType ));
$stmt = AE\executeQueryParams($conn, "{ CALL [$procName] ($callArgs)}", $params);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
// $callResult should be updated to the value in the table
$matched = ($callResult === $data);
if (AE\isColEncrypted()) {
// with AE enabled, char/nchar fields have size up to 512
$matched = (trim($callResult) === $data);
} else {
$matched = ($callResult === $data);
}
if ($matched) {
echo "data matched!\n";
} else {
echo "failed!\n";
echo "failed! $callResult vs $data\n";
}
sqlsrv_free_stmt($stmt);
}
function GetData($k)
function getData($k)
{
$data = "LongStringForTesting";
if ($k == 8) {
@ -105,7 +117,7 @@ function GetData($k)
return $data;
}
function PhpType($k)
function getPhpType($k)
{
$phpType = SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR);
if ($k == 7) {
@ -115,7 +127,7 @@ function PhpType($k)
return $phpType;
}
function SqlType($k)
function getFieldType($k)
{
switch ($k) {
case 1: return ("char(512)");
@ -131,7 +143,7 @@ function SqlType($k)
return ("udt");
}
function DriverType($k, $dataSize)
function getSQLSRVType($k, $dataSize)
{
switch ($k) {
case 1: return (SQLSRV_SQLTYPE_CHAR($dataSize));

View file

@ -1,33 +1,41 @@
--TEST--
Send an empty stream and null stream test.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', false);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once("MsCommon.inc");
$conn = connect();
if (!$conn) {
fatalError("sqlsrv_connect failed.");
$conn = AE\connect();
// if (!$conn) {
// fatalError("sqlsrv_connect failed.");
// }
$tableName = 'test_empty_stream';
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('varchar(max)', 'varchar_stream'),
new AE\ColumnMeta('varbinary(max)', 'varbinary_stream'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_empty_stream', 'U') IS NOT NULL DROP TABLE test_empty_stream");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
// $stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_empty_stream', 'U') IS NOT NULL DROP TABLE test_empty_stream");
// if ($stmt !== false) {
// sqlsrv_free_stmt($stmt);
// }
$stmt = sqlsrv_query($conn, "CREATE TABLE test_empty_stream (id int, varchar_stream varchar(max), varbinary_stream varbinary(max))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
// $stmt = sqlsrv_query($conn, "CREATE TABLE $tableName (id int, varchar_stream varchar(max), varbinary_stream varbinary(max))");
// if ($stmt === false) {
// die(print_r(sqlsrv_errors(), true));
// }
$f1 = 1;
$f2 = fopen("data://text/plain,", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_empty_stream (id, varchar_stream) VALUES (?, ?)", array( &$f1, &$f2 ));
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, varchar_stream) VALUES (?, ?)", array( &$f1, &$f2 ));
if ($stmt === false) {
print_r("sqlsrv_prepare failed.");
die(print_r(sqlsrv_errors(), true));
@ -50,7 +58,7 @@ Send an empty stream and null stream test.
$f4 = fopen("data://text/plain,", "r");
$stmt = sqlsrv_prepare(
$conn,
"INSERT INTO test_empty_stream (id, varbinary_stream) VALUES (?, ?)",
"INSERT INTO $tableName (id, varbinary_stream) VALUES (?, ?)",
array( &$f3,
array( &$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')) )
);
@ -72,7 +80,7 @@ Send an empty stream and null stream test.
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query($conn, "SELECT id, varchar_stream, varbinary_stream FROM test_empty_stream");
$stmt = AE\executeQuery($conn, "SELECT id, varchar_stream, varbinary_stream FROM $tableName");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
@ -127,7 +135,7 @@ Send an empty stream and null stream test.
}
print_r(sqlsrv_errors());
sqlsrv_query($conn, "DROP TABLE test_empty_stream");
dropTable($conn, $tableName);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -1,32 +1,30 @@
--TEST--
error messages when trying to retrieve past the end of a result set and when no result set exists.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Failed to connect.");
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_prepare($conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params");
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))");
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$f1 = 1;
$f2 = "testtestte";
$f3 = 12.0;
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
if (!$stmt) {
var_dump(sqlsrv_errors());
die("sqlsrv_prepare failed.");
@ -69,7 +67,7 @@ error messages when trying to retrieve past the end of a result set and when no
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM test_params");
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
@ -107,7 +105,7 @@ error messages when trying to retrieve past the end of a result set and when no
}
print_r(sqlsrv_errors());
sqlsrv_query($conn, "DROP TABLE test_params");
sqlsrv_query($conn, "DROP TABLE $tableName");
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);