From 5d36629140833c3d0ea10247d1e4154a54595273 Mon Sep 17 00:00:00 2001 From: Kirill Gostaf Date: Wed, 25 Jan 2017 12:50:51 -0800 Subject: [PATCH 1/6] Data type precedence: conversion NVARCHAR(n) --- .../srv_028_data_conversion_nvarchar.phpt | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/sqlsrv/srv_028_data_conversion_nvarchar.phpt diff --git a/test/sqlsrv/srv_028_data_conversion_nvarchar.phpt b/test/sqlsrv/srv_028_data_conversion_nvarchar.phpt new file mode 100644 index 000000000..f12a8e541 --- /dev/null +++ b/test/sqlsrv/srv_028_data_conversion_nvarchar.phpt @@ -0,0 +1,55 @@ +--TEST-- +Data type precedence: conversion NVARCHAR(n) +--SKIPIF-- +--FILE-- +$username, "PWD"=>$password, "CharacterSet"=>"UTF-8"); +$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die(); + +// Create database +sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die(); + +// Create table. Column names: passport +$sql = "CREATE TABLE $tableName (c1 NVARCHAR(8))"; +$stmt = sqlsrv_query($conn, $sql); + +// Insert data. The data type with the lower precedence +// is converted to the data type with the higher precedence +$sql = "INSERT INTO $tableName VALUES (3.1415),(-32),(null)"; +$stmt = sqlsrv_query($conn, $sql); + +// Insert more data +$sql = "INSERT INTO $tableName VALUES (''),('Galaxy'),('-- GO'),(N'银河系')"; +$stmt = sqlsrv_query($conn, $sql); + +// Read data from the table +$sql = "SELECT * FROM $tableName"; +$stmt = sqlsrv_query($conn, $sql); + +while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { + var_dump($row[0]); +} + +// DROP database +sqlsrv_query($conn,"DROP DATABASE ". $dbName); + +// Free statement and connection resources +sqlsrv_free_stmt($stmt); +sqlsrv_close($conn); + +print "Done" +?> + +--EXPECT-- +string(6) "3.1415" +string(8) "-32.0000" +NULL +string(0) "" +string(6) "Galaxy" +string(5) "-- GO" +string(9) "银河系" +Done From 276a34be20865fe7a4510ff4254ad5c5ab872136 Mon Sep 17 00:00:00 2001 From: Kirill Gostaf Date: Wed, 25 Jan 2017 13:29:44 -0800 Subject: [PATCH 2/6] Data type precedence: conversion varchar datetime --- ..._029_data_conversion_varchar_datetime.phpt | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt diff --git a/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt b/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt new file mode 100644 index 000000000..3ebf0db24 --- /dev/null +++ b/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt @@ -0,0 +1,74 @@ +--TEST-- +Data type precedence: conversion VARCHAR(n) +--SKIPIF-- +--FILE-- +$username, "PWD"=>$password, "CharacterSet"=>"UTF-8"); +$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die(); + +// Create database +sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die(); + +// Create table. Column names: passport +$sql = "CREATE TABLE $tableName (c1 VARCHAR(30))"; +$stmt = sqlsrv_query($conn, $sql); + +// Insert data. The data type with the lower precedence is +// converted to the data type with the higher precedence +$sql = "INSERT INTO $tableName VALUES (''),(-378.4),(43000.4),(GETDATE())"; +$stmt = sqlsrv_query($conn, $sql); + +// Insert more data +// $sql = "INSERT INTO $tableName VALUES (''),('Galaxy'),('-- GO'),(N'银河系')"; +// $stmt = sqlsrv_query($conn, $sql); + +$err = sqlsrv_errors(); + +print_r($err[0]); +/* +// Prepare the statement +$sql = "SELECT * FROM $tableName"; +$stmt = sqlsrv_prepare( $conn, $sql); + +// Get and display field metadata +foreach(sqlsrv_field_metadata($stmt) as $meta) +{ + print_r($meta); +} +*/ +// echo "OK"; + +// Read data from the table +$sql = "SELECT * FROM $tableName"; +$stmt = sqlsrv_query($conn, $sql); +// if( $stmt === false ) { die( print_r( sqlsrv_errors(), true )); } + +// echo "OK"; + +// var_damp($stmt); + +for($i=0; $i<3; $i++) +{ + $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC); + var_dump($row[0]); +} + +// DROP database +sqlsrv_query($conn,"DROP DATABASE ". $dbName); + +// Free statement and connection resources +sqlsrv_free_stmt($stmt); +sqlsrv_close($conn); + +print "Done" +?> + +--EXPECT-- +string(19) "Jan 1 1900 12:00AM" +string(19) "Dec 18 1898 2:24PM" +string(19) "Sep 24 2017 9:36AM" +Done From f876511cfc59568e382249387f611ced461cb6cd Mon Sep 17 00:00:00 2001 From: Kirill Gostaf Date: Wed, 25 Jan 2017 15:58:46 -0800 Subject: [PATCH 3/6] Update srv_029_data_conversion_varchar_datetime.phpt --- ..._029_data_conversion_varchar_datetime.phpt | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt b/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt index 3ebf0db24..a519f3f93 100644 --- a/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt +++ b/test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt @@ -7,7 +7,6 @@ Data type precedence: conversion VARCHAR(n) require_once("autonomous_setup.php"); // Connect -// $connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8"); $conn = sqlsrv_connect($serverName, $connectionInfo) ?: die(); // Create database @@ -22,35 +21,9 @@ $stmt = sqlsrv_query($conn, $sql); $sql = "INSERT INTO $tableName VALUES (''),(-378.4),(43000.4),(GETDATE())"; $stmt = sqlsrv_query($conn, $sql); -// Insert more data -// $sql = "INSERT INTO $tableName VALUES (''),('Galaxy'),('-- GO'),(N'银河系')"; -// $stmt = sqlsrv_query($conn, $sql); - -$err = sqlsrv_errors(); - -print_r($err[0]); -/* -// Prepare the statement -$sql = "SELECT * FROM $tableName"; -$stmt = sqlsrv_prepare( $conn, $sql); - -// Get and display field metadata -foreach(sqlsrv_field_metadata($stmt) as $meta) -{ - print_r($meta); -} -*/ -// echo "OK"; - // Read data from the table $sql = "SELECT * FROM $tableName"; $stmt = sqlsrv_query($conn, $sql); -// if( $stmt === false ) { die( print_r( sqlsrv_errors(), true )); } - -// echo "OK"; - -// var_damp($stmt); - for($i=0; $i<3; $i++) { $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC); From 3e8a5878dc98798101823c706e73fd48b618f2d5 Mon Sep 17 00:00:00 2001 From: Kirill Gostaf Date: Fri, 27 Jan 2017 10:55:16 -0800 Subject: [PATCH 4/6] Multiple active resultsets: true/false --- test/sqlsrv/srv_052_mars.phpt | 40 +++++++++++++ .../srv_053_mars_disabled_error_checks.phpt | 56 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/sqlsrv/srv_052_mars.phpt create mode 100644 test/sqlsrv/srv_053_mars_disabled_error_checks.phpt diff --git a/test/sqlsrv/srv_052_mars.phpt b/test/sqlsrv/srv_052_mars.phpt new file mode 100644 index 000000000..ee61f5c45 --- /dev/null +++ b/test/sqlsrv/srv_052_mars.phpt @@ -0,0 +1,40 @@ +--TEST-- +Enable multiple active result sets (MARS) +--SKIPIF-- +--FILE-- +$username, "PWD"=>$password, 'MultipleActiveResultSets' => true); +$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die(); + +// Query +$stmt1 = sqlsrv_query( $conn, "SELECT 'ONE'" ) ?: die(print_r( sqlsrv_errors(), true )); +sqlsrv_fetch( $stmt1 ); + +// Query. Returns if multiple result sets are disabled +$stmt2 = sqlsrv_query( $conn, "SELECT 'TWO'" ) ?: die(print_r( sqlsrv_errors(), true )); +sqlsrv_fetch( $stmt2 ); + +// Print the data +$res = [ sqlsrv_get_field($stmt1, 0), sqlsrv_get_field($stmt2, 0) ]; +var_dump($res); + +// Free statement and connection resources +sqlsrv_free_stmt($stmt1); +sqlsrv_free_stmt($stmt2); +sqlsrv_close($conn); + +print "Done" +?> + +--EXPECT-- +array(2) { + [0]=> + string(3) "ONE" + [1]=> + string(3) "TWO" +} +Done diff --git a/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt b/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt new file mode 100644 index 000000000..412989837 --- /dev/null +++ b/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt @@ -0,0 +1,56 @@ +--TEST-- +Error checking for Multiple active result sets (MARS) disabled +--SKIPIF-- +--FILE-- +$username, "PWD"=>$password, 'MultipleActiveResultSets' => false); +$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die(); + +// Query +$stmt1 = sqlsrv_query( $conn, "SELECT 'ONE'" ) ?: die(print_r( sqlsrv_errors(), true )); +sqlsrv_fetch( $stmt1 ); + +// Query. Returns if multiple result sets are disabled +$stmt2 = sqlsrv_query( $conn, "SELECT 'TWO'" ) ?: die(print_r( sqlsrv_errors(), true )); +sqlsrv_fetch( $stmt2 ); + +// Print the data +$res = [ sqlsrv_get_field($stmt1, 0), sqlsrv_get_field($stmt2, 0) ]; +var_dump($res); + +// Free statement and connection resources +sqlsrv_free_stmt($stmt1); +sqlsrv_free_stmt($stmt2); +sqlsrv_close($conn); + +print "Done" +?> + +--EXPECT-- +Array +( + [0] => Array + ( + [0] => IMSSP + [SQLSTATE] => IMSSP + [1] => -44 + [code] => -44 + [2] => The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option. + [message] => The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option. + ) + + [1] => Array + ( + [0] => HY000 + [SQLSTATE] => HY000 + [1] => 0 + [code] => 0 + [2] => [Microsoft][ODBC Driver 13 for SQL Server]Connection is busy with results for another command + [message] => [Microsoft][ODBC Driver 13 for SQL Server]Connection is busy with results for another command + ) + +) From a4667f5cfda047dbfabd30795dd167993f04e4e1 Mon Sep 17 00:00:00 2001 From: Kirill Gostaf Date: Fri, 27 Jan 2017 11:06:10 -0800 Subject: [PATCH 5/6] Update srv_053_mars_disabled_error_checks.phpt --- test/sqlsrv/srv_053_mars_disabled_error_checks.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt b/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt index 412989837..0f03db7cd 100644 --- a/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt +++ b/test/sqlsrv/srv_053_mars_disabled_error_checks.phpt @@ -1,5 +1,5 @@ --TEST-- -Error checking for Multiple active result sets (MARS) disabled +Error checking for multiple active result sets (MARS) disabled --SKIPIF-- --FILE-- Date: Fri, 27 Jan 2017 13:36:40 -0800 Subject: [PATCH 6/6] Temporary table --- test/sqlsrv/srv_011_temporary_table.phpt | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/sqlsrv/srv_011_temporary_table.phpt diff --git a/test/sqlsrv/srv_011_temporary_table.phpt b/test/sqlsrv/srv_011_temporary_table.phpt new file mode 100644 index 000000000..fb89e7bf2 --- /dev/null +++ b/test/sqlsrv/srv_011_temporary_table.phpt @@ -0,0 +1,32 @@ +--TEST-- +Temporary table +--SKIPIF-- +--FILE-- + + +--EXPECT-- +string(11) "PHP7 SQLSRV" +Done