php-sqlsrv/test/functional/sqlsrv/sqlsrv_fetch_object_unicode_col_name1.phpt

305 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--TEST--
Test for fetch_object with Unicode column name
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
class foo
{
public $stuff = "stuff";
private $id = -1;
private $id_foo = -2;
public function __construct($a, $b)
{
echo "Creating a foo with params $a & $b\n";
}
public function do_foo()
{
echo "Doing foo. $this->id_foo $this->id $this->stuff\n";
$this->id_foo = 4;
}
}
class foo_noargs
{
public $stuff = "stuff";
private $id = -1;
private $id_foo = -2;
public function do_foo()
{
echo "Doing foo. $this->id_foo $this->id $this->stuff\n";
$this->id_foo = 4;
}
} // end class foo_noargs
sqlsrv_configure('WarningsReturnAsErrors', 0);
require_once('MsCommon.inc');
$conn = AE\connect(array( 'CharacterSet'=>'UTF-8' ));
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', '吉安而來'),
new AE\ColumnMeta('float', '此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
AE\createTable($conn, $tableName, $columns);
$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 $tableName (id, 吉安而來, [此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é], 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.");
}
$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.");
}
$f1 = 3;
$f3 = 14.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.");
}
$f1 = 4;
$f3 = 15.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.");
}
$f1 = 5;
$f3 = 16.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, [此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é], 吉安而來, stuff FROM $tableName");
$success = sqlsrv_execute($stmt);
if (!$success) {
var_dump(sqlsrv_errors());
die("sqlsrv_execute failed.");
}
echo "Fetch a stdClass object (1)\n";
$obj = sqlsrv_fetch_object($stmt);
if ($obj === false) {
die(print_r(sqlsrv_errors(), true));
}
print_r($obj);
echo "Fetch a foo_noargs object (2)\n";
$obj = sqlsrv_fetch_object($stmt, "foo_noargs");
if ($obj === false) {
die(print_r(sqlsrv_errors(), true));
}
$obj->do_foo();
print_r($obj);
echo "Fetch a foo object (with constructor args) (3)\n";
$obj = sqlsrv_fetch_object($stmt, "foo", array( 2, 1 ));
if ($obj === false) {
die(print_r(sqlsrv_errors(), true));
}
$obj->do_foo();
print_r($obj);
echo "Just create a normal foo in the script\n";
$next_obj = new foo(1, 2);
print_r($next_obj);
// this case prints out warnings for 7.0.x but not passing enough argument
// results in a fatal error for 7.1.x
echo "With no constructor arguments (4)\n";
try {
$obj = sqlsrv_fetch_object($stmt, "foo");
if ($obj === false) {
die(print_r(sqlsrv_errors(), true));
}
$obj->do_foo();
print_r($obj);
} catch (Error $e) {
echo "Caught error: " . $e->getMessage() . "\n";
}
// the case with args to an object that doesn't take them
echo "Non args constructor with args (5)\n";
$obj = sqlsrv_fetch_object($stmt, "foo_noargs", array( 1, 2 ));
if ($obj === false) {
die(print_r(sqlsrv_errors(), true));
}
if (is_null($obj)) {
echo "Done fetching objects.\n";
} else {
$obj->do_foo();
print_r($obj);
}
// the end of result set case
echo "At the end of the result set (6)\n";
$obj = sqlsrv_fetch_object($stmt, "foo");
if ($obj === false) {
die(print_r(sqlsrv_errors(), true));
}
if (is_null($obj)) {
echo "Done fetching objects.\n";
} else {
$obj->do_foo();
print_r($obj);
}
// past the end of result set case
echo "Past the end of the result set (7)\n";
$obj = sqlsrv_fetch_object($stmt, "foo");
if ($obj === false) {
print_r( sqlsrv_errors());
}
if (is_null($obj)) {
echo "Done fetching objects.\n";
} elseif ($obj) {
$obj->do_foo();
print_r($obj);
}
dropTable($conn, $tableName);
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
--EXPECTREGEX--
Fetch a stdClass object \(1\)
stdClass Object
\(
\[id\] => 1
\[此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é\] => 12
\[吉安而來\] => testtestte
\[stuff\] => This is some text meant to test binding parameters to streams
\)
Fetch a foo_noargs object \(2\)
Doing foo\. -2 2 This is some more text meant to test binding parameters to streams
foo_noargs Object
\(
\[stuff\] => This is some more text meant to test binding parameters to streams
\[id:foo_noargs:private\] => 2
\[id_foo:foo_noargs:private\] => 4
\[此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é\] => 13
\[吉安而來\] => testtestte
\)
Fetch a foo object \(with constructor args\) \(3\)
Creating a foo with params 2 & 1
Doing foo\. -2 3 This is some more text meant to test binding parameters to streams
foo Object
\(
\[stuff\] => This is some more text meant to test binding parameters to streams
\[id:foo:private\] => 3
\[id_foo:foo:private\] => 4
\[此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é\] => 14
\[吉安而來\] => testtestte
\)
Just create a normal foo in the script
Creating a foo with params 1 \& 2
foo Object
\(
\[stuff\] => stuff
\[id:foo:private\] => -1
\[id_foo:foo:private\] => -2
\)
With no constructor arguments \(4\)
(Caught error: Too few arguments to function foo::__construct\(\), 0 passed and exactly 2 expected|
Warning: Missing argument 1 for foo::__construct\(\).+sqlsrv_fetch_object_unicode_col_name1\.php.+Warning: Missing argument 2 for foo::__construct\(\).+sqlsrv_fetch_object_unicode_col_name1\.php.+Notice: Undefined variable: a in.+sqlsrv_fetch_object_unicode_col_name1\.php.+Notice: Undefined variable: b in.+sqlsrv_fetch_object_unicode_col_name1\.php.+Creating a foo with params \&.+Doing foo\. -2 4 This is some more text meant to test binding parameters to streams.+foo Object.+\(.+\[stuff\] => This is some more text meant to test binding parameters to streams.+\[id:foo:private\] => 4.+\[id_foo:foo:private\] => 4.+\[此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é\] => 15.+\[吉安而來\] => testtestte.+\))
Non args constructor with args \(5\)
Doing foo. -2 5 This is some more text meant to test binding parameters to streams
foo_noargs Object
\(
\[stuff\] => This is some more text meant to test binding parameters to streams
\[id:foo_noargs:private\] => 5
\[id_foo:foo_noargs:private\] => 4
\[此是後話Κοντάוְאַתָּה第十四章BiałopioБунтевсемужирафиtest是أي بزمام الإنذارהნომინავიiałopioБунтевсемужирафиtest父親回衙 汗流如雨 吉安而來. 關雎 誨€¥É§é\] => 16
\[吉安而來\] => testtestte
\)
At the end of the result set \(6\)
Done fetching objects\.
Past the end of the result set \(7\)
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\.
\)
\)