more sqlsrv tests and fixed some

This commit is contained in:
yitam 2017-05-04 09:16:29 -07:00
parent 3e285ec07b
commit 78c0f6f4e6
34 changed files with 3309 additions and 10 deletions

View file

@ -8,10 +8,10 @@ steps to reproduce the issue:
3 - call sp.
--FILE--
<?php
require_once("pdo_tools.inc");
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
require_once("MsCommon.inc");
$conn = new PDO( "sqlsrv:Server=$serverName; Database = tempdb ", $username, $password);
$conn = new PDO( "sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
if (!$conn) {
print_r($conn->errorInfo());
}

View file

@ -1,6 +1,6 @@
--TEST--
PHP - Large Column Name Test
--Description--
--DESCRIPTION--
Verifies that long column names are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true

View file

@ -9,10 +9,9 @@ steps to reproduce the issue:
4 - call sp.
--FILE--
<?php
require_once("tools.inc");
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}

View file

@ -5,9 +5,6 @@ UTF-8 connection strings
--FILE--
<?php
//require( 'MsSetup.inc' );
//require ('connect.inc');
function connect($options=array()) {
require 'MsSetup.inc';
if (!isset($options['UID']) && !isset($options['uid'])) {

View file

@ -0,0 +1,49 @@
--TEST--
Fetch array unicode column names
--SKIPIF--
--FILE--
<?php
include 'MsCommon.inc';
$tableName = "UnicodeColNameTest";
include 'MsSetup.inc';
Setup();
$conn = ConnectUTF8();
$tableName = "UnicodeColNameTest";
DropTable($conn, $tableName);
// Column name
$colName = "C1"; // WORKS
$colName = "C1ÐÐ"; // FETCH RETURNS AN EMPTY OUTPUT
// $colName = "星"; // FETCH RETURNS AN EMPTY OUTPUT
// Create table
$sql = "CREATE TABLE $tableName ($colName VARCHAR(10))";
sqlsrv_query($conn, $sql) ?: die( print_r(sqlsrv_errors(), true));
// Insert data
$sql = "INSERT INTO ".$tableName." VALUES ('Paris')";
$stmt = sqlsrv_query($conn, $sql);
// Fetch data
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query) ?: die( print_r(sqlsrv_errors(), true));
// Fetch
$row = sqlsrv_fetch_array($stmt);
echo $row[$colName]."\n";
DropTable($conn, $tableName);
// Close connection
sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);
print "Done";
?>
--EXPECT--
Paris
Done

View file

@ -0,0 +1,46 @@
--TEST--
Extended ASCII column name with UTF8 w/o BOM file encoding
--SKIPIF--
--FILE--
<?php
include 'MsCommon.inc';
$tableName = "UnicodeColNameTest";
include 'MsSetup.inc';
$conn = ConnectUTF8();
$tableName = "UnicodeColNameTest";
DropTable($conn, $tableName);
// Column names array
$colName = ['C1', "C2", "C3"]; // WORKING REFERENCE
$colName = ["C1Ð", "CÐÐÆØ", str_repeat( "CÐÆØ", 32)];
// Create table
$stmt = sqlsrv_query($conn, "create table ".$tableName
." ($colName[0] VARCHAR(10), $colName[1] VARCHAR(20), $colName[2] INT)");
if( $stmt === false ) { die( print_r( sqlsrv_errors(), true )); }
// Prepare the statement
$query = "SELECT * FROM ".$tableName;
$stmt = sqlsrv_prepare($conn, $query);
// Get field metadata
foreach( sqlsrv_field_metadata( $stmt) as $fieldMetadata) {
$res = $fieldMetadata;
var_dump($res['Name']);
}
DropTable($conn, $tableName);
// Close connection
sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);
print "Done";
?>
--EXPECT--
string(4) "C1Ð"
string(9) "CÐÐÆØ"
string(224) "CÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØCÐÆØ"
Done

View file

@ -0,0 +1,83 @@
--TEST--
retrieval of XML as a string and a stream.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "Failed to connect." );
}
$stmt = sqlsrv_query( $conn, "SELECT xml_type FROM [159137]" );
if( $stmt == false ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_query failed." );
}
sqlsrv_fetch( $stmt );
$str = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if( $str === false ) {
var_dump( sqlsrv_errors() );
}
echo "$str\n";
sqlsrv_fetch( $stmt );
$stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR) );
if( $stream === false ) {
var_dump( sqlsrv_errors() );
die( "reading as a stream failed.");
}
while( !feof( $stream )) {
$xml = fread( $stream, 79 );
echo "$xml\n";
}
?>
--EXPECT--
<?xml-stylesheet href="ProductDescription.xsl" type="text/xsl"?><p1:ProductDescription xmlns:p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription" xmlns:wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain" xmlns:wf="http://www.adventure-works.com/schemas/OtherFeatures" xmlns:html="http://www.w3.org/1999/xhtml" ProductModelID="19" ProductModelName="Mountain 100"><p1:Summary><html:p>Our top-of-the-line competition mountain bike.
Performance-enhancing options include the innovative HL Frame,
super-smooth front suspension, and traction for all terrain.
</html:p></p1:Summary><p1:Manufacturer><p1:Name>AdventureWorks</p1:Name><p1:Copyright>2002</p1:Copyright><p1:ProductURL>HTTP://www.Adventure-works.com</p1:ProductURL></p1:Manufacturer><p1:Features>These are the product highlights.
<wm:Warranty><wm:WarrantyPeriod>3 years</wm:WarrantyPeriod><wm:Description>parts and labor</wm:Description></wm:Warranty><wm:Maintenance><wm:NoOfYears>10 years</wm:NoOfYears><wm:Description>maintenance contract available through your dealer or any AdventureWorks retail store.</wm:Description></wm:Maintenance><wf:wheel>High performance wheels.</wf:wheel><wf:saddle><html:i>Anatomic design</html:i> and made from durable leather for a full-day of riding in comfort.</wf:saddle><wf:pedal><html:b>Top-of-the-line</html:b> clipless pedals with adjustable tension.</wf:pedal><wf:BikeFrame>Each frame is hand-crafted in our Bothell facility to the optimum diameter
and wall-thickness required of a premium mountain frame.
The heat-treated welded aluminum frame has a larger diameter tube that absorbs the bumps.</wf:BikeFrame><wf:crankset> Triple crankset; alumunim crank arm; flawless shifting. </wf:crankset></p1:Features><!-- add one or more of these elements... one for each specific product in this product model --><p1:Picture><p1:Angle>front</p1:Angle><p1:Size>small</p1:Size><p1:ProductPhotoID>118</p1:ProductPhotoID></p1:Picture><!-- add any tags in <specifications> --><p1:Specifications> These are the product specifications.
<Material>Almuminum Alloy</Material><Color>Available in most colors</Color><ProductLine>Mountain bike</ProductLine><Style>Unisex</Style><RiderExperience>Advanced to Professional riders</RiderExperience></p1:Specifications></p1:ProductDescription>
<?xml-stylesheet href="ProductDescription.xsl" type="text/xsl"?><p1:ProductDesc
ription xmlns:p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-work
s/ProductModelDescription" xmlns:wm="http://schemas.microsoft.com/sqlserver/200
4/07/adventure-works/ProductModelWarrAndMain" xmlns:wf="http://www.adventure-wo
rks.com/schemas/OtherFeatures" xmlns:html="http://www.w3.org/1999/xhtml" Produc
tModelID="23" ProductModelName="Mountain-500"><p1:Summary><html:p>Suitable for
any type of riding, on or off-road.
Fits any budget. Smooth-shifting with a
comfortable ride.
</html:p></p1:Summary><p1:Manufactur
er><p1:Name>AdventureWorks</p1:Name><p1:Copyright>2002</p1:Copyright><p1:Produc
tURL>HTTP://www.Adventure-works.com</p1:ProductURL></p1:Manufacturer><p1:Featur
es>Product highlights include:
<wm:Warranty><wm:WarrantyPerio
d>1 year</wm:WarrantyPeriod><wm:Description>parts and labor</wm:Description></w
m:Warranty><wm:Maintenance><wm:NoOfYears>3 years</wm:NoOfYears><wm:Description>
maintenance contact available through dealer</wm:Description></wm:Maintenance><
wf:wheel>Stable, durable wheels suitable for novice riders.</wf:wheel><wf:saddl
e>Made from synthetic leather and features gel padding for increased comfort.</
wf:saddle><wf:pedal><html:b>Expanded platform</html:b> so you can ride in any s
hoes; great for all-around riding.</wf:pedal><wf:crankset> Super rigid spindle.
</wf:crankset><wf:BikeFrame>Our best value frame utilizing the same, ground-br
eaking technology as the ML aluminum frame.</wf:BikeFrame></p1:Features><!-- ad
d one or more of these elements... one for each specific product in this produc
t model --><p1:Picture><p1:Angle>front</p1:Angle><p1:Size>small</p1:Size><p1:Pr
oductPhotoID>1</p1:ProductPhotoID></p1:Picture><!-- add any tags in <specificat
ions> --><p1:Specifications> These are the product specifications.
<Height>Varies</Height> Centimeters.
<Material>Alumin
um Alloy</Material><Color>Available in all colors.</Color><ProductLine>Mountain
bike</ProductLine><Style>Unisex</Style><RiderExperience>Novice to Intermediate
riders</RiderExperience></p1:Specifications></p1:ProductDescription>

View file

@ -0,0 +1,34 @@
--TEST--
using an already closed connection.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
$queries = array(
"SET IDENTITY_INSERT [155671] ON",
"INSERT INTO [155671] (cat_id, cat_title, cat_order) VALUES (14, 'This will be inserted into the db.', 1);",
"SET IDENTITY_INSERT [155671] OFF",
);
foreach( $queries as $query) {
$stmt = sqlsrv_query( $conn, $query );
if( $stmt == false ) {
var_dump( sqlsrv_errors() );
die( $query . " caused an error");
}
}
sqlsrv_close( $conn );
echo "Test successful."
?>
--EXPECT--
Test successful.

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,24 @@
--TEST--
crash caused by a statement being orphaned when an error occurred during sqlsrv_conn_execute.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn1 = Connect();
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
sqlsrv_close($conn1);
$row1 = sqlsrv_fetch_array($stmt1);
$conn3 = Connect();
echo "Test successful\n";
?>
--EXPECTREGEX--
Warning: sqlsrv_fetch_array\(\) expects parameter 1 to be resource, boolean given in .+(\/|\\)test_conn_execute\.php on line 11
Test successful

View file

@ -0,0 +1,57 @@
--TEST--
Test MultipleActiveResultSets connection setting off
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_OFF );
require( 'MsCommon.inc' );
$conn = ConnectSpecial(array( 'MultipleActiveResultSets' => false ));
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt1 = sqlsrv_query( $conn, "SELECT 1" );
if( $stmt1 === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_fetch( $stmt1 );
$stmt2 = sqlsrv_query( $conn, "SELECT 2" );
if( $stmt2 !== false ) {
die( "Should have failed with a MARS error" );
}
print_r( sqlsrv_errors() );
echo "Test succeeded.\n";
?>
--EXPECTREGEX--
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 1[0-9] for SQL Server\]Connection is busy with results for another command
\[message\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]Connection is busy with results for another command
\)
\)
Test succeeded\.

View file

@ -0,0 +1,209 @@
--TEST--
datetime objects as fields and as parameters.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
date_default_timezone_set( 'America/Vancouver' );
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('php_table_SERIL1_1', 'U') IS NOT NULL DROP TABLE [php_table_SERIL1_1]");
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query($conn, "CREATE TABLE [php_table_SERIL1_1] ([c1_datetime] datetime, [c2_smalldatetime] smalldatetime)");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt);
// test inserting into date time as a default
$date_time = date_create( '1963-02-01 20:56' );
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_datetime, c2_smalldatetime) VALUES (?,?)", array( $date_time, $date_time ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT c1_datetime, c2_smalldatetime FROM [php_table_SERIL1_1]" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$date = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_DATETIME );
if( $date === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( date_format( $date, 'Y-m-d H:i:s.u'));
echo "\n";
$date = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_DATETIME );
if( $date === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( date_format( $date, 'Y-m-d H:i:s.u'));
echo "\n";
$stmt = sqlsrv_query( $conn, "TRUNCATE TABLE [php_table_SERIL1_1]");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
// try full complement of information for parameters
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_datetime, c2_smalldatetime) VALUES (?,?)",
array( array( $date_time, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIME ),
array( $date_time, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIME )));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT c1_datetime, c2_smalldatetime FROM [php_table_SERIL1_1]" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$date = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_DATETIME );
if( $date === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( date_format( $date, 'Y-m-d H:i:s.u'));
echo "\n";
$date = sqlsrv_get_field( $stmt, 1 );
if( $date === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( date_format( $date, 'Y-m-d H:i:s.u'));
echo "\n";
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query( $conn, "TRUNCATE TABLE [php_table_SERIL1_1]");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
// try with only php type
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_datetime, c2_smalldatetime) VALUES (?,?)",
array( array( $date_time, null, SQLSRV_PHPTYPE_DATETIME ),
array( $date_time, null, SQLSRV_PHPTYPE_DATETIME )));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT c1_datetime, c2_smalldatetime FROM [php_table_SERIL1_1]" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$date = sqlsrv_get_field( $stmt, 0 );
if( $date === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( date_format( $date, 'Y-m-d H:i:s.u'));
echo "\n";
$date = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_DATETIME );
if( $date === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( date_format( $date, 'Y-m-d H:i:s.u'));
echo "\n";
sqlsrv_free_stmt($stmt);
// try an invalid date
$date_time = date_create( '1872-02-01 20:56' );
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c2_smalldatetime) VALUES (?)", array( $date_time ));
if( $stmt !== false ) {
die( "date time should have been out of range." );
}
print_r( sqlsrv_errors() );
class SimpleClass
{
// member declaration
public $var = 'a default value';
// method declaration
public function displayVar() {
echo $this->var;
}
}
$simple_class = new SimpleClass();
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c2_smalldatetime) VALUES (?)", array( $simple_class ));
if( $stmt !== false ) {
die( "class should have failed." );
}
print_r( sqlsrv_errors() );
sqlsrv_query($conn, "DROP TABLE [php_table_SERIL1_1]");
sqlsrv_close($conn);
echo "test succeeded.";
?>
--EXPECTF--
1963-02-01 20:56:00.000000
1963-02-01 20:56:00.000000
1963-02-01 20:56:00.000000
1963-02-01 20:56:00.000000
1963-02-01 20:56:00.000000
1963-02-01 20:56:00.000000
Array
(
[0] => Array
(
[0] => 22007
[SQLSTATE] => 22007
[1] => 242
[code] => 242
[2] => %SThe conversion of a datetimeoffset data type to a smalldatetime data type resulted in an out-of-range value.
[message] => %SThe conversion of a datetimeoffset data type to a smalldatetime data type resulted in an out-of-range value.
)
[1] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 3621
[code] => 3621
[2] => %SThe statement has been terminated.
[message] => %SThe statement has been terminated.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -16
[code] => -16
[2] => An invalid PHP type for parameter 1 was specified.
[message] => An invalid PHP type for parameter 1 was specified.
)
)
test succeeded.

View file

@ -0,0 +1,64 @@
--TEST--
make sure that decimal and money fields arent corrupted. (197725)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('Products', 'U') IS NOT NULL DROP TABLE Products" );
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$sql = "CREATE TABLE Products (ProductID int identity PRIMARY KEY, ProductName nvarchar(40), CategoryID int, UnitPrice money)";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
$sql = "INSERT INTO Products (ProductName, CategoryID, UnitPrice) VALUES (?, ?, ?)";
$productName = "TestProduct";
$categoryId = 1;
$unitPrice = 12.34;
//each element represents a parameter
$newProductParameters = array(
array($productName, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(40)),
array($categoryId, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT),
array($unitPrice, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_MONEY)
);
$stmt = sqlsrv_query($conn, $sql, $newProductParameters);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM Products" );
while( $row = sqlsrv_fetch_array( $stmt )) {
print_r( $row );
}
sqlsrv_free_stmt( $stmt );
sqlsrv_query( $conn, "DROP TABLE Products" );
sqlsrv_close( $conn );
?>
--EXPECT--
Array
(
[0] => 1
[ProductID] => 1
[1] => TestProduct
[ProductName] => TestProduct
[2] => 1
[CategoryID] => 1
[3] => 12.3400
[UnitPrice] => 12.3400
)

View file

@ -0,0 +1,51 @@
--TEST--
Empty result set from query should not return an error
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('EmptyTable', 'U') IS NOT NULL DROP TABLE EmptyTable" );
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "CREATE TABLE EmptyTable (id int, value char(10))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, "DELETE FROM EmptyTable");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_rows_affected( $stmt );
echo "rows deleted = $rows\n";
sqlsrv_free_stmt( $stmt );
$stream = fopen( "data://text/plain,", "r" );
$stmt = sqlsrv_query($conn, "DELETE FROM EmptyTable WHERE value = ?", array( $stream ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_rows_affected( $stmt );
echo "rows deleted = $rows\n";
sqlsrv_free_stmt( $stmt );
sqlsrv_query( $conn, "DROP TABLE EmptyTable" );
sqlsrv_close( $conn );
echo "Test succeeded.\n";
?>
--EXPECT--
rows deleted = 0
rows deleted = 0
Test succeeded.

View file

@ -0,0 +1,145 @@
--TEST--
Send an empty stream and null stream test.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', false );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "sqlsrv_connect failed." );
}
$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 ));
}
$f1 = 1;
$f2 = fopen( "data://text/plain,", "r" );
$stmt = sqlsrv_prepare( $conn, "INSERT INTO test_empty_stream (id, varchar_stream) VALUES (?, ?)", array( &$f1, &$f2 ));
if( $stmt === false ) {
print_r( "sqlsrv_prepare failed." );
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( "sqlsrv_execute(1) failed." );
die( print_r( sqlsrv_errors(), true ));
}
fclose( $f2 );
$f2 = null;
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( "sqlsrv_execute(2) failed." );
die( print_r( sqlsrv_errors(), true ));
}
$f3 = 1;
$f4 = fopen( "data://text/plain,", "r" );
$stmt = sqlsrv_prepare( $conn, "INSERT INTO test_empty_stream (id, varbinary_stream) VALUES (?, ?)",
array( &$f3,
array( &$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM( SQLSRV_ENC_BINARY ), SQLSRV_SQLTYPE_VARBINARY('max')) ));
if( $stmt === false ) {
print_r( "sqlsrv_prepare failed." );
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( "sqlsrv_execute(3) failed." );
die( print_r( sqlsrv_errors(), true ));
}
fclose( $f4 );
$f4 = null;
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( "sqlsrv_execute(4) failed." );
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "SELECT id, varchar_stream, varbinary_stream FROM test_empty_stream" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$field = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR ));
if( $field === false ) {
die( print_r( sqlsrv_errors(), true ));
}
var_dump( $field );
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$field = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR ));
if( $field === false ) {
die( print_r( sqlsrv_errors(), true ));
}
var_dump( $field );
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$field = sqlsrv_get_field( $stmt, 2, SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR ));
if( $field === false ) {
die( print_r( sqlsrv_errors(), true ));
}
var_dump( $field );
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$field = sqlsrv_get_field( $stmt, 2, SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR ));
if( $field === false ) {
die( print_r( sqlsrv_errors(), true ));
}
var_dump( $field );
// test the field range on sqlsrv_get_field
$field = sqlsrv_get_field( $stmt, -2000 );
if( $field !== false ) {
die( "sqlsrv_get_field(-2000) should have failed." );
}
print_r( sqlsrv_errors() );
sqlsrv_query( $conn, "DROP TABLE test_empty_stream" );
sqlsrv_close( $conn );
?>
--EXPECT--
string(0) ""
NULL
string(0) ""
NULL
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -14
[code] => -14
[2] => An invalid parameter was passed to sqlsrv_get_field.
[message] => An invalid parameter was passed to sqlsrv_get_field.
)
)

View file

@ -0,0 +1,53 @@
--TEST--
Encoding of sqlsrv errors
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
header('content-type: text/plain;encoding=ISO-8859-1');
include( 'MsCommon.inc' );
$conn = ConnectUTF8();
if ( !$conn )
{
die( print_r(sqlsrv_errors(),true));
}
$stmt = sqlsrv_query($conn, "SET LANGUAGE German");
if ( !$stmt )
{
print_r(sqlsrv_errors());
exit;
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "select *, BadColumn from sys.syslanguages");
if ( $stmt )
{
echo 'OK!';
sqlsrv_free_stmt($stmt);
}
else
{
$errs = sqlsrv_errors();
print_r($errs);
}
sqlsrv_close($conn);
?>
--EXPECTF--
Array
(
[0] => Array
(
[0] => 42S22
[SQLSTATE] => 42S22
[1] => 207
[code] => 207
[2] => %SUngültiger Spaltenname %cBadColumn%c.
[message] => %SUngültiger Spaltenname %cBadColumn%c.
)
)

533
test/sqlsrv/test_fetch.phpt Normal file
View file

@ -0,0 +1,533 @@
--TEST--
various fetch types.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if (!$conn)
{
FatalError( "connect failed" );
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM [tracks];" );
if( $stmt === false ) {
FatalError( "sqlsrv_query failed" );
}
$fetch_type = SQLSRV_FETCH_NUMERIC;
while( $row = sqlsrv_fetch_array( $stmt, $fetch_type )) {
var_dump( $row );
if( $fetch_type == SQLSRV_FETCH_NUMERIC ) {
$fetch_type = SQLSRV_FETCH_ASSOC;
}
else if( $fetch_type == SQLSRV_FETCH_ASSOC ) {
$fetch_type = SQLSRV_FETCH_BOTH;
}
else if( $fetch_type == SQLSRV_FETCH_BOTH ) {
$fetch_type = SQLSRV_FETCH_NUMERIC;
}
}
// try some out of range values
$stmt = sqlsrv_query( $conn, "SELECT * FROM [tracks];" );
if( $stmt === false ) {
FatalError( "sqlsrv_query failed" );
}
$row = sqlsrv_fetch_array( $stmt, 0 );
if( $row !== false ) {
die( "Invalid fetch type succeeded." );
}
print_r( sqlsrv_errors() );
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH + 1 );
if( $row !== false ) {
die( "Invalid fetch type succeeded." );
}
print_r( sqlsrv_errors() );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
--EXPECT--
array(2) {
[0]=>
string(13) "Casual Viewin"
[1]=>
string(10) "B00005N8UI"
}
array(2) {
["track"]=>
string(10) "Since When"
["asin"]=>
string(10) "B00005N8UI"
}
array(4) {
[0]=>
string(10) "I Go Blind"
["track"]=>
string(10) "I Go Blind"
[1]=>
string(10) "B00005N8UI"
["asin"]=>
string(10) "B00005N8UI"
}
array(2) {
[0]=>
string(8) "Blue Sky"
[1]=>
string(10) "B00005N8UI"
}
array(2) {
["track"]=>
string(10) "Lies To Me"
["asin"]=>
string(10) "B00005N8UI"
}
array(4) {
[0]=>
string(8) "Baby Ran"
["track"]=>
string(8) "Baby Ran"
[1]=>
string(10) "B00005N8UI"
["asin"]=>
string(10) "B00005N8UI"
}
array(2) {
[0]=>
string(7) "One Gun"
[1]=>
string(10) "B00005N8UI"
}
array(2) {
["track"]=>
string(11) "Ocean Pearl"
["asin"]=>
string(10) "B00005N8UI"
}
array(4) {
[0]=>
string(12) "Love You All"
["track"]=>
string(12) "Love You All"
[1]=>
string(10) "B00005N8UI"
["asin"]=>
string(10) "B00005N8UI"
}
array(2) {
[0]=>
string(16) "Nice To Love You"
[1]=>
string(10) "B00005N8UI"
}
array(2) {
["track"]=>
string(12) "Shes A Jones"
["asin"]=>
string(10) "B00005N8UI"
}
array(4) {
[0]=>
string(11) "Sunday Girl"
["track"]=>
string(11) "Sunday Girl"
[1]=>
string(10) "B00005N8UI"
["asin"]=>
string(10) "B00005N8UI"
}
array(2) {
[0]=>
string(11) "Lost & Lazy"
[1]=>
string(10) "B00005N8UI"
}
array(2) {
["track"]=>
string(11) "Hells Bells"
["asin"]=>
string(10) "B000002JS6"
}
array(4) {
[0]=>
string(15) "Shoot To Thrill"
["track"]=>
string(15) "Shoot To Thrill"
[1]=>
string(10) "B000002JS6"
["asin"]=>
string(10) "B000002JS6"
}
array(2) {
[0]=>
string(30) "What Do You Do For Money Honey"
[1]=>
string(10) "B000002JS6"
}
array(2) {
["track"]=>
string(20) "Given The Dog A Bone"
["asin"]=>
string(10) "B000002JS6"
}
array(4) {
[0]=>
string(27) "Let Me Put My Love Into You"
["track"]=>
string(27) "Let Me Put My Love Into You"
[1]=>
string(10) "B000002JS6"
["asin"]=>
string(10) "B000002JS6"
}
array(2) {
[0]=>
string(13) "Back In Black"
[1]=>
string(10) "B000002JS6"
}
array(2) {
["track"]=>
string(27) "You Shook Me All Night Long"
["asin"]=>
string(10) "B000002JS6"
}
array(4) {
[0]=>
string(18) "Have A Drink On Me"
["track"]=>
string(18) "Have A Drink On Me"
[1]=>
string(10) "B000002JS6"
["asin"]=>
string(10) "B000002JS6"
}
array(2) {
[0]=>
string(11) "Shake A Leg"
[1]=>
string(10) "B000002JS6"
}
array(2) {
["track"]=>
string(34) "Rock And Roll Aint Noise Pollution"
["asin"]=>
string(10) "B000002JS6"
}
array(4) {
[0]=>
string(15) "Highway To Hell"
["track"]=>
string(15) "Highway To Hell"
[1]=>
string(10) "B00008BXJG"
["asin"]=>
string(10) "B00008BXJG"
}
array(2) {
[0]=>
string(16) "Girls Got Rhythm"
[1]=>
string(10) "B00008BXJG"
}
array(2) {
["track"]=>
string(17) "Walk All Over You"
["asin"]=>
string(10) "B00008BXJG"
}
array(4) {
[0]=>
string(14) "Touch Too Much"
["track"]=>
string(14) "Touch Too Much"
[1]=>
string(10) "B00008BXJG"
["asin"]=>
string(10) "B00008BXJG"
}
array(2) {
[0]=>
string(23) "Beating Around The Bush"
[1]=>
string(10) "B00008BXJG"
}
array(2) {
["track"]=>
string(19) "Shot Down In Flames"
["asin"]=>
string(10) "B00008BXJG"
}
array(4) {
[0]=>
string(10) "Get It Hot"
["track"]=>
string(10) "Get It Hot"
[1]=>
string(10) "B00008BXJG"
["asin"]=>
string(10) "B00008BXJG"
}
array(2) {
[0]=>
string(32) "If You Want Blood (Youve Got It)"
[1]=>
string(10) "B00008BXJG"
}
array(2) {
["track"]=>
string(15) "Love Hungry Man"
["asin"]=>
string(10) "B00008BXJG"
}
array(4) {
[0]=>
string(13) "Night Prowler"
["track"]=>
string(13) "Night Prowler"
[1]=>
string(10) "B00008BXJG"
["asin"]=>
string(10) "B00008BXJG"
}
array(2) {
[0]=>
string(20) "Good Times Bad Times"
[1]=>
string(10) "B000002J01"
}
array(2) {
["track"]=>
string(23) "Babe Im Gonna Leave You"
["asin"]=>
string(10) "B000002J01"
}
array(4) {
[0]=>
string(12) "You Shook Me"
["track"]=>
string(12) "You Shook Me"
[1]=>
string(10) "B000002J01"
["asin"]=>
string(10) "B000002J01"
}
array(2) {
[0]=>
string(18) "Dazed And Confused"
[1]=>
string(10) "B000002J01"
}
array(2) {
["track"]=>
string(23) "Your Time Is Gonna Come"
["asin"]=>
string(10) "B000002J01"
}
array(4) {
[0]=>
string(19) "Black Mountain Side"
["track"]=>
string(19) "Black Mountain Side"
[1]=>
string(10) "B000002J01"
["asin"]=>
string(10) "B000002J01"
}
array(2) {
[0]=>
string(23) "Communication Breakdown"
[1]=>
string(10) "B000002J01"
}
array(2) {
["track"]=>
string(20) "I Cant Quit You Baby"
["asin"]=>
string(10) "B000002J01"
}
array(4) {
[0]=>
string(19) "How Many More Times"
["track"]=>
string(19) "How Many More Times"
[1]=>
string(10) "B000002J01"
["asin"]=>
string(10) "B000002J01"
}
array(2) {
[0]=>
string(14) "Good Time Boys"
[1]=>
string(10) "B000078DOI"
}
array(2) {
["track"]=>
string(13) "Higher Ground"
["asin"]=>
string(10) "B000078DOI"
}
array(4) {
[0]=>
string(15) "Subway To Venus"
["track"]=>
string(15) "Subway To Venus"
[1]=>
string(10) "B000078DOI"
["asin"]=>
string(10) "B000078DOI"
}
array(2) {
[0]=>
string(13) "Magic Johnson"
[1]=>
string(10) "B000078DOI"
}
array(2) {
["track"]=>
string(20) "Nobody Weird Like Me"
["asin"]=>
string(10) "B000078DOI"
}
array(4) {
[0]=>
string(13) "Knock Me Down"
["track"]=>
string(13) "Knock Me Down"
[1]=>
string(10) "B000078DOI"
["asin"]=>
string(10) "B000078DOI"
}
array(2) {
[0]=>
string(14) "Taste The Pain"
[1]=>
string(10) "B000078DOI"
}
array(2) {
["track"]=>
string(15) "Stone Cold Bush"
["asin"]=>
string(10) "B000078DOI"
}
array(4) {
[0]=>
string(4) "Fire"
["track"]=>
string(4) "Fire"
[1]=>
string(10) "B000078DOI"
["asin"]=>
string(10) "B000078DOI"
}
array(2) {
[0]=>
string(19) "Pretty Little Ditty"
[1]=>
string(10) "B000078DOI"
}
array(2) {
["track"]=>
string(17) "Punk Rock Classic"
["asin"]=>
string(10) "B000078DOI"
}
array(4) {
[0]=>
string(17) "Sexy Mexican Maid"
["track"]=>
string(17) "Sexy Mexican Maid"
[1]=>
string(10) "B000078DOI"
["asin"]=>
string(10) "B000078DOI"
}
array(2) {
[0]=>
string(30) "Johnny, Kick A Hole In The Sky"
[1]=>
string(10) "B000078DOI"
}
array(2) {
["track"]=>
string(42) "Song That Made Us What We Are Today (Demo)"
["asin"]=>
string(10) "B000078DOI"
}
array(4) {
[0]=>
string(37) "Knock Me Down (Original Long Version)"
["track"]=>
string(37) "Knock Me Down (Original Long Version)"
[1]=>
string(10) "B000078DOI"
["asin"]=>
string(10) "B000078DOI"
}
array(2) {
[0]=>
string(41) "Sexy Mexican Maid (Original Long Version)"
[1]=>
string(10) "B000078DOI"
}
array(2) {
["track"]=>
string(23) "Salute To Kareem (Demo)"
["asin"]=>
string(10) "B000078DOI"
}
array(4) {
[0]=>
string(27) "Castles Made Of Sand (Live)"
["track"]=>
string(27) "Castles Made Of Sand (Live)"
[1]=>
string(10) "B000078DOI"
["asin"]=>
string(10) "B000078DOI"
}
array(2) {
[0]=>
string(24) "Crosstown Traffic (Live)"
[1]=>
string(10) "B000078DOI"
}
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -10
[code] => -10
[2] => An invalid fetch type was specified. SQLSRV_FETCH_NUMERIC, SQLSRV_FETCH_ARRAY and SQLSRV_FETCH_BOTH are acceptable values.
[message] => An invalid fetch type was specified. SQLSRV_FETCH_NUMERIC, SQLSRV_FETCH_ARRAY and SQLSRV_FETCH_BOTH are acceptable values.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -10
[code] => -10
[2] => An invalid fetch type was specified. SQLSRV_FETCH_NUMERIC, SQLSRV_FETCH_ARRAY and SQLSRV_FETCH_BOTH are acceptable values.
[message] => An invalid fetch type was specified. SQLSRV_FETCH_NUMERIC, SQLSRV_FETCH_ARRAY and SQLSRV_FETCH_BOTH are acceptable values.
)
)

View file

@ -0,0 +1,85 @@
--TEST--
nameless fields return correctly in sqlsrv_fetch_array and sqlsrv_fetch_object.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if ( $conn === false ) {
FatalError( "connect failed" );
}
$stmt = sqlsrv_query( $conn, "SELECT COUNT(track) FROM tracks" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while( $row = sqlsrv_fetch_array( $stmt )) {
print_r( $row );
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT COUNT(track) FROM tracks" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$row = sqlsrv_fetch_object( $stmt );
print_r( sqlsrv_errors( SQLSRV_ERR_WARNINGS ));
sqlsrv_configure( 'WarningsReturnAsErrors', 1 );
$stmt = sqlsrv_query( $conn, "SELECT COUNT(track) FROM tracks" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$row = sqlsrv_fetch_object( $stmt );
if( $row === false ) {
print_r( sqlsrv_errors() );
}
else {
echo "Should have failed since warnings return as errors.\n";
}
sqlsrv_close( $conn );
?>
--EXPECT--
Array
(
[0] => 61
[] => 61
)
Array
(
[0] => Array
(
[0] => 01SSP
[SQLSTATE] => 01SSP
[1] => -100
[code] => -100
[2] => An empty field name was skipped by sqlsrv_fetch_object.
[message] => An empty field name was skipped by sqlsrv_fetch_object.
)
)
Array
(
[0] => Array
(
[0] => 01SSP
[SQLSTATE] => 01SSP
[1] => -100
[code] => -100
[2] => An empty field name was skipped by sqlsrv_fetch_object.
[message] => An empty field name was skipped by sqlsrv_fetch_object.
)
)

View file

@ -0,0 +1,50 @@
--TEST--
Insert nulls into fields of all types.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', false );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
echo "Starting\n";
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "connect failed." );
}
echo "Inserting nulls into fixed size types\n";
$stmt = sqlsrv_query( $conn, "INSERT INTO test_types (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, money_type, smallmoney_type, float_type, real_type, datetime_type, smalldatetime_type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
array( null, null, null, null, null, null, null, null, null, null, null, null ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "Inserting nulls into variable size types\n";
$stmt = sqlsrv_query( $conn, "INSERT INTO test_streamable_types (varchar_type, nvarchar_type, varbinary_type, text_type, ntext_type, image_type, xml_type, char_short_type, varchar_short_type, nchar_short_type, nvarchar_short_type, binary_short_type, varbinary_short_type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
array( null, null,
array( null, null, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')),
null, null,
null, // array( null, null, null, SQLSRV_SQLTYPE_IMAGE ),
null, null, null, null, null,
array( null, null, null, SQLSRV_SQLTYPE_BINARY(256)),
array( null, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM( SQLSRV_ENC_BINARY ), SQLSRV_SQLTYPE_VARBINARY(256) )));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_close( $conn );
echo "Test succeeded.\n";
?>
--EXPECT--
Starting
Inserting nulls into fixed size types
Inserting nulls into variable size types
Test succeeded.

Binary file not shown.

View file

@ -0,0 +1,142 @@
--TEST--
Test Integer types MAX, MIN, ZERO values.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
$tableUniqueName = "PHP_Firefly_Table";
$conn = Connect();
date_default_timezone_set('Canada/Pacific');
// drop an old table if exists, create a new one
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('$tableUniqueName', 'U') IS NOT NULL DROP TABLE$tableUniqueName");
// -- create the new table
$tsql = "CREATE TABLE $tableUniqueName (
[bigint_type] BIGINT null,
[int_type] INT null,
[smallint_type] SMALLINT null,
[tinyint_type] TINYINT null,
[bit_type] BIT null,
[decimal_type] DECIMAL(38,0) null,
[money_type] MONEY null,
[smallmoney_type] SMALLMONEY null,
[datetime_type] DATETIME null,
[smalldatetime_type] SMALLDATETIME null );";
$stmt = sqlsrv_query($conn,$tsql);
sqlsrv_free_stmt( $stmt );
// inserting data into the table
// -- maximum test
$tsql = "INSERT INTO $tableUniqueName (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, datetime_type, money_type, smallmoney_type)
VALUES (9223372036854775807, 2147483647, 32767, 255, 1, 9999999999999999999999999999999999999, '12/12/1968 16:20', 922337203685477.5807, 214748.3647)";
$stmt = sqlsrv_query($conn, $tsql);
// -- minimum test
$tsql = "INSERT INTO $tableUniqueName (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, datetime_type, money_type, smallmoney_type)
VALUES (-9223372036854775808, -2147483648, -32768, 0, 0, -10000000000000000000000000000000000001,'12/12/1968 16:20', -922337203685477.5808, -214748.3648)";
$stmt = sqlsrv_query($conn, $tsql);
// -- zero test
$tsql = "INSERT INTO $tableUniqueName (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, datetime_type, money_type, smallmoney_type)
VALUES (0, 0, 0, 0, 0, 0, '12/12/1968 16:20', 0, 0)";
$stmt = sqlsrv_query($conn, $tsql);
// ----MAX-------
$tsql = "SELECT * FROM $tableUniqueName";
$stmt = sqlsrv_query($conn, $tsql);
$row = sqlsrv_fetch_array($stmt,1);
print_r($row);
// ----MIN-------
$row = sqlsrv_fetch_array($stmt,2);
print_r($row);
// ----ZERO-------
$row = sqlsrv_fetch_array($stmt);
print_r($row);
sqlsrv_query($conn, "DROP TABLE $tableUniqueName");
sqlsrv_free_stmt( $stmt );
sqlsrv_close($conn);
?>
--EXPECT--
Array
(
[0] => 9223372036854775807
[1] => 2147483647
[2] => 32767
[3] => 255
[4] => 1
[5] => 9999999999999999999999999999999999999
[6] => 922337203685477.5807
[7] => 214748.3647
[8] => DateTime Object
(
[date] => 1968-12-12 16:20:00.000000
[timezone_type] => 3
[timezone] => Canada/Pacific
)
[9] =>
)
Array
(
[bigint_type] => -9223372036854775808
[int_type] => -2147483648
[smallint_type] => -32768
[tinyint_type] => 0
[bit_type] => 0
[decimal_type] => -10000000000000000000000000000000000001
[money_type] => -922337203685477.5808
[smallmoney_type] => -214748.3648
[datetime_type] => DateTime Object
(
[date] => 1968-12-12 16:20:00.000000
[timezone_type] => 3
[timezone] => Canada/Pacific
)
[smalldatetime_type] =>
)
Array
(
[0] => 0
[bigint_type] => 0
[1] => 0
[int_type] => 0
[2] => 0
[smallint_type] => 0
[3] => 0
[tinyint_type] => 0
[4] => 0
[bit_type] => 0
[5] => 0
[decimal_type] => 0
[6] => .0000
[money_type] => .0000
[7] => .0000
[smallmoney_type] => .0000
[8] => DateTime Object
(
[date] => 1968-12-12 16:20:00.000000
[timezone_type] => 3
[timezone] => Canada/Pacific
)
[datetime_type] => DateTime Object
(
[date] => 1968-12-12 16:20:00.000000
[timezone_type] => 3
[timezone] => Canada/Pacific
)
[9] =>
[smalldatetime_type] =>
)

View file

@ -0,0 +1,113 @@
--TEST--
send a large amount (10MB) using encryption.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
class my_stream {
var $total_read = 0;
function stream_open ($path, $mode, $options, &$opened_path )
{
$this->total_read = 0;
return true;
}
function stream_read( $count )
{
if( $this->total_read > 20000000 ) {
return 0;
}
global $packets;
++$packets;
$str = str_repeat( "A", $count );
$this->total_read += $count;
return $str;
}
function stream_write($data)
{
}
function stream_tell()
{
return $this->total_read;
}
function stream_eof()
{
return $this->total_read > 20000000;
}
function stream_seek($offset, $whence)
{
}
}
set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
$packets = 0;
$result = stream_wrapper_register( "mystr", "my_stream" );
if( !$result ) {
die( "Couldn't register stream class." );
}
require( 'MsCommon.inc' );
$conn = Connect(array( 'Encrypt' => true, 'TrustServerCertificate' => true ));
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_lob', 'U') IS NOT NULL DROP TABLE test_lob" );
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "CREATE TABLE test_lob (id tinyint, stuff varbinary(max))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
$lob = fopen( "mystr://test_data", "rb" );
if( !$lob ) {
die( "failed opening test stream.\n" );
}
$stmt = sqlsrv_query( $conn, "INSERT INTO test_lob (id, stuff) VALUES (?,?)", array( 1, array( $lob, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while( $result = sqlsrv_send_stream_data( $stmt )) {
++$packets;
}
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "$packets sent.\n";
$stmt = sqlsrv_query( $conn, "SELECT LEN(stuff) FROM test_lob" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while( $result = sqlsrv_fetch_array( $stmt )) {
print_r( $result );
}
sqlsrv_query( $conn, "DROP TABLE test_lob" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sleep(10); // since this is a long test, we give the database some time to finish
?>
--EXPECT--
2442 sent.
Array
(
[0] => 20004865
[] => 20004865
)

View file

@ -0,0 +1,115 @@
--TEST--
Maximum length outputs from stored procs for string types (nvarchar, varchar, and varbinary)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
set_time_limit(0);
$inValue1 = str_repeat( "A", 3999 );
$outValue1 = "TEST";
sqlsrv_configure('WarningsReturnAsErrors', 0); // True
sqlsrv_configure('LogSubsystems', 15); // True
require( 'MsCommon.inc' );
$conn = Connect();
$field_type = 'NVARCHAR(4000)';
$stmt = sqlsrv_query($conn, "DROP PROC [TestFullLenStringsOut]");
$stmt = sqlsrv_query($conn, "CREATE PROC [TestFullLenStringsOut] (@p1 " . $field_type . ", @p2 " . $field_type . " OUTPUT)
AS
BEGIN
SELECT @p2 = CONVERT(" . $field_type . ", @p1 + N'A')
END");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
// remember to increment buffer_len at stmt.cpp:1358 to 8001 to see what happens and
// verify that something is sent by ODBC to the server in the profiler
$stmt = sqlsrv_query($conn, "{CALL [TestFullLenStringsOut] (?, ?)}",
array(
array($inValue1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(4000)),
array(&$outValue1, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(4000))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while( sqlsrv_next_result( $stmt )) {}
print_r( strlen( $outValue1 ));
echo "\n";
print_r( substr( $outValue1, -2, 2 ));
$field_type = 'VARCHAR(8000)';
$inValue1 = str_repeat( "A", 7999 );
$stmt = sqlsrv_query($conn, "DROP PROC [TestFullLenStringsOut]");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "CREATE PROC [TestFullLenStringsOut] (@p1 " . $field_type . ", @p2 " . $field_type . " OUTPUT)
AS
BEGIN
SELECT @p2 = CONVERT(" . $field_type . ", @p1 + 'A')
END" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, "{CALL [TestFullLenStringsOut] (?, ?)}",
array(
array($inValue1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(8000)),
array(&$outValue1, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(8000))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while( sqlsrv_next_result( $stmt )) {}
echo "\n";
print_r( strlen( $outValue1 ));
echo "\n";
print_r( substr( $outValue1, -2, 2 ));
$field_type = 'VARBINARY(8000)';
$inValue1 = str_repeat( "A", 7999 );
$stmt = sqlsrv_query($conn, "DROP PROC [TestFullLenStringsOut]");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, "CREATE PROC [TestFullLenStringsOut] (@p1 " . $field_type . ", @p2 " . $field_type . " OUTPUT)
AS
BEGIN
SELECT @p2 = CONVERT(" . $field_type . ", @p1 + 0x42)
END");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, "{CALL [TestFullLenStringsOut] (?, ?)}",
array(
array($inValue1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(8000)),
array(&$outValue1, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(8000))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while( sqlsrv_next_result( $stmt )) {}
echo "\n";
print_r( strlen( $outValue1 ));
echo "\n";
print_r( substr( $outValue1, -2, 2 ));
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn ); // True
?>
--EXPECT--
4000
AA
8000
AA
8000
AB

View file

@ -0,0 +1,77 @@
--TEST--
test new error messages when sqlsrv_get_field is called
--DESCRIPTION--
new error messages when sqlsrv_get_field is called before sqlsrv_fetch or
if sqlsrv_get_field is called with out of order field indices.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if (!$conn)
{
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM test_types" );
if (!$stmt)
{
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_get_field( $stmt, 0 );
if( $result !== false ) {
die( "sqlsrv_get_field before sqlsrv_fetch shouldn't have succeeded." );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_fetch( $stmt );
if ($result === false)
{
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_get_field( $stmt, 3 );
$result = sqlsrv_get_field( $stmt, 0 );
if( $result !== false ) {
die( "sqlsrv_get_field for field 0 shouldn't have succeeded." );
}
print_r( sqlsrv_errors() );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -18
[code] => -18
[2] => A row must be retrieved with sqlsrv_fetch before retrieving data with sqlsrv_get_field.
[message] => A row must be retrieved with sqlsrv_fetch before retrieving data with sqlsrv_get_field.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -19
[code] => -19
[2] => Fields within a row must be accessed in ascending order. The sqlsrv_get_field function cannot retrieve field 0 because its index is less than the index of a field that has already been retrieved (3).
[message] => Fields within a row must be accessed in ascending order. The sqlsrv_get_field function cannot retrieve field 0 because its index is less than the index of a field that has already been retrieved (3).
)
)

View file

@ -0,0 +1,55 @@
--TEST--
password with non alphanumeric characters
--DESCRIPTION--
The first three cases should have no problem connecting. Only the last case fails because the
right curly brace should be escaped with another right brace.
In Azure we can't set DEFAULT_DATABASE for a login user. For this test to psss must connect
to the test database defined in MsSetup.inc
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = ConnectSpecial(array( "UID" => "test_password", "pwd" => "! ;4triou" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = ConnectSpecial(array( "UID" => "test_password2", "pwd" => "!}} ;4triou" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = ConnectSpecial(array( "UID" => "test_password3", "pwd" => "! ;4triou}}" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = ConnectSpecial(array( "UID" => "test_password3", "pwd" => "! ;4triou}" ));
if ($conn)
{
echo( "Shouldn't have connected" );
}
$errors = sqlsrv_errors();
echo $errors[0]["message"];
sqlsrv_close( $conn );
print "Test successful";
?>
--EXPECTREGEX--
An unescaped right brace \(}\) was found in either the user name or password. All right braces must be escaped with another right brace \(}}\)\.
Warning: sqlsrv_close\(\) expects parameter 1 to be resource, boolean given in .+(\/|\\)test_non_alpha_password\.php on line 38
Test successful

View file

@ -0,0 +1,102 @@
--TEST--
invalid precision and sizes for parameters.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "sqlsrv_create failed." );
}
$stmt = sqlsrv_prepare( $conn, "IF OBJECT_ID('test_precision_size', 'U') IS NOT NULL DROP TABLE test_precision_size" );
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_prepare( $conn, "CREATE TABLE test_precision_size (id tinyint, varchar_type varchar(8000), decimal_type decimal(38,19)" );
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
$f1 = 1;
$f2 = "testtestte";
$f3 = 12.0;
// test an invalid size for a varchar field (8000 max)
$stmt = sqlsrv_query( $conn, "INSERT INTO test_precision_size (id, varchar_type, decimal_type ) VALUES (?, ?, ?)",
array( $f1, array( $f2, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR(9000)), $f3 ));
if( $stmt !== false ) {
die( "sqlsrv_query should have failed." );
}
else {
print_r( sqlsrv_errors() );
}
// test an invalid precision where precision > than max allowed (38)
$stmt = sqlsrv_query( $conn, "INSERT INTO test_precision_size (id, varchar_type, decimal_type ) VALUES (?, ?, ?)",
array( $f1, array( $f2, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR(8000)), array( $f3, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_DECIMAL( 40, 0 ))));
if( $stmt !== false ) {
die( "sqlsrv_query should have failed." );
}
else {
print_r( sqlsrv_errors() );
}
// test an invalid precision where the scale > precision
$stmt = sqlsrv_query( $conn, "INSERT INTO test_precision_size (id, varchar_type, decimal_type ) VALUES (?, ?, ?)",
array( $f1, array( $f2, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR(8000)), array( $f3, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_DECIMAL( 15, 30 ))));
if( $stmt !== false ) {
die( "sqlsrv_query should have failed." );
}
else {
print_r( sqlsrv_errors() );
}
sqlsrv_query( $conn, "DROP TABLE test_precision_size" );
sqlsrv_close( $conn );
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -31
[code] => -31
[2] => An invalid size or precision for parameter 2 was specified.
[message] => An invalid size or precision for parameter 2 was specified.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -31
[code] => -31
[2] => An invalid size or precision for parameter 3 was specified.
[message] => An invalid size or precision for parameter 3 was specified.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -31
[code] => -31
[2] => An invalid size or precision for parameter 3 was specified.
[message] => An invalid size or precision for parameter 3 was specified.
)
)

View file

@ -0,0 +1,249 @@
--TEST--
scrollable result sets.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', false );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('ScrollTest', 'U') IS NOT NULL DROP TABLE ScrollTest" );
if( $stmt !== false ) { sqlsrv_free_stmt( $stmt ); }
$stmt = sqlsrv_query( $conn, "CREATE TABLE ScrollTest (id int, value char(10))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_has_rows( $stmt );
if( $rows == true ) {
die( "Shouldn't have rows" );
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 1, "Row 1" ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_has_rows( $stmt );
if( $rows == true ) {
die( "Shouldn't have rows" );
}
$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 2, "Row 2" ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_has_rows( $stmt );
if( $rows == true ) {
die( "Shouldn't have rows" );
}
$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 3, "Row 3" ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_has_rows( $stmt );
if( $rows == true ) {
die( "Shouldn't have rows" );
}
$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 4, "Row 4" ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$rows = sqlsrv_has_rows( $stmt );
if( $rows == true ) {
die( "Shouldn't have rows" );
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'static' ));
$result = sqlsrv_fetch( $stmt, SQLSRV_SCROLL_ABSOLUTE, 4 );
if( $result !== null ) {
die( "Should have failed with an invalid row number" );
}
$rows = sqlsrv_has_rows( $stmt );
if( $rows != true ) {
die( "Should have rows" );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_fetch( $stmt, SQLSRV_SCROLL_ABSOLUTE, -1 );
if( $result !== null ) {
die( "Should have failed with an invalid row number" );
}
print_r( sqlsrv_errors() );
$rows = sqlsrv_rows_affected( $stmt );
print_r( sqlsrv_errors() );
$rows = sqlsrv_num_rows( $stmt );
echo "Query returned $rows rows\n";
$row = 3;
$result = sqlsrv_fetch( $stmt, SQLSRV_SCROLL_ABSOLUTE, $row );
do {
$result = sqlsrv_fetch( $stmt, SQLSRV_SCROLL_ABSOLUTE, $row );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$field1 = sqlsrv_get_field( $stmt, 0 );
$field2 = sqlsrv_get_field( $stmt, 1 );
echo "$field1 $field2\n";
$row = $row - 1;
} while( $row >= 0 );
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => SQLSRV_CURSOR_FORWARD ));
$rows = sqlsrv_has_rows( $stmt );
if( $rows != true ) {
die( "Should have rows" );
}
$row_count = 0;
while( $row = sqlsrv_fetch( $stmt )) {
++$row_count;
}
if( $row === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "$row_count rows retrieved on the forward only cursor\n";
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'static' ));
$rows = sqlsrv_has_rows( $stmt );
if( $rows != true ) {
die( "Should have rows" );
}
$row_count = 0;
while( $row = sqlsrv_fetch( $stmt )) {
++$row_count;
}
if( $row === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "$row_count rows retrieved on the static cursor\n";
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'dynamic' ));
sqlsrv_fetch( $stmt );
sqlsrv_fetch( $stmt );
$stmt2 = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 5, "Row 5" ));
if( $stmt2 === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt2 = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 6, "Row 6" ));
if( $stmt2 === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$row_count = 2; // for the two fetches above
while( sqlsrv_fetch( $stmt )) {
++$row_count;
}
echo "$row_count rows retrieved on the dynamic cursor\n";
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => SQLSRV_CURSOR_STATIC ));
$row_count = sqlsrv_num_rows( $stmt );
if( $row_count != 6 ) {
die( "sqlsrv_num_rows should have returned 6 rows in the static cursor\n" );
}
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE, -1 );
if( $row !== null ) {
die( "sqlsrv_fetch_array should have returned null\n" );
}
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE, 6 );
if( $row !== null ) {
die( "sqlsrv_fetch_array should have returned null\n" );
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => SQLSRV_CURSOR_DYNAMIC ));
$result = sqlsrv_num_rows( $stmt );
if( $result !== false ) {
die( "sqlsrv_num_rows should have failed for a dynamic cursor." );
}
sqlsrv_fetch( $stmt );
sqlsrv_fetch( $stmt );
$stmt2 = sqlsrv_query( $conn, "DELETE FROM ScrollTest WHERE id = 2" );
if( $stmt2 === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$row = sqlsrv_get_field( $stmt, 0 );
if( $row !== false ) {
die( "Should have returned false retrieving a field deleted by another query\n" );
}
echo "sqlsrv_get_field returned false when retrieving a field deleted by another query\n";
print_r( sqlsrv_errors() );
// verify the sqlsrv_fetch_object is working
$obj = sqlsrv_fetch_object( $stmt, null, array(null), SQLSRV_SCROLL_LAST, 1 );
if( $obj === false ) {
print_r( sqlsrv_errors() );
}
print_r( $obj );
sqlsrv_query( $conn, "DROP TABLE ScrollTest" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
echo "Test succeeded.\n";
?>
--EXPECTREGEX--
Array
\(
\[0\] => Array
\(
\[0\] => IMSSP
\[SQLSTATE\] => IMSSP
\[1\] => \-51
\[code\] => \-51
\[2\] => This function only works with statements that are not scrollable\.
\[message\] => This function only works with statements that are not scrollable\.
\)
\)
Query returned 4 rows
4 Row 4
3 Row 3
2 Row 2
1 Row 1
4 rows retrieved on the forward only cursor
4 rows retrieved on the static cursor
6 rows retrieved on the dynamic cursor
sqlsrv_get_field returned false when retrieving a field deleted by another query
Array
\(
\[0\] => Array
\(
\[0\] => HY109
\[SQLSTATE\] => HY109
\[1\] => 0
\[code\] => 0
\[2\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]Invalid cursor position
\[message\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]Invalid cursor position
\)
\)
stdClass Object
\(
\[id\] => 6
\[value\] => Row 6
\)
Test succeeded\.

Binary file not shown.

View file

@ -0,0 +1,29 @@
--TEST--
Test for stream zombifying.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "Failed to connect." );
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM [test_streamable_types]" );
$metadata = sqlsrv_field_metadata( $stmt );
$count = count( $metadata );
sqlsrv_fetch( $stmt );
$stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
sqlsrv_fetch( $stmt );
$name = fread( $stream, 100 );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
--EXPECTREGEX--
Warning: fread\(\): supplied resource is not a valid stream resource in .+(\/|\\)test_stream\.php on line [0-9]+

View file

@ -0,0 +1,226 @@
--TEST--
streaming large amounts of data into a database and getting it out as a string exactly the same.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
set_time_limit(0); // True
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_OFF );
require( 'MsCommon.inc' );
$notWindows = (! IsWindows());
// required charset UTF-8 when NOT running in Windows
$conn1 = ($notWindows) ? ConnectUTF8() : Connect() ;
if( $conn1 === false ) {
FatalError("Failed to connect");
}
$stmt1 = sqlsrv_query($conn1, "IF OBJECT_ID('179886', 'U') IS NOT NULL DROP TABLE [179886]");
if( $stmt1 === true ) sqlsrv_free_stmt($stmt1);
$stmt2 = sqlsrv_query($conn1, "CREATE TABLE [179886] ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,0), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_nchar] nchar(512), [c16_nvarchar] nvarchar(512), [c17_nvarchar_max] nvarchar(max), [c18_text] text, [c19_ntext] ntext, [c20_binary] binary(512), [c21_varbinary] varbinary(512), [c22_varbinary_max] varbinary(max), [c23_image] image, [c24_uniqueidentifier] uniqueidentifier, [c25_datetime] datetime, [c26_smalldatetime] smalldatetime, [c27_timestamp] timestamp, [c28_xml] xml)");
if( $stmt2 === false ) {
echo "sqlsrv_query(1) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt2);
sqlsrv_close( $conn1 );
if ($notWindows)
$conn2 = connect(array( 'CharacterSet' =>'utf-8' ));
else
$conn2 = connect();
if( $conn2 === false ) {
echo "sqlsrv_connect failed 2nd.\n";
die( print_r( sqlsrv_errors(), true ));
}
if ($notWindows)
{
require( 'test_stream_large_data_UTF8.inc' );
GenerateInputUTF8Data();
}
else
{
require( 'test_stream_large_data.inc' );
GenerateInputData();
}
// stream the data into the table
$fin1 = fopen("varchar_max.txt", "r"); // 7
$fin2 = fopen("nvarchar_max.txt", "r"); // 10
$fin3 = fopen("text.txt", "r"); // 13
$fin4 = fopen("ntext.txt", "r"); // 16
$fin5 = fopen("xml.txt", "r"); // 19
$stmt3 = sqlsrv_query( $conn2, "INSERT INTO [179886] ([c1_int], [c14_varchar_max], [c17_nvarchar_max], [c18_text], [c19_ntext], [c28_xml]) VALUES(?, ?, ?, ?, ?, ?)", array(1, $fin1, $fin2, $fin3, $fin4, $fin5));
if( $stmt3 === false ) {
echo "sqlsrv_query(2) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
while( $sent = sqlsrv_send_stream_data( $stmt3 )) {
}
if( $sent === false ) {
echo "sqlsrv_send_stream_data(1) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt3); // True
fclose($fin1); // True
fclose($fin2); // True
fclose($fin3); // True
fclose($fin4); // True
fclose($fin5); // True
$fin = fopen("nvarchar_max.txt", "r"); // 10
$stmt4 = sqlsrv_query( $conn2, "INSERT INTO [179886] ([c17_nvarchar_max]) VALUES(?)", array($fin));
if( $stmt4 === false ) {
echo "sqlsrv_query(3) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
while( $sent = sqlsrv_send_stream_data( $stmt4 )) {
}
if( $sent === false ) {
echo "sqlsrv_send_stream_data(2) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt4); // True
fclose($fin); // True
$fin = fopen("text.txt", "r"); // 13
$stmt5 = sqlsrv_query( $conn2, "INSERT INTO [179886] (c18_text) VALUES(?)", array($fin));
if( $stmt5 === false ) {
echo "sqlsrv_query(4) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
while( $sent = sqlsrv_send_stream_data( $stmt5 )) {
}
if( $sent === false ) {
echo "sqlsrv_send_stream_data(3) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt5); // True
fclose($fin); // True
$fin = fopen("ntext.txt", "r"); // 16
$stmt6 = sqlsrv_query( $conn2, "INSERT INTO [179886] (c19_ntext) VALUES(?)", array($fin));
if( $stmt6 === false ) {
echo "sqlsrv_query(5) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
while( $sent = sqlsrv_send_stream_data( $stmt6 )) {
}
if( $sent === false ) {
echo "sqlsrv_send_stream_data(4) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt6); // True
fclose($fin); // True
$fin = fopen("xml.txt", "r"); // 19
$stmt7 = sqlsrv_query( $conn2, "INSERT INTO [179886] (c28_xml) VALUES(?)", array($fin));
if( $stmt7 === false ) {
echo "sqlsrv_query(6) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
while( $sent = sqlsrv_send_stream_data( $stmt7 )) {
}
if( $sent === false ) {
echo "sqlsrv_send_stream_data(5) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt7); // True
fclose($fin); // True
// read the data to make sure it's the right length
$stmt8 = sqlsrv_query($conn2, "SELECT * FROM [179886] WHERE [c1_int] = 1"); // 21
$metadata1 = sqlsrv_field_metadata($stmt8); // 94279320
$count = count($metadata1); // 28
sqlsrv_fetch($stmt8); // True
$value1 = GetField($stmt8, 13, $notWindows);
PrintNumberCharacters($value1, $notWindows);
$fout = fopen( "varchar_max.out", "w" );
fwrite( $fout, $value1 );
fclose( $fout );
$value2 = GetField($stmt8, 16, $notWindows);
PrintNumberCharacters($value2, $notWindows);
$fout = fopen( "nvarchar_max.out", "w" );
fwrite( $fout, $value2 );
fclose( $fout );
$value3 = GetField($stmt8, 17, $notWindows);
PrintNumberCharacters($value3, $notWindows);
$fout = fopen( "text.out", "w" );
fwrite( $fout, $value3 );
fclose( $fout );
$value4 = GetField($stmt8, 18, $notWindows);
PrintNumberCharacters($value4, $notWindows);
$fout = fopen( "ntext.out", "w" );
fwrite( $fout, $value4 );
fclose( $fout );
$value5 = GetField($stmt8, 27, $notWindows);
PrintNumberCharacters($value5, $notWindows);
$fout = fopen( "xml.out", "w" );
fwrite( $fout, $value5 );
fclose( $fout );
sqlsrv_free_stmt( $stmt8 );
// put the data back into the database
$stmt3 = sqlsrv_query( $conn2, "INSERT INTO [179886] ([c1_int], [c14_varchar_max], [c17_nvarchar_max], [c18_text], [c19_ntext], [c28_xml]) VALUES(?, ?, ?, ?, ?, ?)", array(2, $value1, $value2, $value3, $value4, $value5));
if( $stmt3 === false ) {
echo "sqlsrv_query(7) failed.\n";
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt3); // True
$stmt8 = sqlsrv_query($conn2, "SELECT * FROM [179886] WHERE [c1_int] = 2"); // 21
$metadata1 = sqlsrv_field_metadata($stmt8); // 94279320
$count = count($metadata1); // 28
sqlsrv_fetch($stmt8); // True
$value1 = GetField($stmt8, 13, $notWindows);
PrintNumberCharacters($value1, $notWindows);
$value2 = GetField($stmt8, 16, $notWindows);
PrintNumberCharacters($value2, $notWindows);
$value3 = GetField($stmt8, 17, $notWindows);
PrintNumberCharacters($value3, $notWindows);
$value4 = GetField($stmt8, 18, $notWindows);
PrintNumberCharacters($value4, $notWindows);
$value5 = GetField($stmt8, 27, $notWindows);
PrintNumberCharacters($value5, $notWindows);
sqlsrv_free_stmt( $stmt8 );
sqlsrv_close( $conn2 );
function GetField($stmt, $idx, $notWindows)
{
if ($notWindows)
{
return sqlsrv_get_field($stmt, $idx, SQLSRV_PHPTYPE_STRING('UTF-8'));
}
else
{
return sqlsrv_get_field($stmt, $idx, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
}
function PrintNumberCharacters($value, $notWindows)
{
if ($notWindows)
$value = utf8_decode($value);
echo strlen($value) . "\n";
}
?>
--EXPECT--
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576
1048576

View file

@ -0,0 +1,110 @@
--TEST--
Verify query timeout
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$throwaway = Connect(array( 'ConnectionPooling' => 1 ));
if( !$throwaway ) {
die( print_r( sqlsrv_errors(), true ));
}
for( $i = 1; $i <= 3; ++$i ) {
$conn = Connect(array( 'ConnectionPooling' => 1 ));
if( !$conn ) {
die( print_r( sqlsrv_errors(), true ));
}
$conn2 = Connect(array( 'ConnectionPooling' => 1 ));
if( !$conn2 ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_query_timeout', 'U') IS NOT NULL DROP TABLE [test_query_timeout]");
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "CREATE TABLE [test_query_timeout] (id int, stuff varchar(256))");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
$result = sqlsrv_begin_transaction( $conn );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query( $conn, "INSERT INTO [test_query_timeout] (id, stuff) VALUES (?,?)", array( 1, 'this is a test' ));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt2 = sqlsrv_query( $conn2, "WAITFOR DELAY '00:00:05'; SELECT * FROM [test_query_timeout]", array(null), array( 'QueryTimeout' => 1 ));
if( $stmt2 === false ) {
print_r( sqlsrv_errors() );
}
sqlsrv_rollback( $conn );
sqlsrv_query( $conn, "DROP TABLE [test_query_timeout]");
sqlsrv_close( $conn2 );
sqlsrv_close( $conn );
} // for
sqlsrv_close( $throwaway );
echo "Test succeeded.\n";
?>
--EXPECTREGEX--
Array
\(
\[0\] => Array
\(
((\[0\] => 42000)|(\[0\] => HYT00))
((\[SQLSTATE\] => 42000)|(\[SQLSTATE\] => HYT00))
((\[1\] => 1222)|(\[1\] => 0))
((\[code\] => 1222)|(\[code\] => 0))
((\[2\] => .*Lock request time out period exceeded.)|(\[2\] => .*Query timeout expired))
((\[message\] => .*Lock request time out period exceeded.)|(\[message\] => .*Query timeout expired))
\)
\)
Array
\(
\[0\] => Array
\(
((\[0\] => 42000)|(\[0\] => HYT00))
((\[SQLSTATE\] => 42000)|(\[SQLSTATE\] => HYT00))
((\[1\] => 1222)|(\[1\] => 0))
((\[code\] => 1222)|(\[code\] => 0))
((\[2\] => .*Lock request time out period exceeded.)|(\[2\] => .*Query timeout expired))
((\[message\] => .*Lock request time out period exceeded.)|(\[message\] => .*Query timeout expired))
\)
\)
Array
\(
\[0\] => Array
\(
((\[0\] => 42000)|(\[0\] => HYT00))
((\[SQLSTATE\] => 42000)|(\[SQLSTATE\] => HYT00))
((\[1\] => 1222)|(\[1\] => 0))
((\[code\] => 1222)|(\[code\] => 0))
((\[2\] => .*Lock request time out period exceeded.)|(\[2\] => .*Query timeout expired))
((\[message\] => .*Lock request time out period exceeded.)|(\[message\] => .*Query timeout expired))
\)
\)
Test succeeded.

View file

@ -0,0 +1,129 @@
--TEST--
warnings as errors
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', true );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "Warnings from sqlsrv_connect:\n";
print_r( sqlsrv_errors(SQLSRV_ERR_WARNINGS) ); // should print connection warnings and not die
echo "Errors from sqlsrv_connect:\n";
print_r( sqlsrv_errors(SQLSRV_ERR_ERRORS) );
$v1 = 1;
$v2 = 2;
$v3 = 1;
// output parameters generate warnings
$stmt = sqlsrv_query( $conn, "raiserror('This is an error', 10, 1);");
if( $stmt === false ) {
echo "Errors from raiserror\n";
print_r( sqlsrv_errors() );
}
$stmt = sqlsrv_query( $conn, "{call test_out( ?, ?, ? )}", array( $v1, $v2, array( &$v3, SQLSRV_PARAM_OUT )));
if( $stmt === false ) {
echo "Errors from sqlsrv_query with WarningsReturnAsErrors = true:\n";
print_r( sqlsrv_errors(SQLSRV_ERR_ERRORS) ); // should be 1 warning of '3'
}
echo "Warnings from sqlsrv_query with WarningsReturnAsErrors = true:\n";
print_r( sqlsrv_errors(SQLSRV_ERR_WARNINGS) ); // should be nothing
echo "Output:\n$v3\n";
sqlsrv_configure( 'WarningsReturnAsErrors', false );
$stmt = sqlsrv_query( $conn, "{call test_out( ?, ?, ? )}", array( $v1, $v2, array( &$v3, SQLSRV_PARAM_OUT )));
if( $stmt === false ) {
echo "Errors from sqlsrv_query with WarningsReturnAsErrors = false:\n";
die( print_r( sqlsrv_errors() ));
}
echo "Warnings from sqlsrv_query with WarningsReturnAsErrors = false:\n";
print_r( sqlsrv_errors() );
echo "Output:\n$v3\n";
sqlsrv_close( $conn );
print "Test successful";
?>
--EXPECTF--
Warnings from sqlsrv_connect:
Array
(
[0] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 5701
[code] => 5701
[2] => %SChanged database context to '%S'.
[message] => %SChanged database context to '%S'.
)
[1] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 5703
[code] => 5703
[2] => %SChanged language setting to us_english.
[message] => %SChanged language setting to us_english.
)
)
Errors from sqlsrv_connect:
Errors from raiserror
Array
(
[0] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 50000
[code] => 50000
[2] => %SThis is an error
[message] => %SThis is an error
)
)
Errors from sqlsrv_query with WarningsReturnAsErrors = true:
Array
(
[0] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 0
[code] => 0
[2] => %S3
[message] => %S3
)
)
Warnings from sqlsrv_query with WarningsReturnAsErrors = true:
Output:
3
Warnings from sqlsrv_query with WarningsReturnAsErrors = false:
Array
(
[0] => Array
(
[0] => 01000
[SQLSTATE] => 01000
[1] => 0
[code] => 0
[2] => %S3
[message] => %S3
)
)
Output:
3
Test successful

View file

@ -0,0 +1,160 @@
--TEST--
warnings as errors
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_prepare( $conn, "SELECT * FROM [cd_info]");
$result = sqlsrv_field_metadata( $stmt );
if( $result === false ) {
die( "sqlsrv_field_metadata should have succeeded." );
}
$result = sqlsrv_fetch( $stmt );
if( $result !== false ) {
die( "sqlsrv_fetch should have failed because it wasn't yet executed." );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_fetch_array( $stmt );
if( $result !== false ) {
die( "sqlsrv_fetch_array should have failed because it wasn't yet executed." );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_get_field( $stmt, 0 );
if( $result !== false ) {
die( "sqlsrv_get_field should have failed because it wasn't yet executed." );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_next_result( $stmt );
if( $result !== false ) {
die( "sqlsrv_next_result should have failed because it wasn't yet executed." );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_rows_affected( $stmt );
if( $result !== false ) {
die( "sqlsrv_rows_affected should have failed because it wasn't yet executed." );
}
print_r( sqlsrv_errors() );
sqlsrv_execute( $stmt );
$result = sqlsrv_field_metadata( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
print_r( sqlsrv_errors() );
$result = sqlsrv_rows_affected( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch_array( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_get_field( $stmt, 0 );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_next_result( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
print "Test successful";
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -11
[code] => -11
[2] => The statement must be executed before results can be retrieved.
[message] => The statement must be executed before results can be retrieved.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -11
[code] => -11
[2] => The statement must be executed before results can be retrieved.
[message] => The statement must be executed before results can be retrieved.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -11
[code] => -11
[2] => The statement must be executed before results can be retrieved.
[message] => The statement must be executed before results can be retrieved.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -11
[code] => -11
[2] => The statement must be executed before results can be retrieved.
[message] => The statement must be executed before results can be retrieved.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -11
[code] => -11
[2] => The statement must be executed before results can be retrieved.
[message] => The statement must be executed before results can be retrieved.
)
)
Test successful

View file

@ -0,0 +1,162 @@
--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'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "Failed to connect." );
}
$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 ));
if( !$stmt ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_prepare failed." );
}
$success = sqlsrv_execute( $stmt );
if( !$success ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_execute failed." );
}
while( $success = sqlsrv_send_stream_data( $stmt )) {
}
if( !is_null( $success )) {
sqlsrv_cancel( $stmt );
sqlsrv_free_stmt( $stmt );
die( "sqlsrv_send_stream_data failed." );
}
$result = sqlsrv_fetch( $stmt );
if( $result !== false ) {
die( "sqlsrv_fetch should have failed." );
}
print_r( sqlsrv_errors() );
$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." );
}
while( $success = sqlsrv_send_stream_data( $stmt )) {
}
if( !is_null( $success )) {
sqlsrv_cancel( $stmt );
sqlsrv_free_stmt( $stmt );
die( "sqlsrv_send_stream_data failed." );
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_prepare( $conn, "SELECT id, [double], name, stuff FROM test_params" );
$success = sqlsrv_execute( $stmt );
if( !$success ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_execute failed." );
}
while( sqlsrv_fetch( $stmt )) {
$id = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
echo "$id\n";
$double = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
echo "$double\n";
$name = sqlsrv_get_field( $stmt, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
echo "$name\n";
$stream = sqlsrv_get_field( $stmt, 3, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY) );
while( !feof( $stream )) {
$str = fread( $stream, 10000 );
echo $str;
}
echo "\n";
}
$result = sqlsrv_fetch( $stmt );
if( $result !== false ) {
die( "sqlsrv_fetch should have failed." );
}
print_r( sqlsrv_errors() );
$result = sqlsrv_next_result( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_next_result( $stmt );
if( $result !== false ) {
die( "sqlsrv_next_result should have failed." );
}
print_r( sqlsrv_errors() );
sqlsrv_query( $conn, "DROP TABLE test_params" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -28
[code] => -28
[2] => The active result for the query contains no fields.
[message] => The active result for the query contains no fields.
)
)
1
12.0
testtestte
This is some text meant to test binding parameters to streams
2
13.0
testtestte
This is some more text meant to test binding parameters to streams
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -22
[code] => -22
[2] => There are no more rows in the active result set. Since this result set is not scrollable, no more data may be retrieved.
[message] => There are no more rows in the active result set. Since this result set is not scrollable, no more data may be retrieved.
)
)
Array
(
[0] => Array
(
[0] => IMSSP
[SQLSTATE] => IMSSP
[1] => -26
[code] => -26
[2] => There are no more results returned by the query.
[message] => There are no more results returned by the query.
)
)