Skip to content

Commit

Permalink
Merge pull request #253 from v-kigos/PHP-7.0-Linux-tests
Browse files Browse the repository at this point in the history
Test: Data type precedence, conversion NVARCHAR(n)
  • Loading branch information
yitam authored Jan 27, 2017
2 parents 44447ea + 136e8cc commit 78598fc
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/sqlsrv/srv_011_temporary_table.phpt
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
55 changes: 55 additions & 0 deletions test/sqlsrv/srv_028_data_conversion_nvarchar.phpt
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
47 changes: 47 additions & 0 deletions test/sqlsrv/srv_029_data_conversion_varchar_datetime.phpt
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
40 changes: 40 additions & 0 deletions test/sqlsrv/srv_052_mars.phpt
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
56 changes: 56 additions & 0 deletions test/sqlsrv/srv_053_mars_disabled_error_checks.phpt
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
)

)

0 comments on commit 78598fc

Please sign in to comment.