Remove uchar.h usage from buffered results.

This commit is contained in:
v-dareck 2017-02-20 18:11:27 -08:00
parent cc925ad9b3
commit 5951e32886
15 changed files with 1877 additions and 18 deletions

View file

@ -25,7 +25,6 @@
#ifndef _WIN32
#include <type_traits>
#include <uchar.h>
#endif // !_WIN32
@ -160,6 +159,27 @@ SQLRETURN copy_buffer( _Out_ void* buffer, SQLLEN buffer_length, _Out_ SQLLEN* o
}
#endif // !_WIN32
#ifndef _WIN32
size_t charFromUtf16(const WCHAR src, char * dest, size_t cchDest, DWORD * pErrorCode)
{
return SystemLocale::FromUtf16( CP_ACP, &src, 1, dest, cchDest, NULL, pErrorCode );
}
size_t charFromUtf16(const char src, char * dest, size_t cchDest, DWORD * pErrorCode)
{
if (cchDest > 1)
{
dest[0] = src;
dest[1] = '\0';
return 1;
}
return 0;
}
#endif // !_WIN32
// convert a number to a string using locales
// There is an extra copy here, but given the size is short (usually <20 bytes) and the complications of
// subclassing a new streambuf just to avoid the copy, it's easier to do the copy
@ -210,21 +230,20 @@ SQLRETURN number_to_string( Number* number_data, _Out_ void* buffer, SQLLEN buff
if ( std::is_same<Char, char16_t>::value )
{
std::basic_string<char16_t> str;
char *str_num_ptr = &str_num[0], *str_num_end = &str_num[0] + str_num.size();
for ( const auto &mb : str_num )
for (const auto &mb : str_num )
{
char16_t ch16;
std::mbstate_t mbs = std::mbstate_t();
int len = mbrtoc16( &ch16, &mb, str_num_end - str_num_ptr, &mbs );
if ( len > 0 || len == -3 )
size_t cch = SystemLocale::NextChar( CP_ACP, &mb ) - &mb;
if ( cch > 0 )
{
str.push_back( ch16 );
if ( len > 0 )
WCHAR ch16;
DWORD rc;
size_t cchActual = SystemLocale::ToUtf16( CP_ACP, &mb, cch, &ch16, 1, &rc);
if (cchActual > 0)
{
str_num_ptr += len;
str.push_back ( ch16 );
}
}
}
@ -262,17 +281,21 @@ SQLRETURN string_to_number( Char* string_data, SQLLEN str_len, _Out_ void* buffe
std::string str;
if ( std::is_same<Char, SQLWCHAR>::value )
{
// convert to regular character string first
char c_str[3] = "";
char c_str[4] = "";
mbstate_t mbs;
SQLLEN i = 0;
while ( string_data[i] )
{
memset( &mbs, 0, sizeof( mbs )); //set shift state to the initial state
memset( c_str, 0, sizeof( c_str ));
int len = c16rtomb( c_str, string_data[i++], &mbs ); // treat string_data as a char16_t string
str.append(std::string( c_str, len ));
{
memset( c_str, 0, sizeof( c_str ));
DWORD rc;
size_t cch = charFromUtf16( string_data[i++], c_str, sizeof( c_str ), &rc );
if (cch > 0 && rc == ERROR_SUCCESS)
{
str.append(std::string( c_str, cch ));
}
}
}
else

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a varbinary column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 'asdgasdgasdgsadg';
$query = 'CREATE TABLE #TESTTABLE (exist varbinary(max))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindParam(':p0', $sample, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(32) "61736467617364676173646773616467"
no buffered cursor, stringify off, fetch_numeric on
string(32) "61736467617364676173646773616467"
no buffered cursor, stringify on, fetch_numeric on
string(32) "61736467617364676173646773616467"
no buffered cursor, stringify on, fetch_numeric off
string(32) "61736467617364676173646773616467"
buffered cursor, stringify off, fetch_numeric off
string(32) "61736467617364676173646773616467"
buffered cursor, stringify off, fetch_numeric on
string(32) "61736467617364676173646773616467"
buffered cursor, stringify on, fetch_numeric on
string(32) "61736467617364676173646773616467"
buffered cursor, stringify on, fetch_numeric off
string(32) "61736467617364676173646773616467"

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a varchar column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = "eight";
$query = 'CREATE TABLE #TESTTABLE (exist varchar(10))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_STR);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(5) "eight"
no buffered cursor, stringify off, fetch_numeric on
string(5) "eight"
no buffered cursor, stringify on, fetch_numeric on
string(5) "eight"
no buffered cursor, stringify on, fetch_numeric off
string(5) "eight"
buffered cursor, stringify off, fetch_numeric off
string(5) "eight"
buffered cursor, stringify off, fetch_numeric on
string(5) "eight"
buffered cursor, stringify on, fetch_numeric on
string(5) "eight"
buffered cursor, stringify on, fetch_numeric off
string(5) "eight"

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a datetime column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = '2012-06-18 10:34:09';
$query = 'CREATE TABLE #TESTTABLE (exist datetime)';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindParam(':p0', $sample, PDO::PARAM_LOB);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(23) "2012-06-18 10:34:09.000"
no buffered cursor, stringify off, fetch_numeric on
string(23) "2012-06-18 10:34:09.000"
no buffered cursor, stringify on, fetch_numeric on
string(23) "2012-06-18 10:34:09.000"
no buffered cursor, stringify on, fetch_numeric off
string(23) "2012-06-18 10:34:09.000"
buffered cursor, stringify off, fetch_numeric off
string(23) "2012-06-18 10:34:09.000"
buffered cursor, stringify off, fetch_numeric on
string(23) "2012-06-18 10:34:09.000"
buffered cursor, stringify on, fetch_numeric on
string(23) "2012-06-18 10:34:09.000"
buffered cursor, stringify on, fetch_numeric off
string(23) "2012-06-18 10:34:09.000"

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a decimal column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$query = 'CREATE TABLE #TESTTABLE (exist decimal(16, 6))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(17) "1234567890.123400"
no buffered cursor, stringify off, fetch_numeric on
string(17) "1234567890.123400"
no buffered cursor, stringify on, fetch_numeric on
string(17) "1234567890.123400"
no buffered cursor, stringify on, fetch_numeric off
string(17) "1234567890.123400"
buffered cursor, stringify off, fetch_numeric off
string(17) "1234567890.123400"
buffered cursor, stringify off, fetch_numeric on
string(17) "1234567890.123400"
buffered cursor, stringify on, fetch_numeric on
string(17) "1234567890.123400"
buffered cursor, stringify on, fetch_numeric off
string(17) "1234567890.123400"

View file

@ -0,0 +1,113 @@
--TEST--
prepare with cursor buffered and fetch a decimal column with the column bound and specified to pdo type int
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$query = 'CREATE TABLE #TESTTABLE (exist decimal(18, 8))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT exist FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($decimal_col);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($decimal_col);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
int(1234567890)
no buffered cursor, stringify off, fetch_numeric on
int(1234567890)
no buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
no buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"
buffered cursor, stringify off, fetch_numeric off
int(1234567890)
buffered cursor, stringify off, fetch_numeric on
int(1234567890)
buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"

View file

@ -0,0 +1,141 @@
--TEST--
prepare with cursor buffered and fetch a float column
--SKIPIF--
--FILE--
<?php
function FlatsAreEqual($a, $b, $epsilon = 3.9265E-6)
{
return (abs($a - $b) < $epsilon);
}
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$query = 'CREATE TABLE #TESTTABLE (exist float(53))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
print "no buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
print "no buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
print "no buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
//prepare with client buffered cursor
print "buffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
print "buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
print "buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
print "buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE';
print "\nFetched value = Input? $ok\n\n";
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(15) "1234567890.1234"
Fetched value = Input? TRUE
no buffered cursor, stringify off, fetch_numeric on
float(1234567890.1234)
Fetched value = Input? TRUE
no buffered cursor, stringify on, fetch_numeric on
string(15) "1234567890.1234"
Fetched value = Input? TRUE
no buffered cursor, stringify on, fetch_numeric off
string(15) "1234567890.1234"
Fetched value = Input? TRUE
buffered cursor, stringify off, fetch_numeric off
string(15) "1234567890.1234"
Fetched value = Input? TRUE
buffered cursor, stringify off, fetch_numeric on
float(1234567890.1234)
Fetched value = Input? TRUE
buffered cursor, stringify on, fetch_numeric on
string(15) "1234567890.1234"
Fetched value = Input? TRUE
buffered cursor, stringify on, fetch_numeric off
string(15) "1234567890.1234"
Fetched value = Input? TRUE

View file

@ -0,0 +1,117 @@
--TEST--
prepare with cursor buffered and fetch a float column with the column bound and specified to type LOB
--SKIPIF--
--FILE--
<?php
function FlatsAreEqual($a, $b, $epsilon = 3.9265E-6)
{
return (abs($a - $b) < $epsilon);
}
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$query = 'CREATE TABLE #TESTTABLE (exist float(53))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT exist FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB);
$value = $stmt->fetch();
var_dump ($float_col);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(15) "1234567890.1234"
no buffered cursor, stringify off, fetch_numeric on
string(15) "1234567890.1234"
no buffered cursor, stringify on, fetch_numeric on
string(15) "1234567890.1234"
no buffered cursor, stringify on, fetch_numeric off
string(15) "1234567890.1234"
buffered cursor, stringify off, fetch_numeric off
string(15) "1234567890.1234"
buffered cursor, stringify off, fetch_numeric on
string(15) "1234567890.1234"
buffered cursor, stringify on, fetch_numeric on
string(15) "1234567890.1234"
buffered cursor, stringify on, fetch_numeric off
string(15) "1234567890.1234"

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a int column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890;
$query = 'CREATE TABLE #TESTTABLE (exist int)';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(10) "1234567890"
no buffered cursor, stringify off, fetch_numeric on
int(1234567890)
no buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
no buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"
buffered cursor, stringify off, fetch_numeric off
string(10) "1234567890"
buffered cursor, stringify off, fetch_numeric on
int(1234567890)
buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"

View file

@ -0,0 +1,114 @@
--TEST--
prepare with cursor buffered and fetch a int column with the column bound and specified as pdo type int
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890;
$query = 'CREATE TABLE #TESTTABLE (exist int)';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT exist FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT);
$value = $stmt->fetch( PDO::FETCH_BOUND );
var_dump ($int_col);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
int(1234567890)
no buffered cursor, stringify off, fetch_numeric on
int(1234567890)
no buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
no buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"
buffered cursor, stringify off, fetch_numeric off
int(1234567890)
buffered cursor, stringify off, fetch_numeric on
int(1234567890)
buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a money column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$query = 'CREATE TABLE #TESTTABLE (exist money)';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(15) "1234567890.1234"
no buffered cursor, stringify off, fetch_numeric on
string(15) "1234567890.1234"
no buffered cursor, stringify on, fetch_numeric on
string(15) "1234567890.1234"
no buffered cursor, stringify on, fetch_numeric off
string(15) "1234567890.1234"
buffered cursor, stringify off, fetch_numeric off
string(15) "1234567890.1234"
buffered cursor, stringify off, fetch_numeric on
string(15) "1234567890.1234"
buffered cursor, stringify on, fetch_numeric on
string(15) "1234567890.1234"
buffered cursor, stringify on, fetch_numeric off
string(15) "1234567890.1234"

View file

@ -0,0 +1,115 @@
--TEST--
prepare with cursor buffered and fetch a money column with the column bound and specified as pdo type int
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$query = 'CREATE TABLE #TESTTABLE (exist money)';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT exist FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT);
$value = $stmt->fetch(PDO::FETCH_BOUND);
var_dump ($money_col);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
int(1234567890)
no buffered cursor, stringify off, fetch_numeric on
int(1234567890)
no buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
no buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"
buffered cursor, stringify off, fetch_numeric off
int(1234567890)
buffered cursor, stringify off, fetch_numeric on
int(1234567890)
buffered cursor, stringify on, fetch_numeric on
string(10) "1234567890"
buffered cursor, stringify on, fetch_numeric off
string(10) "1234567890"

View file

@ -0,0 +1,269 @@
--TEST--
prepare with cursor buffered and fetch a float column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = 1234567890.1234;
$sample1 = -1234567890.1234;
$sample2 = 1;
$sample3 = -1;
$sample4 = 0.5;
$sample5 = -0.55;
$query = 'CREATE TABLE #TESTTABLE (a float(53), neg_a float(53), b int, neg_b int, c decimal(16, 6), neg_c decimal(16, 6), zero int, zerof float(53), zerod decimal(16,6))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0, :p1, :p2, :p3, :p4, :p5, 0, 0, 0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_INT);
$stmt->bindValue(':p1', $sample1, PDO::PARAM_INT);
$stmt->bindValue(':p2', $sample2, PDO::PARAM_INT);
$stmt->bindValue(':p3', $sample3, PDO::PARAM_INT);
$stmt->bindValue(':p4', $sample4, PDO::PARAM_INT);
$stmt->bindValue(':p5', $sample5, PDO::PARAM_INT);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "\nno buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
array(9) {
[0]=>
string(15) "1234567890.1234"
[1]=>
string(16) "-1234567890.1234"
[2]=>
string(1) "1"
[3]=>
string(2) "-1"
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
string(1) "0"
[7]=>
string(3) "0.0"
[8]=>
string(7) ".000000"
}
no buffered cursor, stringify off, fetch_numeric on
array(9) {
[0]=>
float(1234567890.1234)
[1]=>
float(-1234567890.1234)
[2]=>
int(1)
[3]=>
int(-1)
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
int(0)
[7]=>
float(0)
[8]=>
string(7) ".000000"
}
no buffered cursor, stringify on, fetch_numeric on
array(9) {
[0]=>
string(15) "1234567890.1234"
[1]=>
string(16) "-1234567890.1234"
[2]=>
string(1) "1"
[3]=>
string(2) "-1"
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
string(1) "0"
[7]=>
string(1) "0"
[8]=>
string(7) ".000000"
}
no buffered cursor, stringify on, fetch_numeric off
array(9) {
[0]=>
string(15) "1234567890.1234"
[1]=>
string(16) "-1234567890.1234"
[2]=>
string(1) "1"
[3]=>
string(2) "-1"
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
string(1) "0"
[7]=>
string(3) "0.0"
[8]=>
string(7) ".000000"
}
buffered cursor, stringify off, fetch_numeric off
array(9) {
[0]=>
string(15) "1234567890.1234"
[1]=>
string(16) "-1234567890.1234"
[2]=>
string(1) "1"
[3]=>
string(2) "-1"
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
string(1) "0"
[7]=>
string(1) "0"
[8]=>
string(7) ".000000"
}
buffered cursor, stringify off, fetch_numeric on
array(9) {
[0]=>
float(1234567890.1234)
[1]=>
float(-1234567890.1234)
[2]=>
int(1)
[3]=>
int(-1)
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
int(0)
[7]=>
float(0)
[8]=>
string(7) ".000000"
}
buffered cursor, stringify on, fetch_numeric on
array(9) {
[0]=>
string(15) "1234567890.1234"
[1]=>
string(16) "-1234567890.1234"
[2]=>
string(1) "1"
[3]=>
string(2) "-1"
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
string(1) "0"
[7]=>
string(1) "0"
[8]=>
string(7) ".000000"
}
buffered cursor, stringify on, fetch_numeric off
array(9) {
[0]=>
string(15) "1234567890.1234"
[1]=>
string(16) "-1234567890.1234"
[2]=>
string(1) "1"
[3]=>
string(2) "-1"
[4]=>
string(7) ".500000"
[5]=>
string(8) "-.550000"
[6]=>
string(1) "0"
[7]=>
string(1) "0"
[8]=>
string(7) ".000000"
}

View file

@ -0,0 +1,232 @@
--TEST--
prepare with cursor buffered and fetch various columns with the column bound and specified to pdo type int
--SKIPIF--
--FILE--
<?php
function test()
{
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$decimal = -2345209.3103;
$numeric = 987234.9919;
$salary = "3456789.15";
$debt = "98765.99";
$query = 'CREATE TABLE #TESTTABLE ([c_decimal] decimal(28,4), [c_numeric] numeric(32,4), [c_varchar] varchar(20), [c_nvarchar] nvarchar(20))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0, :p1, :p2, :p3)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $decimal);
$stmt->bindValue(':p1', $numeric);
$stmt->bindValue(':p2', $salary);
$stmt->bindValue(':p3', $debt);
$stmt->execute();
$decimal2 = $decimal * 2;
$numeric2 = $numeric * 2;
$salary2 = $salary * 2;
$debt2 = $debt * 2;
$stmt->bindValue(':p0', $decimal2);
$stmt->bindValue(':p1', $numeric2);
$stmt->bindValue(':p2', $salary2);
$stmt->bindValue(':p3', $debt2);
$stmt->execute();
$decimal3 = $decimal * 3;
$numeric3 = $numeric * 3;
$salary3 = $salary * 3;
$debt3 = $debt * 3;
$stmt->bindValue(':p0', $decimal3);
$stmt->bindValue(':p1', $numeric3);
$stmt->bindValue(':p2', $salary3);
$stmt->bindValue(':p3', $debt3);
$stmt->execute();
$stmt = null;
echo ("Input values:\n\torginal:$decimal\t$numeric\t$salary\t$debt\n\tdoubles:$decimal2\t$numeric2\t$salary2\t$debt2\n\ttriples:$decimal3\t$numeric3\t$salary3\t$debt3\n");
$query = 'SELECT * FROM #TESTTABLE';
// prepare with no buffered cursor
echo "\n\nComparing results (stringify off, fetch_numeric on):\n";
// no buffered cursor, stringify off, fetch_numeric on
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt1 = $conn->prepare($query);
$stmt1->execute();
// buffered cursor, stringify off, fetch_numeric on
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt2 = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt2->execute();
compareResults($stmt1, $stmt2);
$stmt1 = null;
$stmt2 = null;
echo "\n\nComparing results (stringify off, fetch_numeric off):\n";
// no buffered cursor, stringify off, fetch_numeric off
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt1 = $conn->prepare($query);
$stmt1->execute();
// buffered cursor, stringify off, fetch_numeric off
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt2 = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt2->execute();
compareResults($stmt1, $stmt2);
$stmt1 = null;
$stmt2 = null;
$conn = null;
}
function compareResults($stmt1, $stmt2)
{
$stmt1->bindColumn('c_decimal', $decimal_col1, PDO::PARAM_INT);
$stmt1->bindColumn('c_numeric', $numeric_col1, PDO::PARAM_INT);
$stmt1->bindColumn('c_varchar', $salary_col1, PDO::PARAM_INT);
$stmt1->bindColumn('c_nvarchar', $debt_col1, PDO::PARAM_INT);
$stmt2->bindColumn('c_decimal', $decimal_col2, PDO::PARAM_INT);
$stmt2->bindColumn('c_numeric', $numeric_col2, PDO::PARAM_INT);
$stmt2->bindColumn('c_varchar', $salary_col2, PDO::PARAM_INT);
$stmt2->bindColumn('c_nvarchar', $debt_col2, PDO::PARAM_INT);
$numRows = 3;
for ($i = 1; $i <= $numRows; $i++)
{
echo "\nreading row " . $i . "\n";
$value1 = $stmt1->fetch( PDO::FETCH_BOUND );
$value2 = $stmt2->fetch( PDO::FETCH_BOUND );
compareData($decimal_col1, $decimal_col2);
compareData($numeric_col1, $numeric_col2);
compareData($salary_col1, $salary_col2);
compareData($debt_col1, $debt_col2);
}
}
function compareData($data1, $data2)
{
if ($data1 != $data2)
echo "Not matched!\n";
else
echo "Matched!\n";
echo ("\tExpected: "); var_dump ($data1);
echo ("\tActual: "); var_dump ($data2);
}
test();
?>
--EXPECT--
Input values:
orginal:-2345209.3103 987234.9919 3456789.15 98765.99
doubles:-4690418.6206 1974469.9838 6913578.3 197531.98
triples:-7035627.9309 2961704.9757 10370367.45 296297.97
Comparing results (stringify off, fetch_numeric on):
reading row 1
Matched!
Expected: int(-2345209)
Actual: int(-2345209)
Matched!
Expected: int(987234)
Actual: int(987234)
Matched!
Expected: int(3456789)
Actual: int(3456789)
Matched!
Expected: int(98765)
Actual: int(98765)
reading row 2
Matched!
Expected: int(-4690418)
Actual: int(-4690418)
Matched!
Expected: int(1974469)
Actual: int(1974469)
Matched!
Expected: int(6913578)
Actual: int(6913578)
Matched!
Expected: int(197531)
Actual: int(197531)
reading row 3
Matched!
Expected: int(-7035627)
Actual: int(-7035627)
Matched!
Expected: int(2961704)
Actual: int(2961704)
Matched!
Expected: int(10370367)
Actual: int(10370367)
Matched!
Expected: int(296297)
Actual: int(296297)
Comparing results (stringify off, fetch_numeric off):
reading row 1
Matched!
Expected: int(-2345209)
Actual: int(-2345209)
Matched!
Expected: int(987234)
Actual: int(987234)
Matched!
Expected: int(3456789)
Actual: int(3456789)
Matched!
Expected: int(98765)
Actual: int(98765)
reading row 2
Matched!
Expected: int(-4690418)
Actual: int(-4690418)
Matched!
Expected: int(1974469)
Actual: int(1974469)
Matched!
Expected: int(6913578)
Actual: int(6913578)
Matched!
Expected: int(197531)
Actual: int(197531)
reading row 3
Matched!
Expected: int(-7035627)
Actual: int(-7035627)
Matched!
Expected: int(2961704)
Actual: int(2961704)
Matched!
Expected: int(10370367)
Actual: int(10370367)
Matched!
Expected: int(296297)
Actual: int(296297)

View file

@ -0,0 +1,105 @@
--TEST--
prepare with cursor buffered and fetch a nvarchar column
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sample = "가각";
$query = 'CREATE TABLE #TESTTABLE (exist nvarchar(10))';
$stmt = $conn->exec($query);
$query = 'INSERT INTO #TESTTABLE VALUES(:p0)';
$stmt = $conn->prepare($query);
$stmt->bindValue(':p0', $sample, PDO::PARAM_STR);
$stmt->execute();
$query = 'SELECT TOP 1 * FROM #TESTTABLE';
//prepare with no buffered cursor
print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nno buffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query);
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
//prepare with client buffered cursor
print "\nbuffered cursor, stringify off, fetch_numeric off\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify off, fetch_numeric on\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric on\n";
$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
print "\nbuffered cursor, stringify on, fetch_numeric off\n";
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false);
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
$stmt = null;
$conn = null;
?>
--EXPECT--
no buffered cursor, stringify off, fetch_numeric off
string(6) "가각"
no buffered cursor, stringify off, fetch_numeric on
string(6) "가각"
no buffered cursor, stringify on, fetch_numeric on
string(6) "가각"
no buffered cursor, stringify on, fetch_numeric off
string(6) "가각"
buffered cursor, stringify off, fetch_numeric off
string(6) "가각"
buffered cursor, stringify off, fetch_numeric on
string(6) "가각"
buffered cursor, stringify on, fetch_numeric on
string(6) "가각"
buffered cursor, stringify on, fetch_numeric off
string(6) "가각"