-
Notifications
You must be signed in to change notification settings - Fork 375
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 #253 from v-kigos/PHP-7.0-Linux-tests
Test: Data type precedence, conversion NVARCHAR(n)
- Loading branch information
Showing
5 changed files
with
230 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Temporary table | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
|
||
require_once("autonomous_setup.php"); | ||
|
||
// Connect | ||
$conn = sqlsrv_connect($serverName, $connectionInfo); | ||
|
||
// Create temporary table and insert data | ||
$sql = "CREATE TABLE #T (col VARCHAR(32)); | ||
INSERT INTO #T VALUES ('PHP7 SQLSRV')"; | ||
$stmt = sqlsrv_query($conn, $sql); | ||
|
||
// Get the data | ||
$sql = "SELECT * FROM #T"; | ||
$stmt = sqlsrv_query($conn, $sql); | ||
sqlsrv_fetch($stmt); | ||
var_dump(sqlsrv_get_field($stmt, 0)); | ||
|
||
// Free statement and close connection | ||
sqlsrv_free_stmt($stmt); | ||
sqlsrv_close($conn); | ||
|
||
print "Done" | ||
?> | ||
|
||
--EXPECT-- | ||
string(11) "PHP7 SQLSRV" | ||
Done |
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,55 @@ | ||
--TEST-- | ||
Data type precedence: conversion NVARCHAR(n) | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
|
||
require_once("autonomous_setup.php"); | ||
|
||
// Connect | ||
$connectionInfo = array("UID"=>$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 |
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,47 @@ | ||
--TEST-- | ||
Data type precedence: conversion VARCHAR(n) | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
|
||
require_once("autonomous_setup.php"); | ||
|
||
// Connect | ||
$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); | ||
|
||
// Read data from the table | ||
$sql = "SELECT * FROM $tableName"; | ||
$stmt = sqlsrv_query($conn, $sql); | ||
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 |
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,40 @@ | ||
--TEST-- | ||
Enable multiple active result sets (MARS) | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
|
||
require_once("autonomous_setup.php"); | ||
|
||
// Connect | ||
$connectionInfo = array("UID"=>$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 |
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,56 @@ | ||
--TEST-- | ||
Error checking for multiple active result sets (MARS) disabled | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
|
||
require_once("autonomous_setup.php"); | ||
|
||
// Connect | ||
$connectionInfo = array("UID"=>$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 | ||
) | ||
|
||
) |