Merge pull request #605 from Microsoft/dev

Dev
This commit is contained in:
Yuki Wong 2017-11-24 11:10:30 -08:00 committed by GitHub
commit 7d3ed0cd54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
185 changed files with 8672 additions and 6954 deletions

View file

@ -3,6 +3,34 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
## Windows/Linux/macOS 5.1.2-preview - 2017-11-21
Updated PECL release packages. Here is the list of updates:
### Fixed
- Support for non-UTF8 locales in Linux and macOS
- Fixed crash caused by executing an invalid query in a transaction (Issue [#434](https://github.com/Microsoft/msphpsql/issues/434))
- Fixed regression in sqlsrv_next_result returning a no fields error when the active result set is null (Issue [#581](https://github.com/Microsoft/msphpsql/issues/581))
- Fixed incorrect active result set when sqlsrv_next_result or PDOStatement::nextRowset is called when Column Encryption is enabled (Issue [#574](https://github.com/Microsoft/msphpsql/issues/574))
- Fixed data corruption in fetching from an encrypted max column after calling sqlsrv_next_result or PDOStatemet::nextRowset (Issue [#580](https://github.com/Microsoft/msphpsql/issues/580))
- Added error handling for using PDO::SQLSRV_ATTR_DIRECT_QUERY or PDO::ATTR_EMULATE_PREPARES in a Column Encryption enabled connection
- Added error handling for binding TEXT, NTEXT or IMAGE as output parameter (Issue [#231](https://github.com/Microsoft/msphpsql/issues/231))
### Limitations
- In Linux and macOS, setlocale() only takes effect if it is invoked before the first connection. The subsequent locale setting will not work
- Always Encrypted functionalities are only supported using [MSODBC 17 preview](https://github.com/Microsoft/msphpsql/tree/dev/ODBC%2017%20binaries%20preview)
- ODBC binaries for macOS available upon request
- MSODBC 17 preview msodbcsql.msi only works in Windows10
- [Always Encrypted limitations](https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation)
- When using sqlsrv_query with Always Encrypted feature, SQL type has to be specified for each input (see [here](https://github.com/Microsoft/msphpsql/wiki/Features#aebindparam))
- No support for inout / output params when using sql_variant type
### Known Issues
- Binding decimal input as a string when Column Encryption is enabled may change the precision of the input
- Connection pooling on Linux doesn't work properly when using the MSODBC17 preview
- When pooling is enabled in Linux or macOS
- unixODBC <= 2.3.4 (Linux and macOS) might not return proper diagnostics information, such as error messages, warnings and informative messages
- due to this unixODBC bug, fetch large data (such as xml, binary) as streams as a workaround. See the examples [here](https://github.com/Microsoft/msphpsql/wiki/Connection-Pooling-on-Linux-and-Mac)
## Windows/Linux 5.1.1-preview - 2017-10-20
Updated PECL release packages. Here is the list of updates:

View file

@ -9,6 +9,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \
apt-utils \
autoconf \
curl \
libcurl3 \
g++ \
gcc \
git \
@ -28,17 +29,14 @@ ENV TEST_PHP_SQL_SERVER sql
ENV TEST_PHP_SQL_UID sa
ENV TEST_PHP_SQL_PWD Password123
# add locale iso-8859-1
RUN sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
RUN locale-gen en_US
# set locale to utf-8
RUN locale-gen en_US.UTF-8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
#install ODBC driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools
ENV PATH="/opt/mssql-tools/bin:${PATH}"
#install coveralls
RUN pip install --upgrade pip && pip install cpp-coveralls
@ -47,8 +45,14 @@ RUN pip install --upgrade pip && pip install cpp-coveralls
#another option is to copy source to build directory on image
RUN mkdir -p $PHPSQLDIR
COPY . $PHPSQLDIR
WORKDIR $PHPSQLDIR/source/
#install ODBC 17 preview driver
WORKDIR $PHPSQLDIR
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y dpkg -i "./ODBC 17 binaries preview/Ubuntu 16/msodbcsql_17.0.0.1-1_amd64.deb"
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y dpkg -i "./ODBC 17 binaries preview/Ubuntu 16/mssql-tools_17.0.0.1-1_amd64.deb"
ENV PATH="/opt/mssql-tools/bin:${PATH}"
WORKDIR $PHPSQLDIR/source/
RUN chmod +x ./packagize.sh
RUN /bin/bash -c "./packagize.sh"
@ -79,4 +83,4 @@ RUN chmod +x ./entrypoint.sh
CMD /bin/bash ./entrypoint.sh
ENV REPORT_EXIT_STATUS 1
ENV TEST_PHP_EXECUTABLE /usr/bin/php
ENV TEST_PHP_EXECUTABLE /usr/bin/php

View file

@ -35,6 +35,7 @@ Thank you for taking time to take our February survey. Let us know how we are do
* [**RedHat + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel)
* [**SUSE + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/sles)
* [**Windows + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows)
* [**macOS + SQL Server + PHP 7**](https://www.microsoft.com/en-us/sql-server/developer-get-started/php/mac/)
* [**Docker**](https://hub.docker.com/r/lbosqmsft/mssql-php-msphpsql/)
@ -266,6 +267,11 @@ On Ubuntu, Debian, and SUSE systems only, run:
sudo pear config-set php_ini `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` system
On macOS, run:
chmod -R ug+w /usr/local/opt/php71/lib/php
pear config-set php_ini /usr/local/etc/php/7.1/php.ini system
On all systems, run:
pecl install sqlsrv

View file

@ -1,5 +1,5 @@
version: '{branch}.{build}'
branches:
# whitelist
#only:
@ -17,63 +17,63 @@ environment:
PDOSQLSRV_DBNAME: msphpsql_pdosqlsrv
PHP_DEPSVER: 7.0
PHP_SDK: c:\projects\php
matrix:
matrix:
- BUILD_PLATFORM: x86
TEST_PHP_SQL_SERVER: (local)\SQL2016
SQL_INSTANCE: SQL2016
PHP_VC: 14
PHP_MAJOR_VER: 7.1
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x86
PHP_INSTALL_DIR: c:\projects\php\x86\bin
platform: x86
- BUILD_PLATFORM: x64
TEST_PHP_SQL_SERVER: (local)\SQL2012SP1
SQL_INSTANCE: SQL2012SP1
PHP_VC: 14
PHP_MAJOR_VER: 7.0
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x64
PHP_INSTALL_DIR: c:\projects\php\x64\bin
PHP_ZTS: --disable-zts
platform: x64
- BUILD_PLATFORM: x86
TEST_PHP_SQL_SERVER: (local)\SQL2014
SQL_INSTANCE: SQL2014
PHP_VC: 14
PHP_MAJOR_VER: 7.0
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x86
PHP_INSTALL_DIR: c:\projects\php\x86\bin
platform: x86
- BUILD_PLATFORM: x86
TEST_PHP_SQL_SERVER: (local)\SQL2008R2SP2
SQL_INSTANCE: SQL2008R2SP2
PHP_VC: 14
PHP_MAJOR_VER: 7.1
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x86
PHP_INSTALL_DIR: c:\projects\php\x86\bin
PHP_ZTS: --disable-zts
platform: x86
- BUILD_PLATFORM: x64
TEST_PHP_SQL_SERVER: (local)\SQL2012SP1
SQL_INSTANCE: SQL2012SP1
PHP_VC: 14
PHP_MAJOR_VER: 7.0
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x64
PHP_INSTALL_DIR: c:\projects\php\x64\bin
platform: x64
- BUILD_PLATFORM: x64
TEST_PHP_SQL_SERVER: (local)\SQL2014
SQL_INSTANCE: SQL2014
PHP_VC: 14
PHP_MAJOR_VER: 7.1
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x64
PHP_INSTALL_DIR: c:\projects\php\x64\bin
platform: x64
- BUILD_PLATFORM: x86
TEST_PHP_SQL_SERVER: (local)\SQL2008R2SP2
SQL_INSTANCE: SQL2008R2SP2
PHP_VC: 14
PHP_MAJOR_VER: 7.0
PHP_MINOR_VER: latest
PHP_SDK_DIR: c:\projects\php\x86
PHP_INSTALL_DIR: c:\projects\php\x86\bin
PHP_ZTS: --disable-zts
platform: x86
# PHP_MAJOR_VER is PHP major version to build (7.0, 7.1)
# PHP_MINOR_VER is PHP point release number (or latest for latest release)
# PHP_MINOR_VER is PHP point release number (or latest for latest release)
# PHP_INSTALL_DIR is where the built PHP binaries go
# PHP_SDK_DIR is where PHP source is extracted to (e.g. PHP_SDK_DIR\php-7.0.14-src)
# PHP_SDK is where PHP sdk binary tools are extracted to
# PHP_VC is the Visual C++ version
# PHP_ZTS is defined to disable thread safe build
# Build worker image (VM template)
image: Visual Studio 2015
matrix:
fast_finish: true
#services:
#- mssql2012sp1
# clone directory (or %APPVEYOR_BUILD_FOLDER%)
clone_folder: c:\projects\sqlphp
@ -102,12 +102,12 @@ install:
# determine latest PHP versions
- ps: >-
If ($env:PHP_MINOR_VER -Match "latest") {
$env:PHP_VERSION=type sha1sum.txt | where { $_ -match "php-($env:PHP_MAJOR_VER\.\d+)-src" } | foreach { $matches[1] } ;
$env:PHP_VERSION=type sha1sum.txt | where { $_ -match "php-($env:PHP_MAJOR_VER\.\d+)-src" } | foreach { $matches[1] } ;
} Else {
$env:PHP_VERSION=$env:PHP_MAJOR_VER + '.' + $env:PHP_MINOR_VER;
}
- echo Downloading PHP-SDK
- appveyor DownloadFile http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip
- appveyor DownloadFile http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip
- move php-sdk-binary-tools-20110915.zip ..
- echo Downloading PHP source code [%PHP_VERSION%]
- ps: (new-object net.webclient).DownloadFile('http://windows.php.net/downloads/releases/php-' + ${env:PHP_VERSION} + '-src.zip', ${env:APPVEYOR_BUILD_FOLDER} + '\..\php.zip')
@ -115,7 +115,7 @@ install:
# AppVeyor build works are x64 VMs and 32-bit ODBC driver cannot be installed on it
- ps: (new-object net.webclient).DownloadFile('https://download.microsoft.com/download/D/5/E/D5EEF288-A277-45C8-855B-8E2CB7E25B96/x64/msodbcsql.msi', 'c:\projects\msodbcsql.msi')
- cmd /c start /wait msiexec /i "c:\projects\msodbcsql.msi" /q
- echo Checking the version of MSODBCSQL
- echo Checking the version of MSODBCSQL
- reg query "HKLM\SOFTWARE\ODBC\odbcinst.ini\ODBC Driver 13 for SQL Server"
- dir C:\Windows\System32\msodbcsql13.dll
- cd ..
@ -127,31 +127,29 @@ install:
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv\MsSetup.inc
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv\MsSetup.inc) | ForEach-Object { $_ -replace "TARGET_SERVER", ${env:TEST_PHP_SQL_SERVER} -replace "TARGET_DATABASE", ${env:SQLSRV_DBNAME} -replace "TARGET_USERNAME", ${env:TEST_PHP_SQL_UID} -replace "TARGET_PASSWORD", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv\MsSetup.inc
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv\MsSetup.inc
- appveyor DownloadFile http://github.com/OpenCppCoverage/OpenCppCoverage/releases/download/release-0.9.6.1/OpenCppCoverageSetup-x64-0.9.6.1.exe
- OpenCppCoverageSetup-x64-0.9.6.1.exe /VERYSILENT
- ps: ls "c:\Program Files"
- set CPPCOVER="C:\\Program Files\\OpenCppCoverage"
- set PATH=%CPPCOVER%;%PATH%
- echo install opencppcoverage
- choco install opencppcoverage
- set path=C:\Program Files\OpenCppCoverage;%path%
build_script:
- '"C:\\Program Files (x86)\\Microsoft Visual Studio %PHP_VC%.0\\VC\\vcvarsall.bat" %BUILD_PLATFORM%'
- Echo copy msphp code to ext folder
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv\shared
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv\shared
- copy /Y %APPVEYOR_BUILD_FOLDER%\source\sqlsrv %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv
- copy /Y %APPVEYOR_BUILD_FOLDER%\source\shared %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv\shared
- copy /Y %APPVEYOR_BUILD_FOLDER%\source\shared %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv\shared
- copy /Y %APPVEYOR_BUILD_FOLDER%\source\pdo_sqlsrv %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv
- copy /Y %APPVEYOR_BUILD_FOLDER%\source\pdo_sqlsrv %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv
- cd %PHP_SDK_DIR%\php-%PHP_VERSION%-src
- cd
- dir
- dir
- '%PHP_SDK%\bin\phpsdk_setvars.bat'
- buildconf.bat
# only build CLI and MSSQL extensions
- configure.bat --disable-all %PHP_ZTS% --enable-cli --enable-sqlsrv=shared --with-pdo-sqlsrv=shared --enable-pdo=shared --with-prefix=%PHP_INSTALL_DIR%
- copy php.ini-development php.ini
- copy php.ini-development php.ini
- echo extension_dir=%PHP_INSTALL_DIR%\ext >> php.ini
- echo extension=php_sqlsrv.dll >> php.ini
- echo extension=php_pdo_sqlsrv.dll >> php.ini
@ -160,57 +158,67 @@ build_script:
- Echo copy php.ini and run-tests.php from php source to install directory.
- copy php.ini %PHP_INSTALL_DIR%
- copy run-tests.php %PHP_INSTALL_DIR%
- dir %PHP_INSTALL_DIR%
- dir %PHP_INSTALL_DIR%
test_script:
- cd %PHP_INSTALL_DIR%
- cd %PHP_INSTALL_DIR%
- php --ini
- php -i
- python -V
- python -V
- Echo setup test database for SQLSRV tests - %SQLSRV_DBNAME%
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\setup_dbs.py -dbname %SQLSRV_DBNAME%
- Echo setup test database for PDO_SQLSRV tests - %PDOSQLSRV_DBNAME%
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\setup_dbs.py -dbname %PDOSQLSRV_DBNAME%
- copy %APPVEYOR_BUILD_FOLDER%\source\shared\msodbcsql.h %APPVEYOR_BUILD_FOLDER%\test\functional\setup\
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\build_ksp.py
- copy %APPVEYOR_BUILD_FOLDER%\test\functional\setup\*.dll %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv\
- copy %APPVEYOR_BUILD_FOLDER%\test\functional\setup\*.dll %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv\
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\run_ksp.py -server %TEST_PHP_SQL_SERVER% -dbname %SQLSRV_DBNAME% -uid %TEST_PHP_SQL_UID% -pwd %TEST_PHP_SQL_PWD%
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\run_ksp.py -server %TEST_PHP_SQL_SERVER% -dbname %PDOSQLSRV_DBNAME% -uid %TEST_PHP_SQL_UID% -pwd %TEST_PHP_SQL_PWD%
- php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv.log 2>&1
- type %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv.log
- php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv.log 2>&1
- type %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv.log
- cd %APPVEYOR_BUILD_FOLDER%\test\functional\
- ps: $difffiles = Get-ChildItem sqlsrv\*.diff
- ps: $outfiles = Get-ChildItem sqlsrv\*.out
- ps: foreach($file in $difffiles){ls $file; more $file}
- ps: foreach($file in $outfiles){ls $file; more $file}
- ps: $difffiles = Get-ChildItem pdo_sqlsrv\*.diff
- ps: $outfiles = Get-ChildItem pdo_sqlsrv\*.out
- ps: foreach($file in $difffiles){ls $file; more $file}
- ps: foreach($file in $outfiles){ls $file; more $file}
- cd %PHP_INSTALL_DIR%
- OpenCppCoverage.exe --sources %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv --sources %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv --modules *sqlsrv*.dll --export_type=cobertura:.\coverage.xml --cover_children --quiet --continue_after_cpp_exception --optimized_build -- .\php.exe .\run-tests.php -P %APPVEYOR_BUILD_FOLDER%\test\functional\
- ls
#- copy %APPVEYOR_BUILD_FOLDER%\source\shared\msodbcsql.h %APPVEYOR_BUILD_FOLDER%\test\functional\setup\
#- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\build_ksp.py
#- copy %APPVEYOR_BUILD_FOLDER%\test\functional\setup\*.dll %APPVEYOR_BUILD_FOLDER%\test\functional\sqlsrv\
#- copy %APPVEYOR_BUILD_FOLDER%\test\functional\setup\*.dll %APPVEYOR_BUILD_FOLDER%\test\functional\pdo_sqlsrv\
#- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\run_ksp.py -server %TEST_PHP_SQL_SERVER% -dbname %SQLSRV_DBNAME% -uid %TEST_PHP_SQL_UID% -pwd %TEST_PHP_SQL_PWD%
#- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\run_ksp.py -server %TEST_PHP_SQL_SERVER% -dbname %PDOSQLSRV_DBNAME% -uid %TEST_PHP_SQL_UID% -pwd %TEST_PHP_SQL_PWD%
- ps: >-
If ($env:SQL_INSTANCE -Match "SQL2016") {
Write-Host "Running phpt tests via OpenCppCoverage..."
$ext_dir = ${env:PHP_SDK_DIR} + "\php-" + ${env:PHP_VERSION} + "-src\ext";
OpenCppCoverage.exe --sources $ext_dir\sqlsrv --sources $ext_dir\pdo_sqlsrv --modules ext\php_sqlsrv.dll --modules ext\php_pdo_sqlsrv.dll --export_type=cobertura:.\coverage.xml --quiet --cover_children --continue_after_cpp_exception --optimized_build -- .\php.exe run-tests.php -P ${env:APPVEYOR_BUILD_FOLDER}\test\functional\ | out-file -filePath ${env:APPVEYOR_BUILD_FOLDER}\test\functional\tests.log -encoding UTF8;
type ${env:APPVEYOR_BUILD_FOLDER}\test\functional\tests.log;
ls *.xml
} Else {
Write-Host "Running phpt tests the regular way..."
.\php.exe run-tests.php -P ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv\*.phpt | out-file -filePath ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv.log -encoding UTF8;
type ${env:APPVEYOR_BUILD_FOLDER}\test\functional\sqlsrv.log;
.\php.exe run-tests.php -P ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv\*.phpt | out-file -filePath ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv.log -encoding UTF8;
type ${env:APPVEYOR_BUILD_FOLDER}\test\functional\pdo_sqlsrv.log;
}
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\cleanup_dbs.py -dbname %SQLSRV_DBNAME%
- python %APPVEYOR_BUILD_FOLDER%\test\functional\setup\cleanup_dbs.py -dbname %PDOSQLSRV_DBNAME%
- pip install codecov
- codecov -f ".\coverage.xml"
- cd %PHP_INSTALL_DIR%
- ps: $fileExists = Test-Path "coverage.xml"
- ps: >-
If ($fileExists -eq $true) {
Write-Host "Running coverage analysis...";
$env:PATH = ${env:PHP_INSTALL_DIR} + $env:PATH;
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
bash codecov.sh -f "coverage.xml"
}
after_test:
- cd %APPVEYOR_BUILD_FOLDER%\test\functional\
- python output.py
- ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult1.xml))
- ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult2.xml))
- ps: >-
[xml]$results = Get-Content nativeresult1.xml ;
[xml]$results2 = Get-Content nativeresult2.xml ;
$failure = $results.SelectSingleNode("//failure");
$failure2 = $results2.SelectSingleNode("//failure");
if ($failure -ne $null -Or $failure2 -ne $null)
{
- cd %APPVEYOR_BUILD_FOLDER%\test\functional\
- ps: ls *.log
- python output.py
- ps: $difffiles = Get-ChildItem sqlsrv\*.diff
- ps: $outfiles = Get-ChildItem sqlsrv\*.out
- ps: foreach($file in $difffiles){ls $file; more $file}
- ps: foreach($file in $outfiles){ls $file; more $file}
- ps: $diff2files = Get-ChildItem pdo_sqlsrv\*.diff
- ps: $out2files = Get-ChildItem pdo_sqlsrv\*.out
- ps: foreach($file in $diff2files){ls $file; more $file}
- ps: foreach($file in $out2files){ls $file; more $file}
- cd %APPVEYOR_BUILD_FOLDER%\test\functional\
- ps: $xmlfiles = Get-ChildItem *.xml
- ps: foreach($file in $xmlfiles){(new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $file))}
- ps: >-
If ($difffiles -ne $null -Or $diff2files -ne $null) {
$host.SetShouldExit(1);
Write-Host "Forcing build failure due to phpt unit test failure(s)";
}

View file

@ -1,26 +1,27 @@
## Driver version or file name
Please tell us what the PHP driver version or file name is.
## SQL Server version
Please tell us what the SQL Server version is.
## Client operating system
Please tell us what oprating system the client program is running on.
## PHP version
Please tell us which version of PHP you are running.
## Microsoft ODBC Driver version
Please tell us which version of the Microsoft ODBC Driver you are using.
## Table schema
Please tell us the table schema
## Problem description
Please share more details with us.
## Expected behavior and actual behavior
Please tell us what should happen and what happened instead
## Repro code
Please share repro code with us, or tell us how to reproduce the issue.
+## Driver version or file name
+Please tell us what the PHP driver version or file name is.
+
+## SQL Server version
+Please tell us what the SQL Server version is.
+
+## Client operating system
+Please tell us what oprating system the client program is running on.
+
+## PHP version
+Please tell us which version of PHP you are running.
+
+## Microsoft ODBC Driver version
+Please tell us which version of the Microsoft ODBC Driver you are using.
+
+## Table schema
+Please tell us the table schema
+
+## Problem description
+Please share more details with us.
+
+## Expected behavior and actual behavior
+Please tell us what should happen and what happened instead
+
+## Repro code
+Please share repro code with us, or tell us how to reproduce the issue.

View file

@ -1067,33 +1067,6 @@ int pdo_sqlsrv_stmt_next_rowset( _Inout_ pdo_stmt_t *stmt TSRMLS_DC )
SQLSRV_ASSERT( driver_stmt != NULL, "pdo_sqlsrv_stmt_next_rowset: driver_data object was null" );
// Return the correct error in case the user calls nextRowset() on a null result set.
// Null means that SQLNumResultCols() returns 0 and SQLRowCount does not return > 0. But first
// check that the statement has been executed and that we are not past the end of a non-null
// result set to make sure the user gets the correct error message. These checks are also
// done in core_sqlsrv_next_result(), but we cannot check for null results there because that
// function can be called without calling this one, and SQLSRV_ERROR_NO_FIELDS can then
// be triggered incorrectly.
CHECK_CUSTOM_ERROR( !driver_stmt->executed, driver_stmt, SQLSRV_ERROR_STATEMENT_NOT_EXECUTED ) {
throw core::CoreException();
}
CHECK_CUSTOM_ERROR( driver_stmt->past_next_result_end, driver_stmt, SQLSRV_ERROR_NEXT_RESULT_PAST_END ) {
throw core::CoreException();
}
// Now make sure the result set is not null.
bool has_result = core_sqlsrv_has_any_result( driver_stmt );
// Note that if fetch_called is false but has_result is true (i.e. the user is calling
// nextRowset() on a non-null result set before calling fetch()), it is handled
// in core_sqlsrv_next_result() below.
if( !driver_stmt->fetch_called ) {
CHECK_CUSTOM_ERROR( !has_result, driver_stmt, SQLSRV_ERROR_NO_FIELDS ) {
throw core::CoreException();
}
}
core_sqlsrv_next_result( static_cast<sqlsrv_stmt*>( stmt->driver_data ) TSRMLS_CC );
// clear the current meta data since the new result will generate new meta data
@ -1146,9 +1119,19 @@ int pdo_sqlsrv_stmt_param_hook( _Inout_ pdo_stmt_t *stmt,
// since the param isn't reliable, we don't do anything here
case PDO_PARAM_EVT_ALLOC:
if ( stmt->supports_placeholders == PDO_PLACEHOLDER_NONE && (param->param_type & PDO_PARAM_INPUT_OUTPUT )) {
sqlsrv_stmt* driver_stmt = reinterpret_cast<sqlsrv_stmt*>( stmt->driver_data );
THROW_PDO_ERROR( driver_stmt, PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED );
{
pdo_sqlsrv_stmt* driver_stmt = reinterpret_cast<pdo_sqlsrv_stmt*>(stmt->driver_data);
if (driver_stmt->conn->ce_option.enabled) {
if (driver_stmt->direct_query) {
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED);
}
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NONE) {
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED);
}
}
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NONE && (param->param_type & PDO_PARAM_INPUT_OUTPUT)) {
THROW_PDO_ERROR(driver_stmt, PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED);
}
}
break;
case PDO_PARAM_EVT_FREE:

View file

@ -409,6 +409,18 @@ pdo_error PDO_ERRORS[] = {
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -80, false }
},
{
PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED,
{ IMSSP, (SQLCHAR*) "Parameterized statement with attribute PDO::SQLSRV_ATTR_DIRECT_QUERY is not supported in a Column Encryption enabled Connection.", -81, false }
},
{
PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED,
{ IMSSP, (SQLCHAR*) "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.", -82, false }
},
{
SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED,
{ IMSSP, (SQLCHAR*) "Stored Procedures do not support text, ntext or image as OUTPUT parameters.", -83, false }
},
{ UINT_MAX, {} }
};

View file

@ -310,7 +310,7 @@ inline void pdo_reset_dbh_error( _Inout_ pdo_dbh_t* dbh TSRMLS_DC )
// release the last statement from the dbh so that error handling won't have a statement passed to it
if( dbh->query_stmt ) {
dbh->query_stmt = NULL;
zend_objects_store_del( Z_OBJ_P(&dbh->query_stmt_zval TSRMLS_CC) );
zval_ptr_dtor( &dbh->query_stmt_zval );
}
// if the driver isn't valid, just return (PDO calls close sometimes more than once?)
@ -393,7 +393,9 @@ enum PDO_ERROR_CODES {
PDO_SQLSRV_ERROR_INVALID_OUTPUT_PARAM_TYPE,
PDO_SQLSRV_ERROR_INVALID_CURSOR_WITH_SCROLL_TYPE,
PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED,
PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION
PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION,
PDO_SQLSRV_ERROR_CE_DIRECT_QUERY_UNSUPPORTED,
PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED
};
extern pdo_error PDO_ERRORS[];

View file

@ -545,6 +545,21 @@ void core_sqlsrv_prepare( _Inout_ sqlsrv_stmt* stmt, _In_reads_bytes_(sql_len) c
// prepare our wide char query string
core::SQLPrepareW( stmt, reinterpret_cast<SQLWCHAR*>( wsql_string.get() ), wsql_len TSRMLS_CC );
stmt->param_descriptions.clear();
// if AE is enabled, get meta data for all parameters before binding them
if( stmt->conn->ce_option.enabled ) {
SQLSMALLINT num_params;
core::SQLNumParams( stmt, &num_params);
for( int i = 0; i < num_params; i++ ) {
param_meta_data param;
core::SQLDescribeParam( stmt, i + 1, &( param.sql_type ), &( param.column_size ), &( param.decimal_digits ), &( param.nullable ) );
stmt->param_descriptions.push_back( param );
}
}
}
catch( core::CoreException& ) {

View file

@ -39,6 +39,12 @@ void core_sqlsrv_minit( _Outptr_ sqlsrv_context** henv_cp, _Inout_ sqlsrv_contex
SQLSRV_STATIC_ASSERT( sizeof( sqlsrv_sqltype ) == sizeof( zend_long ) );
SQLSRV_STATIC_ASSERT( sizeof( sqlsrv_phptype ) == sizeof( zend_long ));
#ifndef _WIN32
// set locale from environment
// this is necessary for ODBC and MUST be done before connection
setlocale(LC_ALL, "");
#endif
*henv_cp = *henv_ncp = SQL_NULL_HANDLE; // initialize return values to NULL
try {

View file

@ -45,7 +45,7 @@ namespace {
// *** internal constants ***
const int INITIAL_FIELD_STRING_LEN = 256; // base allocation size when retrieving a string field
const int INITIAL_LOB_FIELD_LEN = 2048; // base allocation size when retrieving a LOB field
// *** internal functions ***
@ -1520,9 +1520,9 @@ SQLPOINTER read_lob_field( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_in
}
SQLLEN already_read = 0;
SQLLEN to_read = INITIAL_FIELD_STRING_LEN;
SQLLEN to_read = INITIAL_LOB_FIELD_LEN;
sqlsrv_malloc_auto_ptr<char> buffer;
buffer = static_cast<char*>( sqlsrv_malloc( INITIAL_FIELD_STRING_LEN + extra + sizeof( SQLULEN )));
buffer = static_cast<char*>( sqlsrv_malloc( INITIAL_LOB_FIELD_LEN + extra + sizeof( SQLULEN )));
SQLRETURN r = SQL_SUCCESS;
SQLCHAR state[ SQL_SQLSTATE_BUFSIZE ];
SQLLEN last_field_len = 0;

View file

@ -156,6 +156,7 @@ OACR_WARNING_POP
#include <limits>
#include <cassert>
#include <memory>
#include <vector>
// included for SQL Server specific constants
#include "msodbcsql.h"
@ -1345,6 +1346,28 @@ struct sqlsrv_output_param {
// forward decls
struct sqlsrv_result_set;
// *** parameter metadata struct ***
struct param_meta_data
{
SQLSMALLINT sql_type;
SQLSMALLINT decimal_digits;
SQLSMALLINT nullable;
SQLULEN column_size;
param_meta_data() : sql_type(0), decimal_digits(0), column_size(0), nullable(0)
{
}
~param_meta_data()
{
}
SQLSMALLINT get_sql_type() { return sql_type; }
SQLSMALLINT get_decimal_digits() { return decimal_digits; }
SQLSMALLINT get_nullable() { return nullable; }
SQLULEN get_column_size() { return column_size; }
};
// *** Statement resource structure ***
struct sqlsrv_stmt : public sqlsrv_context {
@ -1357,30 +1380,33 @@ struct sqlsrv_stmt : public sqlsrv_context {
bool past_fetch_end; // Core_sqlsrv_fetch sets this field when the statement goes beyond the last row
sqlsrv_result_set* current_results; // Current result set
SQLULEN cursor_type; // Type of cursor for the current result set
int fwd_row_index; // fwd_row_index is the current row index, SQL_CURSOR_FORWARD_ONLY
int fwd_row_index; // fwd_row_index is the current row index, SQL_CURSOR_FORWARD_ONLY
int curr_result_set; // the current active result set, 0 by default but will be incremented by core_sqlsrv_next_result
bool has_rows; // Has_rows is set if there are actual rows in the row set
bool fetch_called; // Used by core_sqlsrv_get_field to return an informative error if fetch not yet called
int last_field_index; // last field retrieved by core_sqlsrv_get_field
bool past_next_result_end; // core_sqlsrv_next_result sets this to true when the statement goes beyond the
// last results
unsigned long query_timeout; // maximum allowed statement execution time
zend_long buffered_query_limit; // maximum allowed memory for a buffered query (measured in KB)
zend_long buffered_query_limit; // maximum allowed memory for a buffered query (measured in KB)
// holds output pointers for SQLBindParameter
// We use a deque because it 1) provides the at/[] access in constant time, and 2) grows dynamically without moving
// memory, which is important because we pass the pointer to an element of the deque to SQLBindParameter to hold
std::deque<SQLLEN> param_ind_ptrs; // output pointers for lengths for calls to SQLBindParameter
zval param_input_strings; // hold all UTF-16 input strings that aren't managed by PHP
zval output_params; // hold all the output parameters
zval param_streams; // track which streams to send data to the server
zval param_datetime_buffers; // datetime strings to be converted back to DateTime objects
zval param_input_strings; // hold all UTF-16 input strings that aren't managed by PHP
zval output_params; // hold all the output parameters
zval param_streams; // track which streams to send data to the server
zval param_datetime_buffers; // datetime strings to be converted back to DateTime objects
bool send_streams_at_exec; // send all stream data right after execution before returning
sqlsrv_stream current_stream; // current stream sending data to the server as an input parameter
unsigned int current_stream_read; // # of bytes read so far. (if we read an empty PHP stream, we send an empty string
// to the server)
zval field_cache; // cache for a single row of fields, to allow multiple and out of order retrievals
zval col_cache; // Used by get_field_as_string not to call SQLColAttribute() after every fetch.
zval active_stream; // the currently active stream reading data from the database
zval field_cache; // cache for a single row of fields, to allow multiple and out of order retrievals
zval col_cache; // Used by get_field_as_string not to call SQLColAttribute() after every fetch.
zval active_stream; // the currently active stream reading data from the database
std::vector<param_meta_data> param_descriptions;
sqlsrv_stmt( _In_ sqlsrv_conn* c, _In_ SQLHANDLE handle, _In_ error_callback e, _In_opt_ void* drv TSRMLS_DC );
virtual ~sqlsrv_stmt( void );
@ -1689,6 +1715,7 @@ enum SQLSRV_ERROR_CODES {
SQLSRV_ERROR_KEYSTORE_PATH_MISSING,
SQLSRV_ERROR_KEYSTORE_KEY_MISSING,
SQLSRV_ERROR_KEYSTORE_INVALID_VALUE,
SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED,
// Driver specific error codes starts from here.
SQLSRV_ERROR_DRIVER_SPECIFIC = 1000,
@ -2005,6 +2032,16 @@ namespace core {
}
}
inline void SQLNumParams( _Inout_ sqlsrv_stmt* stmt, _Out_opt_ SQLSMALLINT* num_params)
{
SQLRETURN r;
r = ::SQLNumParams( stmt->handle(), num_params );
CHECK_SQL_ERROR_OR_WARNING( r, stmt ) {
throw CoreException();
}
}
inline void SQLEndTran( _In_ SQLSMALLINT handleType, _Inout_ sqlsrv_conn* conn, _In_ SQLSMALLINT completionType TSRMLS_DC )
{
SQLRETURN r = ::SQLEndTran( handleType, conn->handle(), completionType );

View file

@ -19,6 +19,9 @@
#include "core_sqlsrv.h"
#include <sstream>
#include <vector>
namespace {
// certain drivers using this layer will call for repeated or out of order field retrievals. To allow this, we cache the
@ -60,7 +63,8 @@ struct col_cache {
}
};
const int INITIAL_FIELD_STRING_LEN = 256; // base allocation size when retrieving a string field
const int INITIAL_FIELD_STRING_LEN = 2048; // base allocation size when retrieving a string field
const int INITIAL_AE_FIELD_STRING_LEN = 8000; // base allocation size when retrieving a string field when AE is enabled
// UTF-8 tags for byte length of characters, used by streams to make sure we don't clip a character in between reads
const unsigned int UTF8_MIDBYTE_MASK = 0xc0;
@ -101,8 +105,6 @@ void default_sql_size_and_scale( _Inout_ sqlsrv_stmt* stmt, _In_opt_ unsigned in
// given a zval and encoding, determine the appropriate sql type, column size, and decimal scale (if appropriate)
void default_sql_type( _Inout_ sqlsrv_stmt* stmt, _In_opt_ SQLULEN paramno, _In_ zval* param_z, _In_ SQLSRV_ENCODING encoding,
_Out_ SQLSMALLINT& sql_type TSRMLS_DC );
void ae_get_sql_type_info( _Inout_ sqlsrv_stmt* stmt, _In_opt_ SQLULEN paramno, _In_ SQLSMALLINT direction, _In_ zval* param_z, _In_ SQLSRV_ENCODING encoding,
_Out_ SQLSMALLINT& sql_type, _Out_ SQLULEN& column_size, _Out_ SQLSMALLINT& decimal_digits TSRMLS_DC );
void col_cache_dtor( _Inout_ zval* data_z );
void field_cache_dtor( _Inout_ zval* data_z );
void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC );
@ -114,6 +116,7 @@ bool is_valid_sqlsrv_phptype( _In_ sqlsrv_phptype type );
void resize_output_buffer_if_necessary( _Inout_ sqlsrv_stmt* stmt, _Inout_ zval* param_z, _In_ SQLULEN paramno, SQLSRV_ENCODING encoding,
_In_ SQLSMALLINT c_type, _In_ SQLSMALLINT sql_type, _In_ SQLULEN column_size, _In_ SQLSMALLINT decimal_digits,
_Out_writes_(buffer_len) SQLPOINTER& buffer, _Out_ SQLLEN& buffer_len TSRMLS_DC );
void adjustInputPrecision( _Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digits );
bool reset_ae_stream_cursor( _Inout_ sqlsrv_stmt* stmt );
void save_output_param_for_later( _Inout_ sqlsrv_stmt* stmt, _Inout_ sqlsrv_output_param& param TSRMLS_DC );
// send all the stream data
@ -135,6 +138,7 @@ sqlsrv_stmt::sqlsrv_stmt( _In_ sqlsrv_conn* c, _In_ SQLHANDLE handle, _In_ error
current_results( NULL ),
cursor_type( SQL_CURSOR_FORWARD_ONLY ),
fwd_row_index( -1 ),
curr_result_set( 0 ),
has_rows( false ),
fetch_called( false ),
last_field_index( -1 ),
@ -357,18 +361,18 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
try {
// check is only < because params are 0 based
CHECK_CUSTOM_ERROR( param_num >= SQL_SERVER_MAX_PARAMS, stmt, SQLSRV_ERROR_MAX_PARAMS_EXCEEDED, param_num + 1 ) {
CHECK_CUSTOM_ERROR( param_num >= SQL_SERVER_MAX_PARAMS, stmt, SQLSRV_ERROR_MAX_PARAMS_EXCEEDED, param_num + 1 ){
throw core::CoreException();
}
// resize the statements array of int_ptrs if the parameter isn't already set.
if( stmt->param_ind_ptrs.size() < static_cast<size_t>(param_num + 1) ) {
if( stmt->param_ind_ptrs.size() < static_cast<size_t>( param_num + 1 )){
stmt->param_ind_ptrs.resize( param_num + 1, SQL_NULL_DATA );
}
SQLLEN& ind_ptr = stmt->param_ind_ptrs[ param_num ];
zval* param_ref = param_z;
if ( Z_ISREF_P( param_z ) ) {
if( Z_ISREF_P( param_z )){
ZVAL_DEREF( param_z );
}
bool zval_was_null = ( Z_TYPE_P( param_z ) == IS_NULL );
@ -379,24 +383,24 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
// we always let that match if they want a string back.
if( direction == SQL_PARAM_INPUT_OUTPUT ) {
bool match = false;
switch( php_out_type ) {
switch( php_out_type ){
case SQLSRV_PHPTYPE_INT:
if( zval_was_null || zval_was_bool ) {
if( zval_was_null || zval_was_bool ){
convert_to_long( param_z );
}
if( zval_was_long ){
convert_to_string( param_z );
if ( encoding != SQLSRV_ENCODING_SYSTEM && encoding != SQLSRV_ENCODING_UTF8 && encoding != SQLSRV_ENCODING_BINARY ) {
if( encoding != SQLSRV_ENCODING_SYSTEM && encoding != SQLSRV_ENCODING_UTF8 && encoding != SQLSRV_ENCODING_BINARY ){
encoding = SQLSRV_ENCODING_SYSTEM;
}
match = Z_TYPE_P( param_z ) == IS_STRING;
}
else {
else{
match = Z_TYPE_P( param_z ) == IS_LONG;
}
break;
case SQLSRV_PHPTYPE_FLOAT:
if( zval_was_null ) {
if( zval_was_null ){
convert_to_double( param_z );
}
match = Z_TYPE_P( param_z ) == IS_DOUBLE;
@ -415,23 +419,30 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
SQLSRV_ASSERT( false, "Unknown SQLSRV_PHPTYPE_* constant given." );
break;
}
CHECK_CUSTOM_ERROR( !match, stmt, SQLSRV_ERROR_INPUT_OUTPUT_PARAM_TYPE_MATCH, param_num + 1 ) {
CHECK_CUSTOM_ERROR( !match, stmt, SQLSRV_ERROR_INPUT_OUTPUT_PARAM_TYPE_MATCH, param_num + 1 ){
throw core::CoreException();
}
}
// if it's an output parameter and the user asks for a certain type, we have to convert the zval to that type so
// when the buffer is filled, the type is correct
if( direction == SQL_PARAM_OUTPUT ) {
// If the user specifies a certain type for an output parameter, we have to convert the zval
// to that type so that when the buffer is filled, the type is correct. But first,
// should check if a LOB type is specified.
CHECK_CUSTOM_ERROR( direction != SQL_PARAM_INPUT && ( sql_type == SQL_LONGVARCHAR
|| sql_type == SQL_WLONGVARCHAR || sql_type == SQL_LONGVARBINARY ),
stmt, SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED ){
throw core::CoreException();
}
if( direction == SQL_PARAM_OUTPUT ){
switch( php_out_type ) {
case SQLSRV_PHPTYPE_INT:
if( zval_was_long ){
convert_to_string( param_z );
if ( encoding != SQLSRV_ENCODING_SYSTEM && encoding != SQLSRV_ENCODING_UTF8 && encoding != SQLSRV_ENCODING_BINARY ) {
if( encoding != SQLSRV_ENCODING_SYSTEM && encoding != SQLSRV_ENCODING_UTF8 && encoding != SQLSRV_ENCODING_BINARY ){
encoding = SQLSRV_ENCODING_SYSTEM;
}
}
else {
else{
convert_to_long( param_z );
}
break;
@ -456,20 +467,25 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
( encoding == SQLSRV_ENCODING_SYSTEM || encoding == SQLSRV_ENCODING_UTF8 ||
encoding == SQLSRV_ENCODING_BINARY ), "core_sqlsrv_bind_param: invalid encoding" );
if ( stmt->conn->ce_option.enabled && ( sql_type == SQL_UNKNOWN_TYPE || column_size == SQLSRV_UNKNOWN_SIZE )) {
ae_get_sql_type_info( stmt, param_num, direction, param_z, encoding, sql_type, column_size, decimal_digits TSRMLS_CC );
if( stmt->conn->ce_option.enabled && ( sql_type == SQL_UNKNOWN_TYPE || column_size == SQLSRV_UNKNOWN_SIZE )){
// use the meta data only if the user has not specified the sql type or column size
SQLSRV_ASSERT( param_num < stmt->param_descriptions.size(), "Invalid param_num passed in core_sqlsrv_bind_param!" );
sql_type = stmt->param_descriptions[param_num].get_sql_type();
column_size = stmt->param_descriptions[param_num].get_column_size();
decimal_digits = stmt->param_descriptions[param_num].get_decimal_digits();
// change long to double if the sql type is decimal
if ( sql_type == SQL_DECIMAL && Z_TYPE_P( param_z ) == IS_LONG )
convert_to_double( param_z );
if(( sql_type == SQL_DECIMAL || sql_type == SQL_NUMERIC ) && Z_TYPE_P(param_z) == IS_LONG )
convert_to_double( param_z );
}
else {
else{
// if the sql type is unknown, then set the default based on the PHP type passed in
if ( sql_type == SQL_UNKNOWN_TYPE ) {
if( sql_type == SQL_UNKNOWN_TYPE ){
default_sql_type( stmt, param_num, param_z, encoding, sql_type TSRMLS_CC );
}
// if the size is unknown, then set the default based on the PHP type passed in
if ( column_size == SQLSRV_UNKNOWN_SIZE ) {
if( column_size == SQLSRV_UNKNOWN_SIZE ){
default_sql_size_and_scale( stmt, static_cast<unsigned int>(param_num), param_z, encoding, column_size, decimal_digits TSRMLS_CC );
}
}
@ -477,7 +493,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
c_type = default_c_type( stmt, param_num, param_z, encoding TSRMLS_CC );
// set the buffer based on the PHP parameter type
switch( Z_TYPE_P( param_z )) {
switch( Z_TYPE_P( param_z )){
case IS_NULL:
{
@ -491,12 +507,12 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
case IS_FALSE:
case IS_LONG:
{
// if it is boolean, set the lval to 0 or 1
convert_to_long( param_z );
// if it is boolean, set the lval to 0 or 1
convert_to_long( param_z );
buffer = &param_z->value;
buffer_len = sizeof( Z_LVAL_P( param_z ));
ind_ptr = buffer_len;
if( direction != SQL_PARAM_INPUT ) {
if( direction != SQL_PARAM_INPUT ){
// save the parameter so that 1) the buffer doesn't go away, and 2) we can set it to NULL if returned
sqlsrv_output_param output_param( param_ref, static_cast<int>( param_num ), zval_was_bool );
save_output_param_for_later( stmt, output_param TSRMLS_CC );
@ -508,7 +524,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
buffer = &param_z->value;
buffer_len = sizeof( Z_DVAL_P( param_z ));
ind_ptr = buffer_len;
if( direction != SQL_PARAM_INPUT ) {
if( direction != SQL_PARAM_INPUT ){
// save the parameter so that 1) the buffer doesn't go away, and 2) we can set it to NULL if returned
sqlsrv_output_param output_param( param_ref, static_cast<int>( param_num ), false );
save_output_param_for_later( stmt, output_param TSRMLS_CC );
@ -516,82 +532,89 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
}
break;
case IS_STRING:
buffer = Z_STRVAL_P( param_z );
buffer_len = Z_STRLEN_P( param_z );
// if the encoding is UTF-8, translate from UTF-8 to UTF-16 (the type variables should have already been adjusted)
if( direction == SQL_PARAM_INPUT && encoding == CP_UTF8 ) {
zval wbuffer_z;
ZVAL_NULL( &wbuffer_z );
bool converted = convert_input_param_to_utf16( param_z, &wbuffer_z );
CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_INPUT_PARAM_ENCODING_TRANSLATE,
param_num + 1, get_last_error_message() ) {
throw core::CoreException();
{
if ( sql_type == SQL_DECIMAL || sql_type == SQL_NUMERIC ) {
adjustInputPrecision( param_z, decimal_digits );
}
buffer = Z_STRVAL_P( &wbuffer_z );
buffer_len = Z_STRLEN_P( &wbuffer_z );
core::sqlsrv_add_index_zval(*stmt, &(stmt->param_input_strings), param_num, &wbuffer_z TSRMLS_CC);
}
ind_ptr = buffer_len;
if( direction != SQL_PARAM_INPUT ) {
// PHP 5.4 added interned strings, so since we obviously want to change that string here in some fashion,
// we reallocate the string if it's interned
if ( ZSTR_IS_INTERNED( Z_STR_P( param_z ))) {
core::sqlsrv_zval_stringl( param_z, static_cast<const char*>(buffer), buffer_len );
buffer = Z_STRVAL_P( param_z );
buffer_len = Z_STRLEN_P( param_z );
}
// if it's a UTF-8 input output parameter (signified by the C type being SQL_C_WCHAR)
// or if the PHP type is a binary encoded string with a N(VAR)CHAR/NTEXTSQL type,
// convert it to wchar first
if( direction == SQL_PARAM_INPUT_OUTPUT &&
( c_type == SQL_C_WCHAR ||
( c_type == SQL_C_BINARY &&
( sql_type == SQL_WCHAR ||
sql_type == SQL_WVARCHAR ||
sql_type == SQL_WLONGVARCHAR )))) {
bool converted = convert_input_param_to_utf16( param_z, param_z );
CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_INPUT_PARAM_ENCODING_TRANSLATE,
param_num + 1, get_last_error_message() ) {
buffer = Z_STRVAL_P( param_z );
buffer_len = Z_STRLEN_P( param_z );
// if the encoding is UTF-8, translate from UTF-8 to UTF-16 (the type variables should have already been adjusted)
if( direction == SQL_PARAM_INPUT && encoding == CP_UTF8 ){
zval wbuffer_z;
ZVAL_NULL( &wbuffer_z );
bool converted = convert_input_param_to_utf16( param_z, &wbuffer_z );
CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_INPUT_PARAM_ENCODING_TRANSLATE,
param_num + 1, get_last_error_message() ){
throw core::CoreException();
}
buffer = Z_STRVAL_P( param_z );
buffer_len = Z_STRLEN_P( param_z );
ind_ptr = buffer_len;
buffer = Z_STRVAL_P( &wbuffer_z );
buffer_len = Z_STRLEN_P( &wbuffer_z );
core::sqlsrv_add_index_zval( *stmt, &( stmt->param_input_strings ), param_num, &wbuffer_z TSRMLS_CC );
}
ind_ptr = buffer_len;
if( direction != SQL_PARAM_INPUT ){
// PHP 5.4 added interned strings, so since we obviously want to change that string here in some fashion,
// we reallocate the string if it's interned
if( ZSTR_IS_INTERNED( Z_STR_P( param_z ))){
core::sqlsrv_zval_stringl( param_z, static_cast<const char*>(buffer), buffer_len );
buffer = Z_STRVAL_P( param_z );
buffer_len = Z_STRLEN_P( param_z );
}
// since this is an output string, assure there is enough space to hold the requested size and
// set all the variables necessary (param_z, buffer, buffer_len, and ind_ptr)
resize_output_buffer_if_necessary( stmt, param_z, param_num, encoding, c_type, sql_type, column_size, decimal_digits,
buffer, buffer_len TSRMLS_CC );
// if it's a UTF-8 input output parameter (signified by the C type being SQL_C_WCHAR)
// or if the PHP type is a binary encoded string with a N(VAR)CHAR/NTEXTSQL type,
// convert it to wchar first
if( direction == SQL_PARAM_INPUT_OUTPUT &&
( c_type == SQL_C_WCHAR ||
( c_type == SQL_C_BINARY &&
( sql_type == SQL_WCHAR ||
sql_type == SQL_WVARCHAR ||
sql_type == SQL_WLONGVARCHAR )))){
// save the parameter to be adjusted and/or converted after the results are processed
sqlsrv_output_param output_param( param_ref, encoding, param_num, static_cast<SQLUINTEGER>( buffer_len ), zval_was_long );
bool converted = convert_input_param_to_utf16( param_z, param_z );
CHECK_CUSTOM_ERROR( !converted, stmt, SQLSRV_ERROR_INPUT_PARAM_ENCODING_TRANSLATE,
param_num + 1, get_last_error_message() ){
throw core::CoreException();
}
buffer = Z_STRVAL_P( param_z );
buffer_len = Z_STRLEN_P( param_z );
ind_ptr = buffer_len;
}
save_output_param_for_later( stmt, output_param TSRMLS_CC );
// since this is an output string, assure there is enough space to hold the requested size and
// set all the variables necessary (param_z, buffer, buffer_len, and ind_ptr)
resize_output_buffer_if_necessary( stmt, param_z, param_num, encoding, c_type, sql_type, column_size, decimal_digits,
buffer, buffer_len TSRMLS_CC );
// For output parameters, if we set the column_size to be same as the buffer_len,
// then if there is a truncation due to the data coming from the server being
// greater than the column_size, we don't get any truncation error. In order to
// avoid this silent truncation, we set the column_size to be "MAX" size for
// string types. This will guarantee that there is no silent truncation for
// output parameters.
// if column encryption is enabled, at this point the correct column size has been set by SQLDescribeParam
if( direction == SQL_PARAM_OUTPUT && !stmt->conn->ce_option.enabled ) {
switch( sql_type ) {
// save the parameter to be adjusted and/or converted after the results are processed
sqlsrv_output_param output_param( param_ref, encoding, param_num, static_cast<SQLUINTEGER>( buffer_len ), zval_was_long );
save_output_param_for_later( stmt, output_param TSRMLS_CC );
// For output parameters, if we set the column_size to be same as the buffer_len,
// then if there is a truncation due to the data coming from the server being
// greater than the column_size, we don't get any truncation error. In order to
// avoid this silent truncation, we set the column_size to be "MAX" size for
// string types. This will guarantee that there is no silent truncation for
// output parameters.
// if column encryption is enabled, at this point the correct column size has been set by SQLDescribeParam
if( direction == SQL_PARAM_OUTPUT && !stmt->conn->ce_option.enabled ){
switch( sql_type ){
case SQL_VARBINARY:
case SQL_VARCHAR:
case SQL_WVARCHAR:
case SQL_WVARCHAR:
column_size = SQL_SS_LENGTH_UNLIMITED;
break;
default:
break;
}
}
}
}
@ -624,36 +647,36 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
zend_class_entry *class_entry = Z_OBJCE_P( param_z TSRMLS_CC );
while( class_entry != NULL ) {
while( class_entry != NULL ){
SQLSRV_ASSERT( class_entry->name != NULL, "core_sqlsrv_bind_param: class_entry->name is NULL." );
if( class_entry->name->len == DateTime::DATETIME_CLASS_NAME_LEN && class_entry->name != NULL &&
stricmp( class_entry->name->val, DateTime::DATETIME_CLASS_NAME ) == 0 ) {
stricmp( class_entry->name->val, DateTime::DATETIME_CLASS_NAME ) == 0 ){
valid_class_name_found = true;
break;
}
else {
else{
// Check the parent
class_entry = class_entry->parent;
}
}
CHECK_CUSTOM_ERROR( !valid_class_name_found, stmt, SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE, param_num + 1 ) {
CHECK_CUSTOM_ERROR( !valid_class_name_found, stmt, SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE, param_num + 1 ){
throw core::CoreException();
}
// if the user specifies the 'date' sql type, giving it the normal format will cause a 'date overflow error'
// meaning there is too much information in the character string. If the user specifies the 'datetimeoffset'
// sql type, it lacks the timezone.
if( sql_type == SQL_SS_TIMESTAMPOFFSET ) {
if( sql_type == SQL_SS_TIMESTAMPOFFSET ){
core::sqlsrv_zval_stringl( &format_z, const_cast<char*>( DateTime::DATETIMEOFFSET_FORMAT ),
DateTime::DATETIMEOFFSET_FORMAT_LEN );
}
else if( sql_type == SQL_TYPE_DATE ) {
else if( sql_type == SQL_TYPE_DATE ){
core::sqlsrv_zval_stringl( &format_z, const_cast<char*>( DateTime::DATE_FORMAT ), DateTime::DATE_FORMAT_LEN );
}
else {
else{
core::sqlsrv_zval_stringl( &format_z, const_cast<char*>( DateTime::DATETIME_FORMAT ), DateTime::DATETIME_FORMAT_LEN );
}
// call the DateTime::format member function to convert the object to a string that SQL Server understands
@ -664,12 +687,12 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
int zr = call_user_function( EG( function_table ), param_z, &function_z, &buffer_z, 1, params TSRMLS_CC );
zend_string_release( Z_STR( format_z ));
zend_string_release( Z_STR( function_z ));
CHECK_CUSTOM_ERROR( zr == FAILURE, stmt, SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE, param_num + 1 ) {
CHECK_CUSTOM_ERROR( zr == FAILURE, stmt, SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE, param_num + 1 ){
throw core::CoreException();
}
buffer = Z_STRVAL( buffer_z );
zr = add_next_index_zval( &( stmt->param_datetime_buffers ), &buffer_z );
CHECK_CUSTOM_ERROR( zr == FAILURE, stmt, SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE, param_num + 1 ) {
CHECK_CUSTOM_ERROR( zr == FAILURE, stmt, SQLSRV_ERROR_INVALID_PARAMETER_PHPTYPE, param_num + 1 ){
throw core::CoreException();
}
buffer_len = Z_STRLEN( buffer_z ) - 1;
@ -685,7 +708,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
break;
}
if( zval_was_null ) {
if( zval_was_null ){
ind_ptr = SQL_NULL_DATA;
}
@ -693,13 +716,13 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
c_type, sql_type, column_size, decimal_digits, buffer, buffer_len, &ind_ptr TSRMLS_CC );
if ( stmt->conn->ce_option.enabled && sql_type == SQL_TYPE_TIMESTAMP )
{
if ( decimal_digits == 3 )
if( decimal_digits == 3 )
core::SQLSetDescField( stmt, param_num + 1, SQL_CA_SS_SERVER_TYPE, (SQLPOINTER)SQL_SS_TYPE_DATETIME, 0 );
else if (decimal_digits == 0)
core::SQLSetDescField( stmt, param_num + 1, SQL_CA_SS_SERVER_TYPE, (SQLPOINTER)SQL_SS_TYPE_SMALLDATETIME, 0 );
}
}
catch( core::CoreException& e ) {
catch( core::CoreException& e ){
stmt->free_param_data( TSRMLS_C );
SQLFreeStmt( stmt->handle(), SQL_RESET_PARAMS );
throw e;
@ -1098,9 +1121,13 @@ void core_sqlsrv_next_result( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC, _In_ bool fin
// mark we are past the end of all results
stmt->past_next_result_end = true;
// reset the current active result set
stmt->curr_result_set = 0;
return;
}
stmt->curr_result_set++;
stmt->new_result_set( TSRMLS_C );
}
catch( core::CoreException& e ) {
@ -2039,13 +2066,6 @@ void default_sql_size_and_scale( _Inout_ sqlsrv_stmt* stmt, _In_opt_ unsigned in
}
}
void ae_get_sql_type_info( _Inout_ sqlsrv_stmt* stmt, _In_opt_ SQLULEN paramno, _In_ SQLSMALLINT direction, _In_ zval* param_z, _In_ SQLSRV_ENCODING encoding,
_Out_ SQLSMALLINT& sql_type, _Out_ SQLULEN& column_size, _Out_ SQLSMALLINT& decimal_digits TSRMLS_DC )
{
SQLSMALLINT Nullable;
core::SQLDescribeParam( stmt, paramno + 1, &sql_type, &column_size, &decimal_digits, &Nullable );
}
void col_cache_dtor( _Inout_ zval* data_z )
{
col_cache* cache = static_cast<col_cache*>( Z_PTR_P( data_z ));
@ -2196,6 +2216,7 @@ void get_field_as_string( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_ind
SQLLEN field_len_temp = 0;
SQLLEN sql_display_size = 0;
char* field_value_temp = NULL;
unsigned int intial_field_len = INITIAL_FIELD_STRING_LEN;
try {
@ -2222,6 +2243,11 @@ void get_field_as_string( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_ind
break;
}
if( stmt->conn->ce_option.enabled ) {
// when AE is enabled, increase the intial field len
intial_field_len = INITIAL_AE_FIELD_STRING_LEN;
}
col_cache* cached = NULL;
if ( NULL != ( cached = static_cast< col_cache* >( zend_hash_index_find_ptr( Z_ARRVAL( stmt->col_cache ), static_cast< zend_ulong >( field_index ))))) {
sql_field_type = cached->sql_type;
@ -2242,7 +2268,7 @@ void get_field_as_string( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_ind
if( sql_display_size == 0 || sql_display_size == INT_MAX ||
sql_display_size == INT_MAX >> 1 || sql_display_size == UINT_MAX - 1 ) {
field_len_temp = INITIAL_FIELD_STRING_LEN;
field_len_temp = intial_field_len;
SQLLEN initiallen = field_len_temp + extra;
@ -2283,7 +2309,7 @@ void get_field_as_string( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_ind
if( field_len_temp == SQL_NO_TOTAL ) {
// reset the field_len_temp
field_len_temp = INITIAL_FIELD_STRING_LEN;
field_len_temp = intial_field_len;
do {
SQLLEN initial_field_len = field_len_temp;
@ -2338,14 +2364,14 @@ void get_field_as_string( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_ind
&dummy_field_len, false /*handle_warning*/ TSRMLS_CC );
}
else {
// We have already recieved INITIAL_FIELD_STRING_LEN size data.
field_len_temp -= INITIAL_FIELD_STRING_LEN;
// We have already recieved intial_field_len size data.
field_len_temp -= intial_field_len;
// Get the rest of the data.
r = stmt->current_results->get_data( field_index + 1, c_type, field_value_temp + INITIAL_FIELD_STRING_LEN,
r = stmt->current_results->get_data( field_index + 1, c_type, field_value_temp + intial_field_len,
field_len_temp + extra, &dummy_field_len,
true /*handle_warning*/ TSRMLS_CC );
field_len_temp += INITIAL_FIELD_STRING_LEN;
field_len_temp += intial_field_len;
}
if( dummy_field_len == SQL_NULL_DATA ) {
@ -2615,6 +2641,12 @@ bool reset_ae_stream_cursor( _Inout_ sqlsrv_stmt* stmt ) {
// close and reopen the cursor
core::SQLCloseCursor(stmt->current_results->odbc);
core::SQLExecute(stmt);
// advance to the previous active result set
for (int j = 0; j < stmt->curr_result_set; j++) {
core::SQLMoreResults(stmt);
}
// FETCH_NEXT until the cursor reaches the row that it was at
for (int i = 0; i <= stmt->fwd_row_index; i++) {
core::SQLFetchScroll(stmt->current_results->odbc, SQL_FETCH_NEXT, 0);
@ -2624,6 +2656,154 @@ bool reset_ae_stream_cursor( _Inout_ sqlsrv_stmt* stmt ) {
return false;
}
void adjustInputPrecision( _Inout_ zval* param_z, _In_ SQLSMALLINT decimal_digits ) {
size_t maxDecimalPrecision = 38;
// maxDecimalStrLen is the maximum length of a stringified decimal number
// 6 is derived from: 1 for '.'; 1 for sign of the number; 1 for 'e' or 'E' (scientific notation);
// 1 for sign of scientific exponent; 2 for length of scientific exponent
// if the length is greater than maxDecimalStrLen, do not change the string
size_t maxDecimalStrLen = maxDecimalPrecision + 6;
if (Z_STRLEN_P(param_z) > maxDecimalStrLen) {
return;
}
std::vector<size_t> digits;
char* ptr = ZSTR_VAL( Z_STR_P( param_z ));
bool isNeg = false;
bool isScientificNot = false;
char scientificChar = ' ';
short scientificExp = 0;
if( strchr( ptr, 'e' ) || strchr( ptr, 'E' )){
isScientificNot = true;
}
// parse digits in param_z into the vector digits
if( *ptr == '+' || *ptr == '-' ){
if( *ptr == '-' ){
isNeg = true;
}
ptr++;
}
short numInt = 0;
short numDec = 0;
while( isdigit( *ptr )){
digits.push_back( *ptr - '0' );
ptr++;
numInt++;
}
if( *ptr == '.' ){
ptr++;
if( !isScientificNot ){
while( isdigit( *ptr ) && numDec < decimal_digits + 1 ){
digits.push_back( *ptr - '0' );
ptr++;
numDec++;
}
// make sure the rest of the number are digits
while( isdigit( *ptr )){
ptr++;
}
}
else {
while( isdigit( *ptr )){
digits.push_back( *ptr - '0' );
ptr++;
numDec++;
}
}
}
if( isScientificNot ){
if ( *ptr == 'e' || *ptr == 'E' ) {
scientificChar = *ptr;
}
ptr++;
bool isNegExp = false;
if( *ptr == '+' || *ptr == '-' ){
if( *ptr == '-' ){
isNegExp = true;
}
ptr++;
}
while( isdigit( *ptr )){
scientificExp = scientificExp * 10 + ( *ptr - '0' );
ptr++;
}
SQLSRV_ASSERT( scientificExp <= maxDecimalPrecision, "Input decimal overflow: sql decimal type only supports up to a precision of 38." );
if( isNegExp ){
scientificExp = scientificExp * -1;
}
}
// if ptr is not pointing to a null terminator at this point, that means the decimal string input is invalid
// do not change the string and let SQL Server handle the invalid decimal string
if ( *ptr != '\0' ) {
return;
}
// if number of decimal is less than the exponent, that means the number is a whole number, so no need to adjust the precision
if( numDec > scientificExp ){
int decToRemove = numDec - scientificExp - decimal_digits;
if( decToRemove > 0 ){
bool carryOver = false;
short backInd = 0;
// pop digits from the vector until there is only 1 more decimal place than required decimal_digits
while( decToRemove != 1 && !digits.empty() ){
digits.pop_back();
decToRemove--;
}
if( !digits.empty() ){
// check if the last digit to be popped is greater than 5, if so, the digit before it needs to round up
carryOver = digits.back() >= 5;
digits.pop_back();
backInd = digits.size() - 1;
// round up from the end until no more carry over
while( carryOver && backInd >= 0 ){
if( digits.at( backInd ) != 9 ){
digits.at( backInd )++;
carryOver = false;
}
else{
digits.at( backInd ) = 0;
}
backInd--;
}
}
std::ostringstream oss;
if( isNeg ){
oss << '-';
}
// insert 1 if carry over persist all the way to the beginning of the number
if( carryOver && backInd == -1 ){
oss << 1;
}
if( digits.empty() && !carryOver ){
oss << 0;
}
else{
short i = 0;
for( i; i < numInt && i < digits.size(); i++ ){
oss << digits[i];
}
// fill string with 0 if the number of digits in digits is less then numInt
if( i < numInt ){
for( i; i < numInt; i++ ){
oss << 0;
}
}
if( numInt < digits.size() ){
oss << '.';
for( i; i < digits.size(); i++ ){
oss << digits[i];
}
}
if( scientificExp != 0 ){
oss << scientificChar << std::to_string( scientificExp );
}
}
std::string str = oss.str();
zend_string* zstr = zend_string_init( str.c_str(), str.length(), 0 );
zend_string_release( Z_STR_P( param_z ));
ZVAL_NEW_STR( param_z, zstr );
}
}
}
// output parameters have their reference count incremented so that they do not disappear
// while the query is executed and processed. They are saved in the statement so that
// their reference count may be decremented later (after results are processed)

View file

@ -27,6 +27,17 @@
#include <locale>
#define CP_UTF8 65001
#define CP_ISO8859_1 28591
#define CP_ISO8859_2 28592
#define CP_ISO8859_3 28593
#define CP_ISO8859_4 28594
#define CP_ISO8859_5 28595
#define CP_ISO8859_6 28596
#define CP_ISO8859_7 28597
#define CP_ISO8859_8 28598
#define CP_ISO8859_9 28599
#define CP_ISO8859_13 28603
#define CP_ISO8859_15 28605
#define CP_UTF16 1200
#define CP_ACP 0 // default to ANSI code page
@ -178,14 +189,15 @@ private:
SystemLocale & operator=( const SystemLocale & );
std::locale * m_pLocale;
UINT m_uAnsiCP;
explicit SystemLocale( const char * localeName );
~SystemLocale();
static UINT ExpandSpecialCP( UINT codepage )
{
// Convert CP_ACP, CP_OEM to CP_UTF8
return (codepage < 2 ? CP_UTF8 : codepage);
// skip SQLSRV_ENCODING_CHAR
return (codepage <= 3 ? Singleton().m_uAnsiCP : codepage);
}
// Returns the number of bytes this UTF8 code point expects
@ -217,7 +229,7 @@ private:
inline UINT SystemLocale::AnsiCP() const
{
return CP_UTF8;
return m_uAnsiCP;
}
inline UINT SystemLocale::MaxCharCchSize( UINT codepage )

View file

@ -1,5 +1,5 @@
//---------------------------------------------------------------------------------------------------------------------------------
// File: LocalizationImpl.hpp
// File: localizationimpl.cpp
//
// Contents: Contains non-inline code for the SystemLocale class
// Must be included in one c/cpp file per binary
@ -71,6 +71,17 @@ const cp_iconv cp_iconv::g_cp_iconv[] = {
{ 1256, "CP1256//TRANSLIT" },
{ 1257, "CP1257//TRANSLIT" },
{ 1258, "CP1258//TRANSLIT" },
{ CP_ISO8859_1, "ISO8859-1//TRANSLIT" },
{ CP_ISO8859_2, "ISO8859-2//TRANSLIT" },
{ CP_ISO8859_3, "ISO8859-3//TRANSLIT" },
{ CP_ISO8859_4, "ISO8859-4//TRANSLIT" },
{ CP_ISO8859_5, "ISO8859-5//TRANSLIT" },
{ CP_ISO8859_6, "ISO8859-6//TRANSLIT" },
{ CP_ISO8859_7, "ISO8859-7//TRANSLIT" },
{ CP_ISO8859_8, "ISO8859-8//TRANSLIT" },
{ CP_ISO8859_9, "ISO8859-9//TRANSLIT" },
{ CP_ISO8859_13, "ISO8859-13//TRANSLIT" },
{ CP_ISO8859_15, "ISO8859-15//TRANSLIT" },
{ 12000, "UTF-32LE" }
};
const size_t cp_iconv::g_cp_iconv_count = ARRAYSIZE(cp_iconv::g_cp_iconv);
@ -270,7 +281,42 @@ using namespace std;
SystemLocale::SystemLocale( const char * localeName )
: m_pLocale( new std::locale(localeName) )
, m_uAnsiCP(CP_UTF8)
{
struct LocaleCP
{
const char* localeName;
UINT codePage;
};
#define CPxxx(cp) { "CP" #cp, cp }
#define ISO8859(n) { "ISO-8859-" #n, CP_ISO8859_ ## n }, \
{ "8859_" #n, CP_ISO8859_ ## n }, \
{ "ISO8859-" #n, CP_ISO8859_ ## n }, \
{ "ISO8859" #n, CP_ISO8859_ ## n }, \
{ "ISO_8859-" #n, CP_ISO8859_ ## n }, \
{ "ISO_8859_" #n, CP_ISO8859_ ## n }
const LocaleCP lcpTable[] = {
{ "utf8", CP_UTF8 },
{ "UTF-8", CP_UTF8 },
CPxxx(1252), CPxxx(850), CPxxx(437), CPxxx(874), CPxxx(932), CPxxx(936), CPxxx(949), CPxxx(950),
CPxxx(1250), CPxxx(1251), CPxxx(1253), CPxxx(1254), CPxxx(1255), CPxxx(1256), CPxxx(1257), CPxxx(1258),
ISO8859(1), ISO8859(2), ISO8859(3), ISO8859(4), ISO8859(5), ISO8859(6),
ISO8859(7), ISO8859(8), ISO8859(9), ISO8859(13), ISO8859(15),
{ "UTF-32LE", 12000 }
};
if (localeName)
{
const char *charsetName = strchr(localeName, '.');
charsetName = charsetName ? charsetName + 1 : localeName;
for (const LocaleCP& lcp : lcpTable)
{
if (!strncasecmp(lcp.localeName, charsetName, strlen(lcp.localeName)))
{
m_uAnsiCP = lcp.codePage;
return;
}
}
}
}
SystemLocale::~SystemLocale()
@ -285,7 +331,8 @@ const SystemLocale & SystemLocale::Singleton()
#if !defined(__GNUC__) || defined(NO_THREADSAFE_STATICS)
#error "Relying on GCC's threadsafe initialization of local statics."
#endif
static const SystemLocale s_Default( "en_US.utf-8" );
// get locale from environment and set as default
static const SystemLocale s_Default(setlocale(LC_ALL, NULL));
return s_Default;
}

View file

@ -28,7 +28,7 @@
// Increase Patch for backward compatible fixes.
#define SQLVERSION_MAJOR 5
#define SQLVERSION_MINOR 1
#define SQLVERSION_PATCH 1
#define SQLVERSION_PATCH 2
#define SQLVERSION_BUILD 0
// Semantic versioning pre-release

View file

@ -560,32 +560,6 @@ PHP_FUNCTION( sqlsrv_next_result )
PROCESS_PARAMS( stmt, "r", _FN_, 0 );
try {
// Return the correct error in case the user calls sqlsrv_next_result() on a null result set.
// Null means that SQLNumResultCols() returns 0 and SQLRowCount does not return > 0. But first
// check that the statement has been executed and that we are not past the end of a non-null
// result set to make sure the user gets the correct error message. These checks are also
// done in core_sqlsrv_next_result(), but we cannot check for null results there because that
// function can be called without calling this one, and SQLSRV_ERROR_NO_FIELDS can then
// be triggered incorrectly.
CHECK_CUSTOM_ERROR( !stmt->executed, stmt, SQLSRV_ERROR_STATEMENT_NOT_EXECUTED ) {
throw core::CoreException();
}
CHECK_CUSTOM_ERROR( stmt->past_next_result_end, stmt, SQLSRV_ERROR_NEXT_RESULT_PAST_END ) {
throw core::CoreException();
}
bool has_result = core_sqlsrv_has_any_result( stmt );
// Note that if fetch_called is false but has_result is true (i.e. the user is calling
// sqlsrv_next_result() on a non-null result set before calling fetch()), it is handled
// in core_sqlsrv_next_result() below.
if( !stmt->fetch_called ) {
CHECK_CUSTOM_ERROR( !has_result, stmt, SQLSRV_ERROR_NO_FIELDS ) {
throw core::CoreException();
}
}
core_sqlsrv_next_result( stmt TSRMLS_CC, true );

View file

@ -408,6 +408,11 @@ ss_error SS_ERRORS[] = {
SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND,
{ IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -107, false }
},
{
SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED,
{ IMSSP, (SQLCHAR*) "Stored Procedures do not support text, ntext or image as OUTPUT parameters.", -108, false }
},
// terminate the list of errors/warnings
{ UINT_MAX, {} }
};

View file

@ -2,136 +2,93 @@
#########################################################################################
#
# Description:
# Requirement of python 3.4 to execute this script and required result log file are in the same location
# Requirement of python 3.4 to execute this script and required result log file(s)
# are in the same location
# Run with command line without options required. Example: py output.py
# This script parse output of PHP Native Test
#
#
#############################################################################################
import os
import stat
import re
# This module returns either the number of test or the number of failed test
# depending on the argument you requested.
# Input: var - a single variable containing either "FAIL" or "TOTAL"
# Output: Returns a number of test/s or failed test/s
def returnCount(var):
with open(os.path.dirname(os.path.realpath(__file__)) + os.sep + logfile) as f:
num = 0
failnum = 0
for line in f:
if "FAIL" in line or "PASS" in line:
if ".phpt" in line:
if "FAIL" in line:
failnum += 1
num += 1
if var == 'total':
return str(num)
# This module appends an entry to the tests list, may include the test title.
# Input: search_pattern - pattern to look for in the line of the log file
# line - current line of the log file
# index - the current index of tests
# tests_list - a list of xml entries
# get_title - boolean flag to get the test title or not
# Output: None
def get_test_entry(search_pattern, line, index, tests_list, get_title = False):
# find the full path to the test name, enclosed by square brackets
result = re.search(search_pattern, line)
pos1 = result.group(1).find('[')
pos2 = result.group(1).find(']')
test_line = str(result.group(1))
# get the test name by splitting this full path delimited by os.sep
substr = test_line[pos1+1:pos2]
tmp_array = substr.split(os.sep)
pos = len(tmp_array) - 1
test_name = tmp_array[pos]
# only upon a failure do we get the test title
if (get_title is True):
entry = '\t<testcase name="' + test_name + '-' + index + '">'
tests_list.append(entry)
test_title = test_line[0:pos1]
entry = '\t\t<failure message=" Failed in ' + test_title + '"/>'
tests_list.append(entry)
tests_list.append('\t</testcase>')
else:
return str(failnum)
entry = '\t<testcase name="' + test_name + '-' + index + '"/>'
tests_list.append(entry)
# This module prints the line that matches the expression.
# Input: inputStr - String that matches
# file - file name
# path - path of the file.
# Output: null
def readAndPrint(inputStr, file, path):
filn = open(path + os.sep + file).readlines()
for lines in filn:
if inputStr in lines:
print(lines)
# This module returns the test file name.
# Input: line - current line of the log file
# Output: Returns the filename.
def TestFilename(line):
terminateChar = os.sep
currentPos = 0
firstpos = len(line) * -1
while True:
currentPos = currentPos - 1
# if passed the first pos, stop
if currentPos < firstpos:
break
line[currentPos]
if line[currentPos] == terminateChar:
break
file = line[currentPos+1:-1]
return file
def genXML(logfile,number):
# Generating the nativeresult.xml file.
file = open('nativeresult' + str(number) + '.xml','w')
file.write('<?xml version="1.0" encoding="UTF-8" ?>' + os.linesep)
file.write('<testsuite tests="' + returnCount('total') + '" failures="' + returnCount('fail') + '" name="Native Tests" >' + os.linesep)
file.close()
# Extract individual test results from the log file and
# enter it in the nativeresult.xml file.
# Extract individual test results from the log file and
# enter it in the nativeresult.xml file.
# Input: logfile - the log file
# number - the number for this xml file
def gen_XML(logfile, number):
print('================================================')
print("\n" + os.path.splitext(logfile)[0] + "\n" )
tests_list = []
with open(os.path.dirname(os.path.realpath(__file__)) + os.sep + logfile) as f:
num = 1
failnum = 0
for line in f:
file = open('nativeresult' + str(number) + '.xml','a')
if "FAIL" in line or "PASS" in line:
if ".phpt" in line:
file.write('\t<testcase name="')
if "FAIL" in line:
failnum += 1
result = re.search('FAIL(.*).', line)
file.write(TestFilename(str(result.group(1))) + '-' + str(num) + '">' + os.linesep)
stop_pos = result.group(1).find('[')
file.write('\t\t<failure message=" Failed in ' + str(result.group(1))[0:stop_pos] + '"/>' + os.linesep)
file.write('\t</testcase>' + os.linesep)
get_test_entry('FAIL(.*).', line, str(num), tests_list, True)
else:
result = re.search('PASS(.*).', line)
file.write(TestFilename(str(result.group(1))) + '-' + str(num) + '"/>' + os.linesep)
get_test_entry('PASS(.*).', line, str(num), tests_list)
num += 1
file.close()
elif 'Number of tests :' in line or 'Tests skipped ' in line or 'Tests warned ' in line or'Tests failed ' in line or 'Expected fail ' in line or 'Tests passed ' in line:
print(line)
print('================================================')
file = open('nativeresult' + str(number) + '.xml','a')
file.write('</testsuite>' + os.linesep)
file.close()
# Generating the nativeresult.xml file.
file = open('nativeresult' + str(number) + '.xml', 'w')
file.write('<?xml version="1.0" encoding="UTF-8" ?>' + os.linesep)
file.write('<testsuite tests="' + str(num - 1) + '" failures="' + str(failnum) + '" name="Native Tests" >' + os.linesep)
def run():
num = 1
for f in os.listdir(os.path.dirname(os.path.realpath(__file__))):
if f.endswith("log"):
print('================================================')
print(os.path.splitext(f)[0])
readAndPrint('Number of tests :', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests skipped ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests warned ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests failed ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Expected fail ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests passed ', f, os.path.dirname(os.path.realpath(__file__)))
print('================================================')
logfile = f
genXML(logfile,num)
num = num + 1
index = 1
for test in tests_list:
file.write(test + os.linesep)
file.write('</testsuite>' + os.linesep)
file.close()
# ------------------------------------------------------- Main Function ---------------------------------------------------
# ----------------------- Main Function -----------------------
# Display results on screen from result log file.
if __name__ == '__main__':
num = 1
for f in os.listdir(os.path.dirname(os.path.realpath(__file__))):
if f.endswith("log"):
print('================================================')
print("\n" + os.path.splitext(f)[0] + "\n")
readAndPrint('Number of tests :', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests skipped ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests warned ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests failed ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Expected fail ', f, os.path.dirname(os.path.realpath(__file__)))
readAndPrint('Tests passed ', f, os.path.dirname(os.path.realpath(__file__)))
print('================================================')
logfile = f
genXML(logfile,num)
gen_XML(logfile, num)
num = num + 1

View file

@ -62,11 +62,11 @@ $pdoParamTypes = array(
// Checks if the current error is the incompatible types error
// if so, state which sql type is incompatible with which data type
function is_incompatible_types_error( $stmt, $dataType, $pdoParamType ) {
if ( $stmt->errorInfo()[0] == "22018" )
function isIncompatibleTypesError($stmt, $dataType, $pdoParamType)
{
if ($stmt->errorInfo()[0] == "22018") {
echo "PDO param type $pdoParamType is incompatible with encrypted $dataType\n";
else
var_dump( $stmt->errorInfo() );
} else {
var_dump($stmt->errorInfo());
}
}
?>

View file

@ -12,7 +12,6 @@
// looks like an additional file (in addition to pdo_test_base.inc) may be needed for these PHPTs
// to be runnable from the MSSQL teams' internal proprietary test running system
//
require 'MsData.inc';
function IsAEQualified($conn)
{
@ -35,9 +34,7 @@ function connect($options=array())
require 'MsSetup.inc';
$conn = new PDO( "sqlsrv:Server=$server;database=$databaseName;ConnectionPooling=false;" , $uid, $pwd, $options);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
create_and_insert_table1($conn);
create_and_insert_table2($conn);
return $conn;
return $conn;
}
catch( PDOException $e )
@ -447,155 +444,6 @@ function is_col_enc()
return true;
}
// Create and insert
function create_and_insert_table1( $conn )
{
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1;
try
{
$create_query =
"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U'))
DROP TABLE " . $table1 .
" CREATE TABLE [dbo].[" . $table1 . "](
[IntCol] [int] NULL,
[CharCol] [char](10) NULL,
[NCharCol] [nchar](10) NULL,
[DateTimeCol] [datetime] NULL,
[VarcharCol] [varchar](50) NULL,
[NVarCharCol] [nvarchar](50) NULL,
[FloatCol] [float] NULL,
[XmlCol] [xml] NULL
) ON [PRIMARY]
";
$conn->query( $create_query );
for ($i = 0 ; $i <= 1; ++ $i)
{
$insert_query =
"INSERT INTO PDO_Types_1 VALUES (".
$int_col[$i] . $comma .
$string_col[$i] . $comma .
$string_col[$i] . $comma .
"Convert(datetime, ". $date_col[$i] . ")" . $comma .
$string_col[$i] . $comma .
$string_col[$i] . $comma .
$decimal_col[$i] . $comma .
$xml_col[$i] .
")";
$conn->query ( $insert_query );
}
}
catch(Exception $e)
{
var_dump( $e);
exit;
}
}
function create_and_insert_table2( $conn )
{
try
{
//Timestamp is not present.
//VARIANT is not supported.
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1, $table2;
$create_query =
"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'".$table2."') AND type in (N'U')) DROP TABLE " . $table2 .
" CREATE TABLE " .$table2 . " (
[BigIntCol] [bigint] NULL,
[BinaryCol] [binary](5) NULL,
[BitCol] [bit] NULL,
[CharCol] [char](10) NULL,
[DateCol] [date] NULL,
[DateTimeCol] [datetime] NULL,
[DateTime2Col] [datetime2](7) NULL,
[DTOffsetCol] [datetimeoffset](7) NULL,
[DecimalCol] [decimal](18, 0) NULL,
[FloatCol] [float] NULL,
[ImageCol] [image] NULL,
[IntCol] [int] NULL,
[MoneyCol] [money] NULL,
[NCharCol] [nchar](10) NULL,
[NTextCol] [ntext] NULL,
[NumCol] [numeric](18, 0) NULL,
[NVarCharCol] [nvarchar](50) NULL,
[NVarCharMaxCol] [nvarchar](max) NULL,
[RealCol] [real] NULL,
[SmallDTCol] [smalldatetime] NULL,
[SmallIntCol] [smallint] NULL,
[SmallMoneyCol] [smallmoney] NULL,
[TextCol] [text] NULL,
[TimeCol] [time](7) NULL,
[TinyIntCol] [tinyint] NULL,
[Guidcol] [uniqueidentifier] NULL,
[VarbinaryCol] [varbinary](50) NULL,
[VarbinaryMaxCol] [varbinary](max) NULL,
[VarcharCol] [varchar](50) NULL,
[VarcharMaxCol] [varchar](max) NULL,
[XmlCol] [xml] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
";
$stmt = $conn->query( $create_query );
for ($i =0; $i<= 0 ; ++ $i)
{
$insert_query =
" INSERT INTO " .$table2 . " VALUES (".
$int_col[$i] . $comma .
$binary_col[$i] . $comma .
"0" . $comma .
$string_col[$i] . $comma .
"Convert(date, ". $date_col[$i] . $closing_brace .
"Convert(datetime, ". $date_col[$i] . $closing_brace .
"Convert(datetime2(7),". $date_col[$i] . $closing_brace .
"Convert(datetimeoffset(7)," . $date_col[$i] . $closing_brace .
$decimal_col[$i] . $comma .
$decimal_col[$i] .$comma .
$binary_col[$i] . $comma .
$int_col[$i] . $comma .
$decimal_col[$i] . $comma .
$string_col[$i]. $comma .
$large_string_col[$i]. $comma.
$int_col[$i]. $comma .
$string_col[$i]. $comma .
$large_string_col[$i]. $comma .
$decimal_col[$i]. $comma .
"Convert(smalldatetime, ". $date_col[$i]. $closing_brace .
$int_col[$i]. $comma .
$decimal_col[$i]. $comma .
$large_string_col[$i]. $comma .
"Convert(time(7), ". $date_col[$i] . $closing_brace .
$int_col[$i] . $comma .
$guid_col[$i] . $comma .
$binary_col[$i] . $comma .
$binary_col[$i] . $comma .
$string_col[$i] . $comma .
$large_string_col[$i] . $comma .
$xml_col[$i] .
")";
$stmt = $conn->query ($insert_query );
}
}
catch(Exception $e)
{
var_dump( $e);
exit;
}
}
function teardown()
{
// TBD

View file

@ -12,7 +12,6 @@
// looks like an additional file (in addition to pdo_test_base.inc) may be needed for these PHPTs
// to be runnable from the MSSQL teams' internal proprietary test running system
//
require 'MsData.inc';
function isAEQualified($conn)
{
@ -127,19 +126,21 @@ class ColumnMeta
{
public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5))
public $colName; //column name
public $encType; //randomized or deterministic; default is deterministic
public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) )
public $encType; //randomized or deterministic; default is deterministic
public $forceEncrypt; //force encryption on a datatype no supported by Column Encrypton
public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic")
public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic", $forceEncrypt = false)
{
if (is_null($colName)) {
$this->colName = get_default_colname($dataType);
$this->colName = getDefaultColName($dataType);
} else {
$this->colName = $colName;
}
$this->dataType = $dataType;
$this->encType = $encType;
$this->options = $options;
$this->encType = $encType;
$this->forceEncrypt = $forceEncrypt;
}
/**
* @return string column definition for creating a table
@ -150,7 +151,7 @@ class ColumnMeta
$append = " ";
// an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time
if (isColEncrypted() && stripos($this->options, "identity") === false) {
if (isColEncrypted() && $this->isEncryptableType() && stripos($this->options, "identity") === false) {
$cekName = getCekName();
if (stripos($this->dataType, "char") !== false) {
$append .= "COLLATE Latin1_General_BIN2 ";
@ -161,6 +162,19 @@ class ColumnMeta
$colDef = "[" . $this->colName . "] " . $this->dataType . $append;
return $colDef;
}
/**
* @return bool if the datatype for this column is encryptable
*/
public function isEncryptableType()
{
$unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant");
if (!$this->forceEncrypt && in_array(strtolower($this->dataType), $unsupportedTypes)) {
return false;
} else {
return true;
}
}
}
@ -183,9 +197,10 @@ function getDefaultColName($dataType)
* @param array $inputs : an associative array column name and its value; value may be a literal value or a ColumnMeta object
* @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none
* for creating table with datatypes not support for encryption
* @param string $tableOption : table options appended to the end of a create table statement
* @return int reporting the number of rows affected (should always be 0 for creating table)
*/
function createTable($conn, $tbname, $columnMetaArr, $disableCE = false)
function createTable($conn, $tbname, $columnMetaArr, $tableOption = '', $disableCE = false)
{
try {
dropTable($conn, $tbname);
@ -202,7 +217,7 @@ function createTable($conn, $tbname, $columnMetaArr, $disableCE = false)
}
}
$colDef = rtrim($colDef, ", ");
$createSql = "CREATE TABLE $tbname ($colDef)";
$createSql = "CREATE TABLE $tbname ($colDef) $tableOption";
$numRows = $conn->exec($createSql);
return $numRows;
} catch (PDOException $e) {
@ -231,14 +246,14 @@ class BindParamOp
$this->variable = $variable;
$pdoParams = array("PDO::PARAM_BOOL", "PDO::PARAM_NULL", "PDO::PARAM_INT", "PDO::PARAM_STR", "PDO::PARAM_LOB");
if (in_array($pdoType, $pdoParams)) {
if (in_array($pdoType, $pdoParams) || is_null($pdoType)) {
$this->pdoType = $pdoType;
} else {
prinft("BindParamOp construct: The pdoType provided must be one of PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, or PDO::PARAM_LOB.\n");
printf("BindParamOp construct: The pdoType provided must be one of PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, or PDO::PARAM_LOB.\n");
exit;
}
if ($length >= 0) {
if ($length >= 0 || is_null($length)) {
$this->length = $length;
} else {
printf("BindParamOp construct: The length provided must be greater or equal to 0.\n");
@ -246,7 +261,7 @@ class BindParamOp
}
$encodingAttrs = array("PDO::SQLSRV_ENCODING_BINARY", "PDO::SQLSRV_ENCODING_SYSTEM", "PDO::SQLSRV_ENCODING_UTF8", "PDO::SQLSRV_ENCODING_DEFAULT");
if (in_array($options, $encodingAttrs)) {
if (in_array($options, $encodingAttrs) || is_null($options)) {
$this->options = $options;
} else {
printf("BindParamOp construct: The option provided must be one of PDO::SQLSRV_ENCODING_BINARY, PDO::SQLSRV_ENCODING_SYSTEM, PDO::SQLSRV_ENCODING_UTF8, PDO::SQLSRV_ENCODING_DEFAULT");
@ -508,146 +523,6 @@ function isColEncrypted()
}
}
// Create and insert
function create_and_insert_table1($conn)
{
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1;
try {
$create_query =
"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U'))
DROP TABLE " . $table1 .
" CREATE TABLE [dbo].[" . $table1 . "](
[IntCol] [int] NULL,
[CharCol] [char](10) NULL,
[NCharCol] [nchar](10) NULL,
[DateTimeCol] [datetime] NULL,
[VarcharCol] [varchar](50) NULL,
[NVarCharCol] [nvarchar](50) NULL,
[FloatCol] [float] NULL,
[XmlCol] [xml] NULL
) ON [PRIMARY]
";
$conn->query($create_query);
for ($i = 0 ; $i <= 1; ++ $i) {
$insert_query =
"INSERT INTO PDO_Types_1 VALUES (".
$int_col[$i] . $comma .
$string_col[$i] . $comma .
$string_col[$i] . $comma .
"Convert(datetime, ". $date_col[$i] . ")" . $comma .
$string_col[$i] . $comma .
$string_col[$i] . $comma .
$decimal_col[$i] . $comma .
$xml_col[$i] .
")";
$conn->query($insert_query);
}
} catch (Exception $e) {
var_dump($e);
exit;
}
}
function create_and_insert_table2($conn)
{
try {
//Timestamp is not present.
//VARIANT is not supported.
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1, $table2;
$create_query =
"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'".$table2."') AND type in (N'U')) DROP TABLE " . $table2 .
" CREATE TABLE " .$table2 . " (
[BigIntCol] [bigint] NULL,
[BinaryCol] [binary](5) NULL,
[BitCol] [bit] NULL,
[CharCol] [char](10) NULL,
[DateCol] [date] NULL,
[DateTimeCol] [datetime] NULL,
[DateTime2Col] [datetime2](7) NULL,
[DTOffsetCol] [datetimeoffset](7) NULL,
[DecimalCol] [decimal](18, 0) NULL,
[FloatCol] [float] NULL,
[ImageCol] [image] NULL,
[IntCol] [int] NULL,
[MoneyCol] [money] NULL,
[NCharCol] [nchar](10) NULL,
[NTextCol] [ntext] NULL,
[NumCol] [numeric](18, 0) NULL,
[NVarCharCol] [nvarchar](50) NULL,
[NVarCharMaxCol] [nvarchar](max) NULL,
[RealCol] [real] NULL,
[SmallDTCol] [smalldatetime] NULL,
[SmallIntCol] [smallint] NULL,
[SmallMoneyCol] [smallmoney] NULL,
[TextCol] [text] NULL,
[TimeCol] [time](7) NULL,
[TinyIntCol] [tinyint] NULL,
[Guidcol] [uniqueidentifier] NULL,
[VarbinaryCol] [varbinary](50) NULL,
[VarbinaryMaxCol] [varbinary](max) NULL,
[VarcharCol] [varchar](50) NULL,
[VarcharMaxCol] [varchar](max) NULL,
[XmlCol] [xml] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
";
$stmt = $conn->query($create_query);
for ($i =0; $i<= 0 ; ++ $i) {
$insert_query =
" INSERT INTO " .$table2 . " VALUES (".
$int_col[$i] . $comma .
$binary_col[$i] . $comma .
"0" . $comma .
$string_col[$i] . $comma .
"Convert(date, ". $date_col[$i] . $closing_brace .
"Convert(datetime, ". $date_col[$i] . $closing_brace .
"Convert(datetime2(7),". $date_col[$i] . $closing_brace .
"Convert(datetimeoffset(7)," . $date_col[$i] . $closing_brace .
$decimal_col[$i] . $comma .
$decimal_col[$i] .$comma .
$binary_col[$i] . $comma .
$int_col[$i] . $comma .
$decimal_col[$i] . $comma .
$string_col[$i]. $comma .
$large_string_col[$i]. $comma.
$int_col[$i]. $comma .
$string_col[$i]. $comma .
$large_string_col[$i]. $comma .
$decimal_col[$i]. $comma .
"Convert(smalldatetime, ". $date_col[$i]. $closing_brace .
$int_col[$i]. $comma .
$decimal_col[$i]. $comma .
$large_string_col[$i]. $comma .
"Convert(time(7), ". $date_col[$i] . $closing_brace .
$int_col[$i] . $comma .
$guid_col[$i] . $comma .
$binary_col[$i] . $comma .
$binary_col[$i] . $comma .
$string_col[$i] . $comma .
$large_string_col[$i] . $comma .
$xml_col[$i] .
")";
$stmt = $conn->query($insert_query);
}
} catch (Exception $e) {
var_dump($e);
exit;
}
}
function teardown()
{
// TBD
@ -1366,7 +1241,7 @@ function CreateTableEx($conn, $tableName, $dataType)
{
Trace("Creating table $tableName ...");
$tsql = "CREATE TABLE [$tableName] ($dataType)";
DropTable($conn, $tableName);
dropTable($conn, $tableName);
if (IsPdoMode()) {
$outcome = $conn->exec($tsql);

View file

@ -1,65 +0,0 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.
Description:
Random data generator for INSERT statements.
*/
// globals
$table1 = "PDO_Types_1";
$table2= "PDO_AllTypes";
$large_string = "This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.";
$string_col = array("'STRINGCOL1'", "'STRINGCOL2'");
$date_col = array("'2000-11-11 11:11:11.111'", "'2000-11-11 11:11:11.222'");
$large_string_col = array("' 1 " . $large_string . "'", "' 2 " . $large_string . "'");
$xml_col = array("'<xml> 1 " . $large_string . "</xml>'", "'<xml> 2 " . $large_string . "</xml>'");
$binary_col = array('0x0', '0x0');
$int_col = array ( 1, 2);
$decimal_col = array (111.111, 222.222);
$guid_col = array("'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'", "'BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB'");
$null_col = 'null';
$comma = ",";
$closing_brace = "),";
class PDO_Types_1_Class{
var $IntCol;
var $CharCol;
var $NCharCol;
var $DateTimeCol;
var $VarcharCol;
var $NVarCharCol;
var $FloatCol;
var $XmlCol;
function dumpAll()
{
var_dump($this->IntCol);
var_dump($this->CharCol);
var_dump($this->NCharCol);
var_dump($this->DateTimeCol);
var_dump($this->VarcharCol);
var_dump($this->NVarCharCol);
var_dump($this->FloatCol);
var_dump($this->XmlCol);
}
}
$table1_class = 'PDO_Types_1_Class';
?>

View file

@ -0,0 +1,205 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.
Description:
Random data generator for INSERT statements.
*/
// globals
$int_col = array(1, 2);
$bin = fopen('php://memory', 'a');
fwrite($bin, '00');
rewind($bin);
$binary_col = array($bin, $bin);
$string_col = array("STRINGCOL1", "STRINGCOL2");
$decimal_col = array(111.111, 222.222);
$large_string = "This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.";
$date_col = array('2000-11-11', '2000-11-11');
$datetime_col = array('2000-11-11 11:11:11.111', '2000-11-11 11:11:11.222');
$datetime2_col = array('2000-11-11 11:11:11.111', '2000-11-11 11:11:11.222');
$dtoffset_col = array('2000-11-11 11:11:11.111 +00:00', '2000-11-11 11:11:11.222 +00:00');
$smalldt_col = array('2000-11-11 11:11:00', '2000-11-11 11:11:00');
$timeCol = array('11:11:11.111', '11:11:11.222');
$large_string_col = array(" 1 " . $large_string . "", " 2 " . $large_string . "");
$guid_col = array("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA", "BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB");
$xml_col = array("<xml> 1 " . $large_string . "</xml>", "<xml> 2 " . $large_string . "</xml>");
$null_col = 'null';
$mainTypesClass = 'PDO_MainTypesClass';
class PDO_MainTypesClass
{
public $IntCol;
public $CharCol;
public $NCharCol;
public $DateTimeCol;
public $VarcharCol;
public $NVarCharCol;
public $FloatCol;
public $XmlCol;
public function dumpAll()
{
var_dump($this->IntCol);
var_dump($this->CharCol);
var_dump($this->NCharCol);
var_dump($this->DateTimeCol);
var_dump($this->VarcharCol);
var_dump($this->NVarCharCol);
var_dump($this->FloatCol);
var_dump($this->XmlCol);
}
}
function createTableMainTypes($conn, $tbname)
{
try {
require_once("MsCommon_mid-refactor.inc");
$columnMetaArr = array("IntCol" => "int",
"CharCol" => "char(10)",
"NCharCol" => "nchar(10)",
"DateTimeCol" => "datetime",
"VarcharCol" => "varchar(50)",
"NVarCharCol" => "nvarchar(50)",
"FloatCol" => "float",
"XmlCol" => "xml");
createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY]");
} catch (Exception $e) {
var_dump($e);
exit;
}
}
function insertIntoTableMainTypes($conn, $tbname, $rownum)
{
try {
require_once("MsCommon_mid-refactor.inc");
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $datetime_col, $datetime2_col, $dtoffset_col, $smalldt_col, $timeCol;
$inputs = array("IntCol" => $int_col[$rownum],
"CharCol" => $string_col[$rownum],
"NCharCol" => $string_col[$rownum],
"DateTimeCol" => $datetime_col[$rownum],
"VarcharCol" => $string_col[$rownum],
"NVarCharCol" => $string_col[$rownum],
"FloatCol" => $decimal_col[$rownum],
"XmlCol" => $xml_col[$rownum]);
$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam");
} catch (Exception $e) {
var_dump($e);
exit;
}
}
function createAndInsertTableMainTypes($conn, $tbname, $rows = array(0, 1))
{
createTableMainTypes($conn, $tbname);
foreach ($rows as $rownum) {
insertIntoTableMainTypes($conn, $tbname, $rownum);
}
}
function createTableAllTypes($conn, $tbname)
{
try {
require_once("MsCommon_mid-refactor.inc");
$columnMetaArr = array("BigIntCol" => "bigint",
"BinaryCol" => "binary(5)",
"BitCol" => "bit",
"CharCol" => "char(10)",
"DateCol" => "date",
"DateTimeCol" => "datetime",
"DateTime2Col" => "datetime2(7)",
"DTOffsetCol" => "datetimeoffset(7)",
"DecimalCol" => "decimal(18,0)",
"FloatCol" => "float",
"ImageCol" => "image",
"IntCol" => "int",
"MoneyCol" => "money",
"NCharCol" => "nchar(10)",
"NTextCol" => "ntext",
"NumCol" => "numeric(18,0)",
"NVarCharCol" => "nvarchar(50)",
"NVarCharMaxCol" => "nvarchar(max)",
"RealCol" => "real",
"SmallDTCol" => "smalldatetime",
"SmallIntCol" => "smallint",
"SmallMoneyCol" => "smallmoney",
"TextCol" => "text",
"TimeCol" => "time(7)",
"TinyIntCol" => "tinyint",
"Guidcol" => "uniqueidentifier",
"VarbinaryCol" => "varbinary(50)",
"VarbinaryMaxCol" => "varbinary(max)",
"VarcharCol" => "varchar(50)",
"VarcharMaxCol" => "varchar(max)",
"XmlCol" => "xml");
createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]");
} catch (Exception $e) {
var_dump($e);
exit;
}
}
function insertIntoTableAllTypes($conn, $tbname, $rownum)
{
try {
require_once("MsCommon_mid-refactor.inc");
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $datetime_col, $datetime2_col, $dtoffset_col, $smalldt_col, $timeCol;
$inputs = array("BigIntCol" => $int_col[$rownum],
"BinaryCol" => new BindParamOp(2, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"BitCol" => 0,
"CharCol" => $string_col[$rownum],
"DateCol" => $date_col[$rownum],
"DateTimeCol" => $datetime_col[$rownum],
"DateTime2Col" => $datetime2_col[$rownum],
"DTOffsetCol" => $dtoffset_col[$rownum],
"DecimalCol" => $decimal_col[$rownum],
"FloatCol" => $decimal_col[$rownum],
"ImageCol" => new BindParamOp(11, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"IntCol" => $int_col[$rownum],
"MoneyCol" => $decimal_col[$rownum],
"NCharCol" => $string_col[$rownum],
"NTextCol" => $large_string_col[$rownum],
"NumCol" => $int_col[$rownum],
"NVarCharCol" => $string_col[$rownum],
"NVarCharMaxCol" => $large_string_col[$rownum],
"RealCol" => $decimal_col[$rownum],
"SmallDTCol" => $smalldt_col[$rownum],
"SmallIntCol" => $int_col[$rownum],
"SmallMoneyCol" => $decimal_col[$rownum],
"TextCol" => $large_string_col[$rownum],
"TimeCol" => $timeCol[$rownum],
"TinyIntCol" => $int_col[$rownum],
"Guidcol" => $guid_col[$rownum],
"VarbinaryCol" => new BindParamOp(27, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"VarbinaryMaxCol" => new BindParamOp(28, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"VarcharCol" => $string_col[$rownum],
"VarcharMaxCol" => $large_string_col[$rownum],
"XmlCol" => $xml_col[$rownum]);
$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam");
} catch (Exception $e) {
var_dump($e);
exit;
}
}
function createAndInsertTableAllTypes($conn, $tbname, $rows = array(0))
{
createTableAllTypes($conn, $tbname);
foreach ($rows as $rownum) {
insertIntoTableAllTypes($conn, $tbname, $rownum);
}
}

View file

@ -1,60 +1,23 @@
--TEST--
PDO Drivers Info Test
--DESCRIPTION--
Verifies the functionality of "PDO:getAvailableDrivers().
Verifies the functionality of "PDO:getAvailableDrivers()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function DriversInfo()
{
include 'MsSetup.inc';
$testName = "PDO - Drivers";
StartTest($testName);
try {
$drivers = PDO::getAvailableDrivers();
if (in_array("sqlsrv", $drivers))
{
$count = count($drivers);
for ($i = 0; $i < $count; $i++)
{
Trace("Driver #".($i + 1).": ".$drivers[$i]."\n");
}
}
else
{
if (!in_array("sqlsrv", $drivers)) {
printf("$PhpDriver is missing.\n");
} else {
printf("Done\n");
}
EndTest($testName);
} catch (Exception $e) {
echo $e->getMessage();
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
DriversInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - Drivers" completed successfully.
Done

View file

@ -5,57 +5,26 @@ Verifies the functionality of PDO with phpinfo().
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function DriversInfo()
{
include 'MsSetup.inc';
$testName = "PDO - phpinfo";
StartTest($testName);
try {
ob_start();
phpinfo();
$info = ob_get_contents();
ob_end_clean();
// Check phpinfo() data
if (stristr($info, "PDO support => enabled") === false)
{
if (stristr($info, "PDO support => enabled") === false) {
printf("PDO is not enabled\n");
} elseif (stristr($info, "pdo_sqlsrv support => enabled") === false) {
printf("Cannot find PDO_SQLSRV driver in phpinfo() output\n");
} else {
printf("Done\n");
}
else if (stristr($info, "pdo_sqlsrv support => enabled") === false)
{
printf("Cannot find PDO driver line in phpinfo() output\n");
}
EndTest($testName);
} catch (Exception $e) {
echo $e->getMessage();
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
DriversInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - phpinfo" completed successfully.
Done

View file

@ -6,57 +6,32 @@ Verifies as well that invalid connection attempts fail as expected.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ConnectionTest()
{
include 'MsSetup.inc';
$testName = "PDO Connection";
StartTest($testName);
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try {
// Invalid connection attempt => errors are expected
Trace("Invalid connection attempt (to a non-existing server) ....\n");
$conn1 = PDOConnect('PDO', "InvalidServerName", $uid, $pwd, false);
if ($conn1)
{
$serverName="InvalidServerName";
$dsn = getDSN($serverName, $databaseName);
$conn1 = new PDO($dsn, $uid, $pwd, $connectionOptions);
if ($conn1) {
printf("Invalid connection attempt should have failed.\n");
}
$conn1 = null;
unset($conn1);
} catch (Exception $e) {
unset($conn1);
echo "Done\n";
}
try {
// Valid connection attempt => no errors are expected
Trace("\nValid connection attempt (to $server) ....\n");
$conn2 = Connect();
$conn2 = null;
EndTest($testName);
$conn2 = connect();
unset($conn2);
} catch (Exception $e) {
echo $e->getMessage();
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ConnectionTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection" completed successfully.
Done

View file

@ -5,76 +5,46 @@ Verification of PDO::errorCode()
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function CheckErrorCode()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Error Code";
StartTest($testName);
$conn1 = Connect();
CheckError(1, $conn1, '00000');
require_once("MsCommon_mid-refactor.inc");
try {
$conn1 = connect();
checkError(1, $conn1);
// Prepare test table
$table1 = $tableName."1";
$table2 = $tableName."2";
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
$table1 = "Table1";
createTable($conn1, $table1, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "varchar(10)"));
// Check errors when executing SELECT queries
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
CheckError(2, $conn1);
CheckError(3, $stmt1);
checkError(2, $conn1);
checkError(3, $stmt1);
$stmt1->execute();
$stmt2 = &$stmt1;
CheckError(4, $stmt1);
checkError(4, $stmt1);
$stmt1->closeCursor();
DropTable($conn1, $table1);
CheckError(5, $conn1);
dropTable($conn1, $table1);
checkError(5, $conn1);
// Cleanup
$stmt1 = null;
$conn1 = null;
EndTest($testName);
unset($stmt);
unset($conn);
echo "Done\n";
} catch (Exception $e) {
echo $e->getMessage();
}
function CheckError($offset, &$obj, $expected = '00000')
function checkError($offset, &$obj)
{
$code = $obj->errorCode();
if (($code != $expected) && (($expected != '00000') || ($code !='')))
{
printf("[%03d] Expecting error code '%s' got code '%s'\n",
$offset, $expected, $code);
$expected = '00000';
if ($code != $expected && !empty($code)) {
printf("[%03d] Expecting error code '%s' got code '%s'\n", $offset, $expected, $code);
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
CheckErrorCode();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection - Error Code" completed successfully.
Done

View file

@ -5,112 +5,81 @@ Verification of PDO::errorInfo()
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
function CheckErrorInfo()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Error Info";
StartTest($testName);
$conn1 = Connect();
CheckError(1, $conn1, '00000');
try {
$conn1 = connect("", array(), PDO::ERRMODE_SILENT);
checkError(1, $conn1, '00000');
// Prepare test table
$table1 = $tableName."1";
$table2 = $tableName."2";
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
$table1 = "Table1";
$table2 = "Table2";
createTable($conn1, $table1, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "varchar(10)"));
// Check errors when executing SELECT queries
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
CheckError(2, $conn1);
CheckError(3, $stmt1);
checkError(2, $conn1);
checkError(3, $stmt1);
$stmt1->execute();
$stmt2 = &$stmt1;
CheckError(4, $stmt1);
checkError(4, $stmt1);
$stmt1->closeCursor();
//DropTable($conn1, $table1);
dropTable($conn1, $table1);
@$stmt1->execute();
CheckError(5, $conn1);
//CheckError(6, $stmt1, '42S02');
//CheckError(7, $stmt2, '42S02');
checkError(5, $conn1);
checkError(6, $stmt1, '42S02');
checkError(7, $stmt2, '42S02');
$stmt1->closeCursor();
DropTable($conn1, $table2);
dropTable($conn1, $table2);
$conn2 = &$conn1;
//@$conn1->query("SELECT id, label FROM [$table2]");
//CheckError(8, $conn1, '42S02');
//CheckError(9, $conn2, '42S02');
@$conn1->query("SELECT id, label FROM [$table2]");
checkError(8, $conn1, '42S02');
checkError(9, $conn2, '42S02');
createTable($conn1, $table1, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "varchar(10)"));
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
$stmt1 = $conn1->query("SELECT id, label FROM [$table1]");
CheckError(10, $conn1);
CheckError(11, $stmt1);
checkError(10, $conn1);
checkError(11, $stmt1);
$stmt1->closeCursor();
// @$conn1->query("SELECT id, label FROM [$table2]");
// CheckError(12, $conn1, '42S02');
// CheckError(13, $conn2, '42S02');
CheckError(14, $stmt1);
@$conn1->query("SELECT id, label FROM [$table2]");
checkError(12, $conn1, '42S02');
checkError(13, $conn2, '42S02');
checkError(14, $stmt1);
// Cleanup
DropTable($conn1, $table1);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
dropTable($conn1, $table1);
unset($stmt1);
unset($conn1);
echo "Done\n";
} catch (Exception $e) {
echo $e->getMessage();
}
function CheckError($offset, &$obj, $expected = '00000')
function checkError($offset, &$obj, $expected = '00000')
{
$info = $obj->errorInfo();
$code = $info[0];
if (($code != $expected) && (($expected != '00000') || ($code != '')))
{
printf("[%03d] Expecting error code '%s' got code '%s'\n",
$offset, $expected, $code);
if (($code != $expected) && (($expected != '00000') || ($code != ''))) {
printf("[%03d] Expecting error code '%s' got code '%s'\n", $offset, $expected, $code);
}
if ($expected != '00000')
{
if (!isset($info[1]) || ($info[1] == ''))
{
if ($expected != '00000') {
if (!isset($info[1]) || ($info[1] == '')) {
printf("[%03d] Driver-specific error code not set\n", $offset);
}
if (!isset($info[2]) || ($info[2] == ''))
{
printf("[%03d] Driver-specific error message.not set\n", $offset);
if (!isset($info[2]) || ($info[2] == '')) {
printf("[%03d] Driver-specific error message not set\n", $offset);
}
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
CheckErrorInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection - Error Info" completed successfully.
Done

View file

@ -3,7 +3,7 @@ require_once("MsSetup.inc");
// Using the test database for two tables specifically constructed
// for the connection resiliency tests
$dbName = $databaseName;
$dbName = $databaseName;
$tableName1 = "test_connres1";
$tableName2 = "test_connres2";
@ -12,73 +12,69 @@ $tableName2 = "test_connres2";
// Using generated tables will eventually allow us to put the
// connection resiliency tests on Github, since the integrated testing
// from AppVeyor does not have AdventureWorks.
function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 )
function generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2)
{
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
if ( $conn === false )
{
die ( print_r( sqlsrv_errors() ) );
try {
$conn = new PDO("sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd);
// Create table
$sql = "CREATE TABLE $tableName1 (c1 INT, c2 VARCHAR(40))";
$stmt = $conn->query($sql);
// Insert data
$sql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
for ($t = 100; $t < 116; $t++) {
$stmt = $conn->prepare($sql);
$ts = substr(sha1($t), 0, 5);
$params = array( $t,$ts );
$stmt->execute($params);
}
// Create table
$sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
$stmt = $conn->query($sql);
// Insert data
$sql = "INSERT INTO $tableName2 VALUES ( ?, ? )";
for ($t = 200; $t < 209; $t++) {
$stmt = $conn->prepare($sql);
$ts = substr(sha1($t), 0, 5);
$params = array( $t,$ts );
$stmt->execute($params);
}
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
// Create table
$sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )";
$stmt = $conn->query( $sql );
// Insert data
$sql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
for( $t = 100; $t < 116; $t++ )
{
$stmt = $conn->prepare( $sql );
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt->execute( $params );
}
// Create table
$sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
$stmt = $conn->query( $sql );
// Insert data
$sql = "INSERT INTO $tableName2 VALUES ( ?, ? )";
for( $t = 200; $t < 209; $t++ )
{
$stmt = $conn->prepare( $sql );
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt->execute( $params );
}
$conn = null;
}
// Break connection by getting the session ID and killing it.
// Note that breaking a connection and testing reconnection requires a
// TCP/IP protocol connection (as opposed to a Shared Memory protocol).
function BreakConnection( $conn, $conn_break )
function breakConnection($conn, $conn_break)
{
$stmt1 = $conn->query( "SELECT @@SPID" );
$obj = $stmt1->fetch( PDO::FETCH_NUM );
$stmt1 = $conn->query("SELECT @@SPID");
$obj = $stmt1->fetch(PDO::FETCH_NUM);
$spid = $obj[0];
$stmt2 = $conn_break->query( "KILL ".$spid );
$stmt2 = $conn_break->query("KILL ".$spid);
sleep(1);
}
// Remove any databases previously created by GenerateDatabase
function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
function dropTables($server, $uid, $pwd, $tableName1, $tableName2)
{
global $dbName;
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
$conn = new PDO("sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd);
$query="IF OBJECT_ID('$tableName1', 'U') IS NOT NULL DROP TABLE $tableName1";
$stmt=$conn->query( $query );
$stmt=$conn->query($query);
$query="IF OBJECT_ID('$tableName2', 'U') IS NOT NULL DROP TABLE $tableName2";
$stmt=$conn->query( $query );
$stmt=$conn->query($query);
}
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 );
?>
dropTables($server, $uid, $pwd, $tableName1, $tableName2);
generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2);

View file

@ -8,12 +8,12 @@ require_once("MsCommon_mid-refactor.inc");
try {
// Connect
// set errmode to silent to compare sqlstates in the test
$conn = connect("", array(), PDO::ERRMODE_SILENT);
$conn = connect();
// Create table
$tableName = 'pdo_040test';
// common function insertRow() is not used here since the test deliberately executes an invalid insertion statement
// common function insertRow() is not used here since the test deliberately
// executes an invalid insertion statement
// thus it's not necessary to create an encrypted column for testing column encryption
$sql = "CREATE TABLE $tableName (code INT)";
$stmt = $conn->exec($sql);
@ -22,37 +22,36 @@ try {
// Number of supplied values does not match table definition
$sql = "INSERT INTO $tableName VALUES (?,?)";
$stmt = $conn->prepare($sql);
$params = array(2010,"London");
$params = array(2010, "London");
// SQL statement has an error, which is then reported
$stmt->execute($params);
$error = $stmt->errorInfo();
$success = true;
if ($stmt) {
$stmt->execute($params);
}
} catch (PDOException $e) {
$error = $e->errorInfo;
$success = false;
if (!isColEncrypted()) {
// 21S01 is the expected ODBC Column name or number of supplied values does not match table definition error
if ($error[0] != "21S01") {
$success = false;
if ($error[0] === "21S01") {
$success = true;
}
} else {
// 07009 is the expected ODBC Invalid Descriptor Index error
if ($error[0] != "07009") {
$success = false;
if ($error[0] === "07009") {
$success = true;
}
}
// Close connection
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
}
if ($success) {
print "Done";
} else {
var_dump($error);
}
} catch (PDOException $e) {
var_dump($e->errorInfo);
} finally {
// Clean up and close connection
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
}
?>

View file

@ -7,20 +7,14 @@ Exception is thrown for the unsupported connection attribute ATTR_PREFETCH only
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try {
echo "Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...\n";
$dsn = "sqlsrv:Server = $server;database = $databaseName";
if ($keystore != "none")
$dsn .= "ColumnEncryption=Enabled;";
if ($keystore == "ksp") {
require_once("AE_Ksp.inc");
$ksp_path = getKSPPath();
$dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=$ksp_name;CEKeystoreEncryptKey=$encrypt_key;";
}
$dsn = getDSN($server, $databaseName);
$attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$conn = new PDO($dsn, $uid, $pwd, $attr);
echo "Error from supported attribute (ATTR_PREFETCH) is silented\n\n";
echo "Error from unsupported attribute (ATTR_PREFETCH) is silenced\n\n";
unset($conn);
echo "Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION...\n";
@ -35,7 +29,7 @@ try {
--EXPECT--
Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...
Error from supported attribute (ATTR_PREFETCH) is silented
Error from unsupported attribute (ATTR_PREFETCH) is silenced
Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION...
Exception from unsupported attribute (ATTR_PREFETCH) is caught

View file

@ -0,0 +1,170 @@
--TEST--
GitHub issue 574 - Fetch Next Result Test
--DESCRIPTION--
Verifies the functionality of PDOStatement nextRowset
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect();
$tableName = 'test574';
$tableName1 = 'test574_1';
// create two tables with max fields
$columns = array(new ColumnMeta('varchar(max)', 'col1'));
createTable($conn, $tableName, $columns);
$columns = array(new ColumnMeta('varchar(max)', 'col1'));
createTable($conn, $tableName1, $columns);
// insert one row to each table
$phrase = str_repeat('This is a test ', 25000);
$stmt = insertRow($conn, $tableName, array('col1' => $phrase));
unset($stmt);
$phrase1 = str_repeat('This is indeed very long ', 30000);
$stmt = insertRow($conn, $tableName1, array('col1' => $phrase1));
unset($stmt);
// run queries in a batch
$stmt = $conn->prepare("SELECT * FROM [$tableName]; SELECT artist FROM [cd_info]; SELECT * FROM [$tableName1]");
$stmt->execute();
// fetch from $tableName
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
if ($row[0] === $phrase) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}
// fetch from cd_info
echo "1. next result? ";
$next = $stmt->nextRowset();
var_dump($next);
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo $row[0] . PHP_EOL;
}
// fetch from $tableName1
echo "2. next result? ";
$next = $stmt->nextRowset();
var_dump($next);
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
if ($row[0] === $phrase1) {
echo(substr($row[0], 0, 25)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}
// should be no more next results, first returns false second throws an exception
echo "3. next result? ";
$next = $stmt->nextRowset();
var_dump($next);
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
fatalError("This is unexpected!\n");
}
echo "4. next result? " . PHP_EOL;
try {
$next = $stmt->nextRowset();
} catch (PDOException $e) {
echo $e->getMessage() . PHP_EOL;
}
// run queries in a batch again, different order this time
$stmt = $conn->prepare("SELECT * FROM [$tableName1]; SELECT * FROM [$tableName]; SELECT artist FROM [cd_info]");
$stmt->execute();
// skip the first two queries
$stmt->nextRowset();
$stmt->nextRowset();
// fetch from cd_info
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo $row[0] . PHP_EOL;
}
// re-execute the statement, should return to the first query in the batch
$stmt->execute();
// fetch from $tableName1
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
if ($row[0] === $phrase1) {
echo(substr($row[0], 0, 25)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}
unset($stmt);
// execute a simple query, no more batch
$stmt = $conn->query("SELECT * FROM [$tableName]");
// fetch from $tableName
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
if ($row[0] === $phrase) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}
// should be no more next results, first returns false second throws an exception
echo "5. next result? ";
$next = $stmt->nextRowset();
var_dump($next);
echo "6. next result? " . PHP_EOL;
try {
$next = $stmt->nextRowset();
} catch (PDOException $e) {
echo $e->getMessage() . PHP_EOL;
}
dropTable($conn, $tableName);
dropTable($conn, $tableName1);
unset($stmt);
unset($conn);
echo "Done\n";
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
--EXPECT--
This is a test
1. next result? bool(true)
Led Zeppelin
2. next result? bool(true)
This is indeed very long
3. next result? bool(false)
4. next result?
SQLSTATE[IMSSP]: There are no more results returned by the query.
Led Zeppelin
This is indeed very long
This is a test
5. next result? bool(false)
6. next result?
SQLSTATE[IMSSP]: There are no more results returned by the query.
Done

View file

@ -1,7 +1,7 @@
--TEST--
Test the TNIR keyword with enabled and disabled options and the MultiSubnetFailover keyword with true and false options
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
// The way SYN packets are sent from the host is different depending on the combination of the TNIR and MultiSubnetFailover values
@ -12,23 +12,20 @@ Test the TNIR keyword with enabled and disabled options and the MultiSubnetFailo
// TNIR is enabled by default
// MultiSubnetFailover is disabled by default
require_once("MsSetup.inc");
$GLOBALS['uid'] = $uid;
$GLOBALS['pwd'] = $pwd;
$GLOBALS['server'] = $server;
require_once("MsCommon_mid-refactor.inc");
function test_tnir( $TNIRValue, $MSFValue ) {
function test_tnir($TNIRValue, $MSFValue)
{
$MSFValueStr = ($MSFValue) ? 'true' : 'false';
$connectionString = "sqlsrv:Server=$GLOBALS[server]; TransparentNetworkIPResolution=$TNIRValue; MultiSubnetFailover=$MSFValueStr";
try {
$start = microtime(true);
$conn = new PDO($connectionString, $GLOBALS['uid'], $GLOBALS['pwd'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$conn = connect("TransparentNetworkIPResolution=$TNIRValue; MultiSubnetFailover=$MSFValueStr;");
echo "Connection successful with TNIR $TNIRValue and MultiSubnetFailover $MSFValueStr.\n";
$connect_time = round(microtime(true) - $start, 2);
echo "Time to connect is $connect_time sec.\n\n";
$conn = NULL;
}
catch(PDOException $e) {
unset($conn);
} catch (PDOException $e) {
echo "Connection failed with TNIR $TNIRValue and MultiSubnetFailover $MSFValueStr.\n";
print_r($e->errorInfo);
}
@ -57,4 +54,4 @@ Connection successful with TNIR Disabled and MultiSubnetFailover false\.
Time to connect is [0-9]+.?[0-9]* sec\.
Connection successful with TNIR Disabled and MultiSubnetFailover true\.
Time to connect is [0-9]+.?[0-9]* sec\.
Time to connect is [0-9]+.?[0-9]* sec\.

View file

@ -3,44 +3,40 @@ Test for inserting and retrieving encrypted data of datetime types
--DESCRIPTION--
No PDO::PARAM_ type specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
try
{
$conn = ae_connect();
try {
$conn = connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $r === false ) {
is_incompatible_types_error( $stmt, $dataType, "default type" );
}
else {
$stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -0,0 +1,308 @@
--TEST--
Test for inserting into and retrieving from decimal columns of different scale
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
$num = array("-10.0", "13.33", "-191.78464696202265", "833.33", "-850.00000000000006", "851.64835164835168", "-316053.16053160531", "505505.5055055055055055055", "-1535020.0615", "7501300.675013006750130067501300675", "-7540010.067540010067540010067540010067", "7540450.0675404500675404500675404500", "-820012820012820.01282001282001282001282", "1122551511225515.1122", "-1234567892112345678912.3456", "123456789012346261234567890123.4629", "-13775323913775323913775323913775323913");
$frac = array("-0.000", "0.100", "-0.1333", "0.019178464696202265", "-0.083333", "0.085000000000000006", "-0.085164835164835168", "0.0000316", "-0.00005", "0.0000153502", "-0.0000075013", "0.00000754001", "-0.00000754045", "0.000000000008200", "-0.00000000000000112255", "0.00000000000000000000123456789", "-0.00000000000000000000000123456789012346", "0.00000000000000000000000000000001377532");
$numSets = array("Testing numbers greater than 1 or less than -1:" => $num,
"Testing numbers between 1 and -1:" => $frac);
$scalesToTest = array(0, 1, 2, 3, 4, 5, 7, 9, 19, 28, 38);
try {
$conn = connect();
$tbname = "decimalTable";
foreach ($numSets as $testName => $numSet) {
echo "\n$testName\n";
foreach ($numSet as $input) {
$numInt = ceil(log10(abs($input) + 1));
$decimalTypes = array();
foreach ($scalesToTest as $scale) {
if ($scale < 39 - $numInt) {
$decimalTypes = array_merge($decimalTypes, array("c$scale" => "decimal(38, $scale)"));
}
}
if (empty($decimalTypes)) {
$decimalTypes = array("c0" => "decimal(38, 0)");
}
createTable($conn, $tbname, $decimalTypes);
$insertValues = array();
foreach ($decimalTypes as $key => $value) {
$insertValues = array_merge($insertValues, array($key => $input));
}
insertRow($conn, $tbname, $insertValues);
$stmt = $conn->query("SELECT * FROM $tbname");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
foreach ($row as $key => $value) {
if ($value != 0) {
echo "$key: $value\n";
}
}
$conn->exec("TRUNCATE TABLE $tbname");
}
}
dropTable($conn, $tbname);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Testing numbers greater than 1 or less than -1:
c0: -10
c1: -10.0
c2: -10.00
c3: -10.000
c4: -10.0000
c5: -10.00000
c7: -10.0000000
c9: -10.000000000
c19: -10.0000000000000000000
c28: -10.0000000000000000000000000000
c0: 13
c1: 13.3
c2: 13.33
c3: 13.330
c4: 13.3300
c5: 13.33000
c7: 13.3300000
c9: 13.330000000
c19: 13.3300000000000000000
c28: 13.3300000000000000000000000000
c0: -192
c1: -191.8
c2: -191.78
c3: -191.785
c4: -191.7846
c5: -191.78465
c7: -191.7846470
c9: -191.784646962
c19: -191.7846469620226500000
c28: -191.7846469620226500000000000000
c0: 833
c1: 833.3
c2: 833.33
c3: 833.330
c4: 833.3300
c5: 833.33000
c7: 833.3300000
c9: 833.330000000
c19: 833.3300000000000000000
c28: 833.3300000000000000000000000000
c0: -850
c1: -850.0
c2: -850.00
c3: -850.000
c4: -850.0000
c5: -850.00000
c7: -850.0000000
c9: -850.000000000
c19: -850.0000000000000600000
c28: -850.0000000000000600000000000000
c0: 852
c1: 851.6
c2: 851.65
c3: 851.648
c4: 851.6484
c5: 851.64835
c7: 851.6483516
c9: 851.648351648
c19: 851.6483516483516800000
c28: 851.6483516483516800000000000000
c0: -316053
c1: -316053.2
c2: -316053.16
c3: -316053.161
c4: -316053.1605
c5: -316053.16053
c7: -316053.1605316
c9: -316053.160531605
c19: -316053.1605316053100000000
c28: -316053.1605316053100000000000000000
c0: 505506
c1: 505505.5
c2: 505505.51
c3: 505505.506
c4: 505505.5055
c5: 505505.50551
c7: 505505.5055055
c9: 505505.505505506
c19: 505505.5055055055055055055
c28: 505505.5055055055055055055000000000
c0: -1535020
c1: -1535020.1
c2: -1535020.06
c3: -1535020.062
c4: -1535020.0615
c5: -1535020.06150
c7: -1535020.0615000
c9: -1535020.061500000
c19: -1535020.0615000000000000000
c28: -1535020.0615000000000000000000000000
c0: 7501301
c1: 7501300.7
c2: 7501300.68
c3: 7501300.675
c4: 7501300.6750
c5: 7501300.67501
c7: 7501300.6750130
c9: 7501300.675013007
c19: 7501300.6750130067501300675
c28: 7501300.6750130067501300675013006750
c0: -7540010
c1: -7540010.1
c2: -7540010.07
c3: -7540010.068
c4: -7540010.0675
c5: -7540010.06754
c7: -7540010.0675400
c9: -7540010.067540010
c19: -7540010.0675400100675400101
c28: -7540010.0675400100675400100675400101
c0: 7540450
c1: 7540450.1
c2: 7540450.07
c3: 7540450.068
c4: 7540450.0675
c5: 7540450.06754
c7: 7540450.0675405
c9: 7540450.067540450
c19: 7540450.0675404500675404501
c28: 7540450.0675404500675404500675404500
c0: -820012820012820
c1: -820012820012820.0
c2: -820012820012820.01
c3: -820012820012820.013
c4: -820012820012820.0128
c5: -820012820012820.01282
c7: -820012820012820.0128200
c9: -820012820012820.012820013
c19: -820012820012820.0128200128200128200
c0: 1122551511225515
c1: 1122551511225515.1
c2: 1122551511225515.11
c3: 1122551511225515.112
c4: 1122551511225515.1122
c5: 1122551511225515.11220
c7: 1122551511225515.1122000
c9: 1122551511225515.112200000
c19: 1122551511225515.1122000000000000000
c0: -1234567892112345678912
c1: -1234567892112345678912.3
c2: -1234567892112345678912.35
c3: -1234567892112345678912.346
c4: -1234567892112345678912.3456
c5: -1234567892112345678912.34560
c7: -1234567892112345678912.3456000
c9: -1234567892112345678912.345600000
c0: 123456789012346261234567890123
c1: 123456789012346261234567890123.5
c2: 123456789012346261234567890123.46
c3: 123456789012346261234567890123.463
c4: 123456789012346261234567890123.4629
c5: 123456789012346261234567890123.46290
c7: 123456789012346261234567890123.4629000
c0: -13775323913775323913775323913775323913
Testing numbers between 1 and -1:
c1: .1
c2: .10
c3: .100
c4: .1000
c5: .10000
c7: .1000000
c9: .100000000
c19: .1000000000000000000
c28: .1000000000000000000000000000
c1: -.1
c2: -.13
c3: -.133
c4: -.1333
c5: -.13330
c7: -.1333000
c9: -.133300000
c19: -.1333000000000000000
c28: -.1333000000000000000000000000
c2: .02
c3: .019
c4: .0192
c5: .01918
c7: .0191785
c9: .019178465
c19: .0191784646962022650
c28: .0191784646962022650000000000
c1: -.1
c2: -.08
c3: -.083
c4: -.0833
c5: -.08333
c7: -.0833330
c9: -.083333000
c19: -.0833330000000000000
c28: -.0833330000000000000000000000
c1: .1
c2: .09
c3: .085
c4: .0850
c5: .08500
c7: .0850000
c9: .085000000
c19: .0850000000000000060
c28: .0850000000000000060000000000
c1: -.1
c2: -.09
c3: -.085
c4: -.0852
c5: -.08516
c7: -.0851648
c9: -.085164835
c19: -.0851648351648351680
c28: -.0851648351648351680000000000
c5: .00003
c7: .0000316
c9: .000031600
c19: .0000316000000000000
c28: .0000316000000000000000000000
c4: -.0001
c5: -.00005
c7: -.0000500
c9: -.000050000
c19: -.0000500000000000000
c28: -.0000500000000000000000000000
c5: .00002
c7: .0000154
c9: .000015350
c19: .0000153502000000000
c28: .0000153502000000000000000000
c5: -.00001
c7: -.0000075
c9: -.000007501
c19: -.0000075013000000000
c28: -.0000075013000000000000000000
c5: .00001
c7: .0000075
c9: .000007540
c19: .0000075400100000000
c28: .0000075400100000000000000000
c5: -.00001
c7: -.0000075
c9: -.000007540
c19: -.0000075404500000000
c28: -.0000075404500000000000000000
c19: .0000000000082000000
c28: .0000000000082000000000000000
c19: -.0000000000000011226
c28: -.0000000000000011225500000000
c28: .0000000000000000000012345679
c38: .00000000000000000000123456789000000000
c28: -.0000000000000000000000012346
c38: -.00000000000000000000000123456789012346
c38: .00000000000000000000000000000001377532

View file

@ -3,77 +3,62 @@ Test for inserting and retrieving encrypted data of money types
--DESCRIPTION--
No PDO::PARAM_ tpe specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
$dataTypes = array( "smallmoney", "money" );
try
{
$conn = ae_connect();
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
foreach ( $dataTypes as $dataType ) {
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("smallmoney", "money");
try {
//set to ERRMODE_SILENT to compare actual error and expected unsupport money types in encrypted columns error
$conn = connect('', array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array(new columnMeta($dataType, "c_det", null, "deterministic", true),
new columnMeta($dataType, "c_rand", null, "randomized", true));
createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( !is_col_enc() )
{
if ( $r === false )
{
$stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if (!isColEncrypted()) {
if ($r === false) {
echo "Default type should be compatible with $dataType.\n";
$success = false;
}
else
{
} else {
$sql = "SELECT * FROM $tbname";
$stmt = $conn->query( $sql );
$row = $stmt->fetch( PDO::FETCH_ASSOC );
if ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] )
{
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) {
echo "Incorrect output retrieved for datatype $dataType.\n";
$success = false;
}
}
}
else
{
if ( $r === false )
{
if ( $stmt->errorInfo()[0] != "22018" )
{
} else {
if ($r === false) {
if ($stmt->errorInfo()[0] != "22018") {
echo "Incorrect error returned.\n";
$success = false;
}
}
else
{
} else {
echo "$dataType is not compatible with any type.\n";
$success = false;
}
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of numeric types
--DESCRIPTION--
No PDO::PARAM_ tpe specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );
try
{
$conn = ae_connect();
foreach ( $dataTypes as $dataType ) {
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real");
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $r === false ) {
is_incompatible_types_error( $stmt, $dataType, "default type" );
}
else {
$stmt = insertRow($conn, $tbname, array( "c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,49 +3,42 @@ Test for inserting and retrieving encrypted data of datetime types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
try
{
$conn = ae_connect();
foreach ( $dataTypes as $dataType ) {
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// prepare statement for inserting into table
foreach ( $pdoParamTypes as $pdoParamType ) {
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType )));
if ( $r === false )
{
is_incompatible_types_error( $stmt, $dataType, $pdoParamType );
}
else {
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, $pdoParamType);
} else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
}
$conn->query( "TRUNCATE TABLE $tbname" );
$conn->query("TRUNCATE TABLE $tbname");
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,84 +3,69 @@ Test for inserting and retrieving encrypted data of money types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "smallmoney", "money" );
try
{
$conn = ae_connect();
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
foreach ( $dataTypes as $dataType ) {
try {
//set to ERRMODE_SILENT to compare actual error and expected unsupport money types in encrypted columns error
$conn = connect('', array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($dataType, "c_det", null, "deterministic", true),
new ColumnMeta($dataType, "c_rand", null, "randomized", true));
createTable($conn, $tbname, $colMetaArr);
// test each PDO::PARAM_ type
foreach ( $pdoParamTypes as $pdoParamType ) {
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType )));
if ( !is_col_enc() )
{
if ( $r === false )
{
$stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, (string)$inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, (string)$inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if (!isColEncrypted()) {
if ($r === false) {
echo "$pdoParamType should be compatible with $dataType.\n";
$success = false;
}
else
{
} else {
$sql = "SELECT * FROM $tbname";
$stmt = $conn->query( $sql );
$row = $stmt->fetch( PDO::FETCH_ASSOC );
if ( ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] ) && $pdoParamType != "PDO::PARAM_NULL" )
{
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) && $pdoParamType != "PDO::PARAM_NULL") {
echo "Incorrect output retrieved for datatype $dataType.\n";
var_dump( $inputValues );
var_dump( $row );
var_dump($inputValues);
var_dump($row);
$success = false;
}
}
}
else
{
if ( $r === false )
{
if ( $stmt->errorInfo()[0] != "22018" )
{
} else {
if ($r === false) {
if ($stmt->errorInfo()[0] != "22018") {
echo "Incorrect error returned.\n";
$success = false;
}
}
else
{
} else {
echo "$dataType is not compatible with any type.\n";
$success = false;
}
}
$conn->query( "TRUNCATE TABLE $tbname" );
$conn->query("TRUNCATE TABLE $tbname");
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,49 +3,45 @@ Test for inserting and retrieving encrypted data of numeric types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "bit", "tinyint", "smallint", "int", "decimal(18,5)", "numeric(10,5)", "float", "real" );
try
{
$conn = ae_connect();
foreach ( $dataTypes as $dataType ) {
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// test each PDO::PARAM_ type
foreach ( $pdoParamTypes as $pdoParamType ) {
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType )));
if ( $r === false )
{
is_incompatible_types_error( $stmt, $dataType, $pdoParamType );
if ($dataType == "decimal(18,5)") {
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, (string)$inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, (string)$inputValues[1], $pdoParamType)), "prepareBindParam", $r);
} else {
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
}
else {
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, $pdoParamType);
} else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
}
$conn->query( "TRUNCATE TABLE $tbname" );
$conn->query("TRUNCATE TABLE $tbname");
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
@ -121,20 +117,20 @@ c_rand: 2147483647
Testing decimal(18,5):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted decimal(18,5)****
c_det: -9223372036854.80078
c_rand: 9223372036854.80078
c_det: -9223372036854.80000
c_rand: 9223372036854.80000
****PDO param type PDO::PARAM_NULL is compatible with encrypted decimal(18,5)****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted decimal(18,5)****
c_det: -9223372036854.80078
c_rand: 9223372036854.80078
c_det: -9223372036854.80000
c_rand: 9223372036854.80000
****PDO param type PDO::PARAM_STR is compatible with encrypted decimal(18,5)****
c_det: -9223372036854.80000
c_rand: 9223372036854.80000
****PDO param type PDO::PARAM_LOB is compatible with encrypted decimal(18,5)****
c_det: -9223372036854.80078
c_rand: 9223372036854.80078
c_det: -9223372036854.80000
c_rand: 9223372036854.80000
Testing numeric(10,5):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted numeric(10,5)****

View file

@ -3,50 +3,41 @@ Test for inserting and retrieving encrypted data of string types
--DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
try
{
$conn = ae_connect();
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
foreach ( $dataTypes as $dataType ) {
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)");
try {
$conn = connect('', array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// prepare statement for inserting into table
foreach ( $pdoParamTypes as $pdoParamType ) {
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType )));
if ( $r === false )
{
is_incompatible_types_error( $stmt, $dataType, $pdoParamType );
}
else {
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType),"c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, $pdoParamType);
} else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
}
$conn->query( "TRUNCATE TABLE $tbname" );
$conn->query("TRUNCATE TABLE $tbname");
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -3,73 +3,60 @@ Test for inserting encrypted data and retrieving both encrypted and decrypted da
--DESCRIPTION--
Retrieving SQL query contains encrypted filter
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
try
{
$conn = ae_connect();
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect();
// Create the table
$tbname = 'Patients';
$colMetaArr = array( new columnMeta( "int", "PatientId", "IDENTITY(1,1)" ),
new columnMeta( "char(11)", "SSN"),
new columnMeta( "nvarchar(50)", "FirstName", "NULL" ),
new columnMeta( "nvarchar(50)", "LastName", "NULL"),
new columnMeta( "date", "BirthDate", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new ColumnMeta("int", "PatientId", "IDENTITY(1,1)"),
new ColumnMeta("char(11)", "SSN"),
new ColumnMeta("nvarchar(50)", "FirstName", "NULL"),
new ColumnMeta("nvarchar(50)", "LastName", "NULL"),
new ColumnMeta("date", "BirthDate", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// insert a row
$SSN = "795-73-9838";
$inputs = array( "SSN" => $SSN, "FirstName" => "Catherine", "LastName" => "Abel", "BirthDate" => "1996-10-19" );
$stmt = insert_row( $conn, $tbname, $inputs );
$stmt = insertRow($conn, $tbname, $inputs);
echo "Retrieving plaintext data:\n";
$selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname WHERE SSN = ?";
$stmt = $conn->prepare( $selectSql );
$stmt->bindParam( 1, $SSN );
$stmt = $conn->prepare($selectSql);
$stmt->bindParam(1, $SSN);
$stmt->execute();
$decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC );
foreach ( $decrypted_row as $key => $value )
{
$decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC);
foreach ($decrypted_row as $key => $value) {
print "$key: $value\n";
}
unset( $stmt );
}
catch( PDOException $e )
{
unset($stmt);
} catch (PDOException $e) {
echo $e->getMessage();
}
// for AE only
echo "\nChecking ciphertext data:\n";
if ( is_col_enc() )
{
try
{
$conn1 = ae_connect( null, null, true );
if (isColEncrypted()) {
try {
$conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true);
$selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname";
$stmt = $conn1->query( $selectSql );
$encrypted_row = $stmt->fetch( PDO::FETCH_ASSOC );
foreach ( $encrypted_row as $key => $value )
{
if ( ctype_print( $value ))
$stmt = $conn1->query($selectSql);
$encrypted_row = $stmt->fetch(PDO::FETCH_ASSOC);
foreach ($encrypted_row as $key => $value) {
if (ctype_print($value)) {
print "Error: expected a binary array for $key\n";
}
}
unset( $stmt );
unset( $conn1 );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn1);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
unset( $conn );
dropTable($conn, $tbname);
unset($conn);
echo "Done\n";
?>
--EXPECT--

View file

@ -1,80 +1,64 @@
--TEST--
Test for inserting encrypted fixed size types data and retrieve both encrypted and decrypted data
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
try
{
$conn = ae_connect();
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect();
// Create the table
$tbname = 'FixedSizeAnalysis';
$colMetaArr = array( new columnMeta( "tinyint", "TinyIntData" ),
new columnMeta( "smallint", "SmallIntData" ),
new columnMeta( "int", "IntData" ),
new columnMeta( "bigint", "BigIntData" ),
new columnMeta( "decimal(38,0)", "DecimalData" ),
new columnMeta( "bit", "BitData" ),
new columnMeta( "datetime", "DateTimeData" ),
new columnMeta( "datetime2", "DateTime2Data" ));
create_table( $conn, $tbname, $colMetaArr );
// insert a row
$inputs = array( "TinyIntData" => 255,
"SmallIntData" => 32767,
"IntData" => 2147483647,
"BigIntData" => 92233720368547,
"DecimalData" => 79228162514264,
"BitData" => true,
"DateTimeData" => '9999-12-31 23:59:59.997',
"DateTime2Data" => '9999-12-31 23:59:59.9999999');
$paramOptions = array( new bindParamOption( 4, "PDO::PARAM_INT" ) );
$r;
$stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions );
print "Decrypted values:\n";
fetch_all( $conn, $tbname );
$colMetaArr = array("TinyIntData" => "tinyint",
"SmallIntData" => "smallint",
"IntData" => "int",
"BigIntData" => "bigint",
"DecimalData" => "decimal(18,0)",
"BitData" => "bit",
"DateTimeData" => "datetime",
"DateTime2Data" => "datetime2");
createTable($conn, $tbname, $colMetaArr);
unset( $stmt );
}
catch( PDOException $e )
{
// insert a row
$inputs = array( "TinyIntData" => 255,
"SmallIntData" => 32767,
"IntData" => 2147483647,
"BigIntData" => 92233720368547,
"DecimalData" => 79228162514264,
"BitData" => true,
"DateTimeData" => '9999-12-31 23:59:59.997',
"DateTime2Data" => '9999-12-31 23:59:59.9999999');
//$paramOptions = array( new bindParamOption(4, "PDO::PARAM_INT") );
$r;
$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r);
print "Decrypted values:\n";
fetchAll($conn, $tbname);
unset($stmt);
} catch (PDOException $e) {
echo $e->getMessage();
}
// for AE only
if ( is_col_enc() )
{
try
{
$conn1 = ae_connect( null, null, true );
if (isColEncrypted()) {
try {
$conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true);
$selectSql = "SELECT * FROM $tbname";
$stmt = $conn1->query( $selectSql );
$encrypted_row = $stmt->fetch( PDO::FETCH_ASSOC );
foreach ( $encrypted_row as $key => $value )
{
if ( ctype_print( $value ))
{
$stmt = $conn1->query($selectSql);
$encrypted_row = $stmt->fetch(PDO::FETCH_ASSOC);
foreach ($encrypted_row as $key => $value) {
if (ctype_print($value)) {
print "Error: expected a binary array for $key\n";
}
}
unset( $stmt );
unset( $conn1 );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn1);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
unset( $conn );
dropTable($conn, $tbname);
unset($conn);
echo "Done\n";
?>
--EXPECT--
@ -87,4 +71,4 @@ DecimalData: 79228162514264
BitData: 1
DateTimeData: 9999-12-31 23:59:59.997
DateTime2Data: 9999-12-31 23:59:59.9999999
Done
Done

View file

@ -1,79 +1,60 @@
--TEST--
Test for inserting encrypted nvarchar data of variable lengths and retrieving encrypted and decrypted data
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
$testPass = true;
try
{
$conn = ae_connect();
try {
$conn = connect();
// Create the table
$tbname = 'NVarcharAnalysis';
$colMetaArr = array( new columnMeta( "int", "CharCount", "IDENTITY(0,1)" ), new columnMeta( "nvarchar(1000)" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new columnMeta("nvarchar(1000)"));
createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
for ( $i = 0; $i < 1000; $i++ )
{
$data = str_repeat( "*", $i );
$stmt = insert_row( $conn, $tbname, array( get_default_colname( "nvarchar(1000)" ) => $data ) );
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = insertRow($conn, $tbname, array(getDefaultColName("nvarchar(1000)") => $data));
}
$selectSql = "SELECT * FROM $tbname";
$stmt = $conn->query( $selectSql );
while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] ))
{
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
$stmt = $conn->query($selectSql);
while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) {
$rowInd = $decrypted_row['CharCount'] + 1;
echo "Failed to decrypted at row $rowInd\n";
$testPass = false;
}
}
unset( $stmt );
}
catch( PDOException $e )
{
unset($stmt);
} catch (PDOException $e) {
echo $e->getMessage();
}
// for AE only
if ( is_col_enc() )
{
try
{
$conn1 = ae_connect( null, null, true );
$stmt = $conn1->query( $selectSql );
while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] ))
{
if (isColEncrypted()) {
try {
$conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true);
$stmt = $conn1->query($selectSql);
while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($decrypted_row['CharCount'] == strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) {
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
echo "Failed to encrypted at row $rowInd\n";
$testPass = false;
}
}
unset( $stmt );
unset( $conn1 );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn1);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
unset( $conn );
if ( $testPass ) {
dropTable($conn, $tbname);
unset($conn);
if ($testPass) {
echo "Test successfully done.\n";
}
?>
--EXPECT--
Test successfully done.
Test successfully done.

View file

@ -1,78 +1,60 @@
--TEST--
Test for inserting encrypted varchar data of variable lengths and retrieving encrypted and decrypted data
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
$testPass = true;
try
{
$conn = ae_connect();
try {
$conn = connect();
// Create the table
$tbname = 'VarcharAnalysis';
$colMetaArr = array( new columnMeta( "int", "CharCount", "IDENTITY(0,1)" ), new columnMeta( "varchar(1000)" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new ColumnMeta("varchar(1000)"));
createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
for( $i = 0; $i < 1000; $i++ )
{
$data = str_repeat( "*", $i );
$stmt = insert_row( $conn, $tbname, array( get_default_colname( "varchar(1000)" ) => $data ) );
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = insertRow($conn, $tbname, array(getDefaultColname("varchar(1000)") => $data));
}
$selectSql = "SELECT * FROM $tbname";
$stmt = $conn->query( $selectSql );
while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] ))
{
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
$stmt = $conn->query($selectSql);
while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColname("varchar(1000)")])) {
$rowInd = $decrypted_row['CharCount'] + 1;
echo "Failed to decrypted at row $rowInd\n";
$testPass = false;
}
}
unset( $stmt );
}
catch( PDOException $e )
{
unset($stmt);
} catch (PDOException $e) {
echo $e->getMessage();
}
// for AE only
if ( is_col_enc() )
{
try
{
$conn1 = ae_connect( null, null, true );
$stmt = $conn1->query( $selectSql );
while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] ))
{
if (isColEncrypted()) {
try {
$conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true);
$stmt = $conn1->query($selectSql);
while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($decrypted_row['CharCount'] == strlen($decrypted_row[getDefaultColname("varchar(1000)")])) {
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
echo "Failed to encrypted at row $rowInd\n";
$testPass = false;
}
}
unset( $stmt );
unset( $conn1 );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn1);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
DropTable( $conn, $tbname );
unset( $conn );
if ( $testPass ) {
dropTable($conn, $tbname);
unset($conn);
if ($testPass) {
echo "Test successfully done.\n";
}
?>
--EXPECT--
Test successfully done.
Test successfully done.

View file

@ -0,0 +1,405 @@
--TEST--
Test for inserting into and retrieving from decimal columns of different scale
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
$posExp = array(-0.00e+01, 10.0E+00, -1.333e+1, 1.9178464696202265E+2, -8.3333e+2, 8.5000000000000006E+2, -8.5164835164835168E+2, 3.16E+05, -5E+05, 1.53502e+006, -7.5013e+006, 7.54001e+006, -7.54045e+006, 820.0E+10, -1.12255E+7, 1.23456789E+9, -1.23456789012346E+7, 1.377532E+10);
$negExp = array(0.00e-01, -10.0E-00, 1.333e-1, -1.9178464696202265E-2, 8.3333e-2, -8.5000000000000006E-2, 8.5164835164835168E-2, -3.16E-01, 5E-03, -1.53502e-004, 7.5013e-004, -7.54001e-004, 7.54045e-004, -820.0E-1, 1.12255E-4, -1.23456789E-3, 1.23456789012346E-4, -1.377532E-1);
$numSets = array("Testing numbers greater than 1 or less than -1:" => $posExp,
"Testing numbers between 1 and -1:" => $negExp);
$scalesToTest = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19);
try {
$conn = connect();
$tbname = "decimalTable";
foreach ($numSets as $testName => $numSet) {
echo "\n$testName\n";
foreach ($numSet as $input) {
$numInt = ceil(log10(abs($input) + 1));
$decimalTypes = array();
foreach ($scalesToTest as $scale) {
if ($scale < 39 - $numInt) {
$decimalTypes = array_merge($decimalTypes, array("c$scale" => "decimal(38, $scale)"));
}
}
if (empty($decimalTypes)) {
$decimalTypes = array("c0" => "decimal(38, 0)");
}
createTable($conn, $tbname, $decimalTypes);
$insertValues = array();
foreach ($decimalTypes as $key => $value) {
if (isColEncrypted()) {
$insertValues = array_merge($insertValues, array($key => strval($input)));
} else {
$insertValues = array_merge($insertValues, array($key => $input));
}
}
insertRow($conn, $tbname, $insertValues, "prepareBindParam");
$stmt = $conn->query("SELECT * FROM $tbname");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
foreach ($row as $key => $value) {
if ($value != 0) {
echo "$key: $value\n";
}
}
$conn->exec("TRUNCATE TABLE $tbname");
}
}
dropTable($conn, $tbname);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Testing numbers greater than 1 or less than -1:
c0: 10
c1: 10.0
c2: 10.00
c3: 10.000
c4: 10.0000
c5: 10.00000
c6: 10.000000
c7: 10.0000000
c8: 10.00000000
c9: 10.000000000
c19: 10.0000000000000000000
c0: -13
c1: -13.3
c2: -13.33
c3: -13.330
c4: -13.3300
c5: -13.33000
c6: -13.330000
c7: -13.3300000
c8: -13.33000000
c9: -13.330000000
c19: -13.3300000000000000000
c0: 192
c1: 191.8
c2: 191.78
c3: 191.785
c4: 191.7846
c5: 191.78465
c6: 191.784647
c7: 191.7846470
c8: 191.78464696
c9: 191.784646962
c19: 191.7846469620200000000
c0: -833
c1: -833.3
c2: -833.33
c3: -833.330
c4: -833.3300
c5: -833.33000
c6: -833.330000
c7: -833.3300000
c8: -833.33000000
c9: -833.330000000
c19: -833.3300000000000000000
c0: 850
c1: 850.0
c2: 850.00
c3: 850.000
c4: 850.0000
c5: 850.00000
c6: 850.000000
c7: 850.0000000
c8: 850.00000000
c9: 850.000000000
c19: 850.0000000000000000000
c0: -852
c1: -851.6
c2: -851.65
c3: -851.648
c4: -851.6484
c5: -851.64835
c6: -851.648352
c7: -851.6483516
c8: -851.64835165
c9: -851.648351648
c19: -851.6483516483500000000
c0: 316000
c1: 316000.0
c2: 316000.00
c3: 316000.000
c4: 316000.0000
c5: 316000.00000
c6: 316000.000000
c7: 316000.0000000
c8: 316000.00000000
c9: 316000.000000000
c19: 316000.0000000000000000000
c0: -500000
c1: -500000.0
c2: -500000.00
c3: -500000.000
c4: -500000.0000
c5: -500000.00000
c6: -500000.000000
c7: -500000.0000000
c8: -500000.00000000
c9: -500000.000000000
c19: -500000.0000000000000000000
c0: 1535020
c1: 1535020.0
c2: 1535020.00
c3: 1535020.000
c4: 1535020.0000
c5: 1535020.00000
c6: 1535020.000000
c7: 1535020.0000000
c8: 1535020.00000000
c9: 1535020.000000000
c19: 1535020.0000000000000000000
c0: -7501300
c1: -7501300.0
c2: -7501300.00
c3: -7501300.000
c4: -7501300.0000
c5: -7501300.00000
c6: -7501300.000000
c7: -7501300.0000000
c8: -7501300.00000000
c9: -7501300.000000000
c19: -7501300.0000000000000000000
c0: 7540010
c1: 7540010.0
c2: 7540010.00
c3: 7540010.000
c4: 7540010.0000
c5: 7540010.00000
c6: 7540010.000000
c7: 7540010.0000000
c8: 7540010.00000000
c9: 7540010.000000000
c19: 7540010.0000000000000000000
c0: -7540450
c1: -7540450.0
c2: -7540450.00
c3: -7540450.000
c4: -7540450.0000
c5: -7540450.00000
c6: -7540450.000000
c7: -7540450.0000000
c8: -7540450.00000000
c9: -7540450.000000000
c19: -7540450.0000000000000000000
c0: 8200000000000
c1: 8200000000000.0
c2: 8200000000000.00
c3: 8200000000000.000
c4: 8200000000000.0000
c5: 8200000000000.00000
c6: 8200000000000.000000
c7: 8200000000000.0000000
c8: 8200000000000.00000000
c9: 8200000000000.000000000
c19: 8200000000000.0000000000000000000
c0: -11225500
c1: -11225500.0
c2: -11225500.00
c3: -11225500.000
c4: -11225500.0000
c5: -11225500.00000
c6: -11225500.000000
c7: -11225500.0000000
c8: -11225500.00000000
c9: -11225500.000000000
c19: -11225500.0000000000000000000
c0: 1234567890
c1: 1234567890.0
c2: 1234567890.00
c3: 1234567890.000
c4: 1234567890.0000
c5: 1234567890.00000
c6: 1234567890.000000
c7: 1234567890.0000000
c8: 1234567890.00000000
c9: 1234567890.000000000
c19: 1234567890.0000000000000000000
c0: -12345679
c1: -12345678.9
c2: -12345678.90
c3: -12345678.901
c4: -12345678.9012
c5: -12345678.90124
c6: -12345678.901235
c7: -12345678.9012350
c8: -12345678.90123500
c9: -12345678.901235000
c19: -12345678.9012350000000000000
c0: 13775320000
c1: 13775320000.0
c2: 13775320000.00
c3: 13775320000.000
c4: 13775320000.0000
c5: 13775320000.00000
c6: 13775320000.000000
c7: 13775320000.0000000
c8: 13775320000.00000000
c9: 13775320000.000000000
c19: 13775320000.0000000000000000000
Testing numbers between 1 and -1:
c0: -10
c1: -10.0
c2: -10.00
c3: -10.000
c4: -10.0000
c5: -10.00000
c6: -10.000000
c7: -10.0000000
c8: -10.00000000
c9: -10.000000000
c19: -10.0000000000000000000
c1: .1
c2: .13
c3: .133
c4: .1333
c5: .13330
c6: .133300
c7: .1333000
c8: .13330000
c9: .133300000
c19: .1333000000000000000
c2: -.02
c3: -.019
c4: -.0192
c5: -.01918
c6: -.019178
c7: -.0191785
c8: -.01917846
c9: -.019178465
c19: -.0191784646962020000
c1: .1
c2: .08
c3: .083
c4: .0833
c5: .08333
c6: .083333
c7: .0833330
c8: .08333300
c9: .083333000
c19: .0833330000000000000
c1: -.1
c2: -.09
c3: -.085
c4: -.0850
c5: -.08500
c6: -.085000
c7: -.0850000
c8: -.08500000
c9: -.085000000
c19: -.0850000000000000000
c1: .1
c2: .09
c3: .085
c4: .0852
c5: .08516
c6: .085165
c7: .0851648
c8: .08516484
c9: .085164835
c19: .0851648351648350000
c1: -.3
c2: -.32
c3: -.316
c4: -.3160
c5: -.31600
c6: -.316000
c7: -.3160000
c8: -.31600000
c9: -.316000000
c19: -.3160000000000000000
c2: .01
c3: .005
c4: .0050
c5: .00500
c6: .005000
c7: .0050000
c8: .00500000
c9: .005000000
c19: .0050000000000000000
c4: -.0002
c5: -.00015
c6: -.000154
c7: -.0001535
c8: -.00015350
c9: -.000153502
c19: -.0001535020000000000
c3: .001
c4: .0008
c5: .00075
c6: .000750
c7: .0007501
c8: .00075013
c9: .000750130
c19: .0007501300000000000
c3: -.001
c4: -.0008
c5: -.00075
c6: -.000754
c7: -.0007540
c8: -.00075400
c9: -.000754001
c19: -.0007540010000000000
c3: .001
c4: .0008
c5: .00075
c6: .000754
c7: .0007540
c8: .00075405
c9: .000754045
c19: .0007540450000000000
c0: -82
c1: -82.0
c2: -82.00
c3: -82.000
c4: -82.0000
c5: -82.00000
c6: -82.000000
c7: -82.0000000
c8: -82.00000000
c9: -82.000000000
c19: -82.0000000000000000000
c4: .0001
c5: .00011
c6: .000112
c7: .0001123
c8: .00011226
c9: .000112255
c19: .0001122550000000000
c3: -.001
c4: -.0012
c5: -.00123
c6: -.001235
c7: -.0012346
c8: -.00123457
c9: -.001234568
c19: -.0012345678900000000
c4: .0001
c5: .00012
c6: .000123
c7: .0001235
c8: .00012346
c9: .000123457
c19: .0001234567890123500
c1: -.1
c2: -.14
c3: -.138
c4: -.1378
c5: -.13775
c6: -.137753
c7: -.1377532
c8: -.13775320
c9: -.137753200
c19: -.1377532000000000000

View file

@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of string types
--DESCRIPTION--
No PDO::PARAM_ type specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
try
{
$conn = ae_connect();
foreach ( $dataTypes as $dataType ) {
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)");
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $r === false ) {
is_incompatible_types_error( $stmt, $dataType, "default type" );
}
else {
$stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
fetchAll($conn, $tbname);
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
unset( $stmt );
unset( $conn );
}
catch( PDOException $e )
{
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

View file

@ -1,84 +1,78 @@
--TEST--
Test for binding output params for encrypted data for all types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
$conn = ae_connect();
require_once("MsCommon_mid-refactor.inc");
$conn = connect();
// Create the table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( "int", "c1_int" ),
new columnMeta( "smallint", "c2_smallint" ),
new columnMeta( "tinyint", "c3_tinyint" ),
new columnMeta( "bit", "c4_bit" ),
new columnMeta( "bigint", "c5_bigint" ),
new columnMeta( "decimal(18,5)", "c6_decimal" ),
new columnMeta( "numeric(10,5)", "c7_numeric" ),
new columnMeta( "float", "c8_float" ),
new columnMeta( "real", "c9_real" ),
new columnMeta( "date", "c10_date" ),
new columnMeta( "datetime", "c11_datetime" ),
new columnMeta( "datetime2", "c12_datetime2" ),
new columnMeta( "datetimeoffset", "c13_datetimeoffset" ),
new columnMeta( "time", "c14_time" ),
new columnMeta( "char(5)", "c15_char" ),
new columnMeta( "varchar(max)", "c16_varchar" ),
new columnMeta( "nchar(5)", "c17_nchar" ),
new columnMeta( "nvarchar(max)", "c18_nvarchar" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = getTableName();
$colMetaArr = array("c1_int" => "int",
"c2_smallint" => "smallint",
"c3_tinyint" => "tinyint",
"c4_bit" => "bit",
"c5_bigint" => "bigint",
"c6_decimal" => "decimal(18,5)",
"c7_numeric" => "numeric(10,5)",
"c8_float" => "float",
"c9_real" => "real",
"c10_date" => "date",
"c11_datetime" => "datetime",
"c12_datetime2" => "datetime2",
"c13_datetimeoffset" => "datetimeoffset",
"c14_time" => "time",
"c15_char" => "char(5)",
"c16_varchar" => "varchar(max)",
"c17_nchar" => "nchar(5)",
"c18_nvarchar" => "nvarchar(max)");
createTable($conn, $tbname, $colMetaArr);
// Create a Store Procedure
$spname = 'selectAllColumns';
$spSql = "CREATE PROCEDURE $spname (
@c1_int int OUTPUT, @c2_smallint smallint OUTPUT,
@c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT,
@c1_int int OUTPUT, @c2_smallint smallint OUTPUT,
@c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT,
@c5_bigint bigint OUTPUT, @c6_decimal decimal(18,5) OUTPUT,
@c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT,
@c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT,
@c9_real real OUTPUT, @c10_date date OUTPUT,
@c11_datetime datetime OUTPUT, @c12_datetime2 datetime2 OUTPUT,
@c13_datetimeoffset datetimeoffset OUTPUT, @c14_time time OUTPUT,
@c15_char char(5) OUTPUT, @c16_varchar varchar(max) OUTPUT,
@c17_nchar nchar(5) OUTPUT, @c18_nvarchar nvarchar(max) OUTPUT) AS
SELECT @c1_int = c1_int, @c2_smallint = c2_smallint,
@c3_tinyint = c3_tinyint, @c4_bit = c4_bit,
@c5_bigint = c5_bigint, @c6_decimal = c6_decimal,
@c7_numeric = c7_numeric, @c8_float = c8_float,
@c9_real = c9_real, @c10_date = c10_date,
SELECT @c1_int = c1_int, @c2_smallint = c2_smallint,
@c3_tinyint = c3_tinyint, @c4_bit = c4_bit,
@c5_bigint = c5_bigint, @c6_decimal = c6_decimal,
@c7_numeric = c7_numeric, @c8_float = c8_float,
@c9_real = c9_real, @c10_date = c10_date,
@c11_datetime = c11_datetime, @c12_datetime2 = c12_datetime2,
@c13_datetimeoffset = c13_datetimeoffset, @c14_time = c14_time,
@c15_char = c15_char, @c16_varchar = c16_varchar,
@c17_nchar = c17_nchar, @c18_nvarchar = c18_nvarchar
FROM $tbname";
$conn->query( $spSql );
$conn->query($spSql);
// Insert data
$inputs = array( "c1_int" => 2147483647,
"c2_smallint" => 32767,
"c3_tinyint" => 255,
"c4_bit" => 1,
"c5_bigint" => 922337203685479936,
"c6_decimal" => 9223372036854.80000,
"c7_numeric" => 21474.83647,
$inputs = array( "c1_int" => 2147483647,
"c2_smallint" => 32767,
"c3_tinyint" => 255,
"c4_bit" => 1,
"c5_bigint" => 922337203685479936,
"c6_decimal" => 9223372036854.80000,
"c7_numeric" => 21474.83647,
"c8_float" => 9223372036.8548,
"c9_real" => 2147.483,
"c10_date" => '9999-12-31',
"c11_datetime" => '9999-12-31 23:59:59.997',
"c12_datetime2" => '9999-12-31 23:59:59.9999999',
"c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00',
"c14_time" => '23:59:59.9999999',
"c15_char" => 'th, n',
"c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.',
"c17_nchar" => 'th Un',
"c9_real" => 2147.483,
"c10_date" => '9999-12-31',
"c11_datetime" => '9999-12-31 23:59:59.997',
"c12_datetime2" => '9999-12-31 23:59:59.9999999',
"c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00',
"c14_time" => '23:59:59.9999999',
"c15_char" => 'th, n',
"c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.',
"c17_nchar" => 'th Un',
"c18_nvarchar" => 'When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).' );
$paramOptions = array( new bindParamOption( 5, "PDO::PARAM_INT" ) );
$r;
$stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions );
$stmt = insertRow($conn, $tbname, $inputs, null, $r);
// Call store procedure
$outSql = get_callProcSql_placeholders( $spname, count( $inputs ));
$outSql = getCallProcSqlPlaceholders($spname, count($inputs));
$intOut = 0;
$smallintOut = 0;
$tinyintOut = 0;
@ -97,7 +91,7 @@ $charOut = '';
$varcharOut = '';
$ncharOut = '';
$nvarcharOut = '';
$stmt = $conn->prepare( $outSql );
$stmt = $conn->prepare($outSql);
$stmt->bindParam(1, $intOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE);
$stmt->bindParam(2, $smallintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE);
$stmt->bindParam(3, $tinyintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE);
@ -117,31 +111,28 @@ $stmt->bindParam(16, $varcharOut, PDO::PARAM_STR, 2048);
$stmt->bindParam(17, $ncharOut, PDO::PARAM_STR, 2048);
$stmt->bindParam(18, $nvarcharOut, PDO::PARAM_STR, 2048);
$stmt->execute();
print ( "intOut: " . $intOut . "\n" );
print ( "smallintOut: " . $smallintOut . "\n" );
print ( "tinyintOut: " . $tinyintOut . "\n" );
print ( "bitOut: " . $bitOut . "\n" );
print ( "bigintOut: " . $bigintOut . "\n" );
print ( "decimalOut: " . $decimalOut . "\n" );
print ( "numericOut: " . $numericOut . "\n" );
print ( "floatOut: " . $floatOut . "\n" );
print ( "realOut: " . $realOut . "\n" );
print ( "dateOut: " . $dateOut . "\n" );
print ( "datetimeOut: " . $datetimeOut . "\n" );
print ( "datetime2Out: " . $datetime2Out . "\n" );
print ( "datetimeoffsetOut: " . $datetimeoffsetOut . "\n" );
print ( "timeOut: " . $timeOut . "\n" );
print ( "charOut: " . $charOut . "\n" );
print ( "varcharOut: " . $varcharOut . "\n" );
print ( "ncharOut: " . $ncharOut . "\n" );
print ( "nvarcharOut: " . $nvarcharOut . "\n" );
$conn->query( "DROP PROCEDURE $spname" );
$conn->query( "DROP TABLE $tbname" );
unset( $stmt );
unset( $conn );
print("intOut: " . $intOut . "\n");
print("smallintOut: " . $smallintOut . "\n");
print("tinyintOut: " . $tinyintOut . "\n");
print("bitOut: " . $bitOut . "\n");
print("bigintOut: " . $bigintOut . "\n");
print("decimalOut: " . $decimalOut . "\n");
print("numericOut: " . $numericOut . "\n");
print("floatOut: " . $floatOut . "\n");
print("realOut: " . $realOut . "\n");
print("dateOut: " . $dateOut . "\n");
print("datetimeOut: " . $datetimeOut . "\n");
print("datetime2Out: " . $datetime2Out . "\n");
print("datetimeoffsetOut: " . $datetimeoffsetOut . "\n");
print("timeOut: " . $timeOut . "\n");
print("charOut: " . $charOut . "\n");
print("varcharOut: " . $varcharOut . "\n");
print("ncharOut: " . $ncharOut . "\n");
print("nvarcharOut: " . $nvarcharOut . "\n");
dropProc($conn, $spname);
dropTable($conn, $tbname);
unset($stmt);
unset($conn);
?>
--EXPECTREGEX--
intOut: 2147483647
@ -161,4 +152,4 @@ timeOut: 23:59:59\.9999999
charOut: th\, n
varcharOut: This large row size can cause errors \(such as error 512\) during some normal operations\, such as a clustered index key update\, or sorts of the full column set\, which users cannot anticipate until performing an operation\.
ncharOut: th Un
nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\).
nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\).

View file

@ -0,0 +1,66 @@
--TEST--
Test error from preparing a parameterized query with direct query or emulate prepare when Column Encryption is enabled
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
try {
$connection = connect();
$tbname = "TEST";
createTable($connection, $tbname, array(new ColumnMeta("int", "id", "IDENTITY(1,1) NOT NULL"), "name" => "nvarchar(max)"));
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
try {
$name = "Edward";
$st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", array(PDO::SQLSRV_ATTR_DIRECT_QUERY => true));
$st->execute(array("p0" => $name));
} catch (PDOException $e) {
$error = $e->errorInfo;
// expects an exception if Column Encryption is enabled
if (isColEncrypted()) {
if ($error[0] != "IMSSP" ||
$error[1] != -81 ||
$error[2] != "Parameterized statement with attribute PDO::SQLSRV_ATTR_DIRECT_QUERY is not supported in a Column Encryption enabled Connection.") {
echo "An unexpected exception was caught.\n";
var_dump($error);
}
} else {
var_dump($error);
}
}
try {
$name = "Alphonse";
$st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", array(PDO::ATTR_EMULATE_PREPARES => true));
$st->execute(array("p0" => $name));
} catch (PDOException $e) {
$error = $e->errorInfo;
// expects an exception if Column Encryption is enabled
if (isColEncrypted()) {
if ($error[0] != "IMSSP" ||
$error[1] != -82 ||
$error[2] != "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.") {
echo "An unexpected exception was caught.\n";
var_dump($error);
}
} else {
var_dump($error);
}
}
try {
dropTable($connection, $tbname);
unset($st);
unset($connection);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
echo "Done\n";
?>
--EXPECT--
Done

View file

@ -14,6 +14,7 @@ createTable($conn, $tbname, array("c1_bigint" => "bigint"));
// Create a Stored Procedure
$spname = "selectBigint";
dropProc($conn, $spname);
$spSql = "CREATE PROCEDURE $spname (@c1_bigint bigint OUTPUT) AS
SELECT @c1_bigint = c1_bigint FROM $tbname";
$conn->query($spSql);

View file

@ -14,6 +14,7 @@ createTable($conn, $tbname, array("c1_bool" => "int"));
// Create a Stored Procedure
$spname = "selectBool";
dropProc($conn, $spname);
$spSql = "CREATE PROCEDURE $spname (@c1_bool int OUTPUT) AS
SELECT @c1_bool = c1_bool FROM $tbname";
$conn->query($spSql);

View file

@ -52,6 +52,7 @@ function testValidValues()
case 17:
$value = "{ODBC Driver 17 for SQL Server}";
break;
case 14:
case 13:
$value = "{ODBC Driver 13 for SQL Server}";
break;
@ -60,7 +61,7 @@ function testValidValues()
$value = "{ODBC Driver 11 for SQL Server}";
break;
default:
$value = "invalid value";
$value = "invalid value $msodbcsqlMaj";
}
$connectionOptions = "Driver = $value";
connectVerifyOutput($connectionOptions);
@ -70,6 +71,7 @@ function testValidValues()
case 17:
$value = "ODBC Driver 17 for SQL Server";
break;
case 14:
case 13:
$value = "ODBC Driver 13 for SQL Server";
break;
@ -78,7 +80,7 @@ function testValidValues()
$value = "ODBC Driver 11 for SQL Server";
break;
default:
$value = "invalid value";
$value = "invalid value $msodbcsqlMaj";
}
$connectionOptions = "Driver = $value";

View file

@ -17,218 +17,194 @@ non-MARS connection. This should fail too.
// when exiting the helper method? Do the associated cursors remain active? It is an
// unnecessary complication, so I have left the code like this.
require_once( "break_pdo.php" );
require_once("break_pdo.php");
require_once("MsCommon_mid-refactor.inc");
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
$conn_break = connect();
///////////////////////////////////////////////////////////////////////////////
// Part 1
// Part 1
// Expected to successfully execute second query because buffered cursor for
// first query means connection is idle when broken
///////////////////////////////////////////////////////////////////////////////
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;";
try
{
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e )
{
try {
// TODO: Idle connection resiliency does not work with Column Encryption at this point
// Do not connect with ColumnEncryption for now
$conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true);
} catch (PDOException $e) {
echo "Could not connect.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$query1 = "SELECT * FROM $tableName1";
try
{
$stmt1 = $conn->prepare( $query1, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) );
if ( $stmt1->execute() ) echo "Statement 1 successful.\n";
try {
$stmt1 = $conn->prepare($query1, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ));
if ($stmt1->execute()) {
echo "Statement 1 successful.\n";
}
$rowcount = $stmt1->rowCount();
echo $rowcount." rows in result set.\n";
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Error executing statement 1.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
BreakConnection( $conn, $conn_break );
breakConnection($conn, $conn_break);
$query2 = "SELECT * FROM $tableName2";
try
{
$stmt2 = $conn->prepare( $query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) );
if ( $stmt2->execute() ) echo "Statement 2 successful.\n";
try {
$stmt2 = $conn->prepare($query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ));
if ($stmt2->execute()) {
echo "Statement 2 successful.\n";
}
$rowcount = $stmt2->rowCount();
echo $rowcount." rows in result set.\n";
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Error executing statement 2.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$conn = null;
unset($conn);
///////////////////////////////////////////////////////////////////////////////
// Part 2
// Part 2
// Expected to successfully execute second query because first statement is
// freed before breaking connection
///////////////////////////////////////////////////////////////////////////////
try
{
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e )
{
try {
$conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true);
} catch (PDOException $e) {
echo "Could not connect.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$query1 = "SELECT * FROM $tableName1";
try
{
$stmt3 = $conn->query( $query1 );
if ( $stmt3 ) echo "Statement 3 successful.\n";
try {
$stmt3 = $conn->query($query1);
if ($stmt3) {
echo "Statement 3 successful.\n";
}
$rowcount = $stmt3->rowCount();
echo $rowcount." rows in result set.\n";
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Error executing statement 3.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$stmt3 = null;
unset($stmt3);
BreakConnection( $conn, $conn_break );
breakConnection($conn, $conn_break);
$query2 = "SELECT * FROM $tableName2";
try
{
$stmt4 = $conn->query( $query2 );
if ( $stmt4 ) echo "Statement 4 successful.\n";
try {
$stmt4 = $conn->query($query2);
if ($stmt4) {
echo "Statement 4 successful.\n";
}
$rowcount = $stmt4->rowCount();
echo $rowcount." rows in result set.\n";
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Error executing statement 4.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$conn = null;
unset($conn);
///////////////////////////////////////////////////////////////////////////////
// Part 3
// Part 3
// Expected to fail executing second query because default cursor for first
// query is still active when connection is broken
///////////////////////////////////////////////////////////////////////////////
try
{
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e )
{
try {
$conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true);
} catch (PDOException $e) {
echo "Could not connect.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$query1 = "SELECT * FROM $tableName1";
try
{
$stmt5 = $conn->query( $query1 );
if ( $stmt5 ) echo "Statement 5 successful.\n";
try {
$stmt5 = $conn->query($query1);
if ($stmt5) {
echo "Statement 5 successful.\n";
}
$rowcount = $stmt5->rowCount();
echo $rowcount." rows in result set.\n";
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Error executing statement 5.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
BreakConnection( $conn, $conn_break );
breakConnection($conn, $conn_break);
$query2 = "SELECT * FROM $tableName2";
try
{
$stmt6 = $conn->query( $query2 );
if ( $stmt6 ) echo "Statement 6 successful.\n";
try {
$stmt6 = $conn->query($query2);
if ($stmt6) {
echo "Statement 6 successful.\n";
}
$rowcount = $stmt6->rowCount();
echo $rowcount." rows in result set.\n";
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Error executing statement 6.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$conn = null;
unset($conn);
///////////////////////////////////////////////////////////////////////////////
// Part 4
// Part 4
// Expected to trigger an error because there are two active statements with
// pending results and MARS is off
///////////////////////////////////////////////////////////////////////////////
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10; MultipleActiveResultSets = false;";
try
{
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e )
{
try {
$conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true);
} catch (PDOException $e) {
echo "Could not connect.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
BreakConnection( $conn, $conn_break );
breakConnection($conn, $conn_break);
try
{
$stmt7 = $conn->query( "SELECT * FROM $tableName1" );
if ( $stmt7 ) echo "Statement 7 successful.\n";
}
catch( PDOException $e )
{
try {
$stmt7 = $conn->query("SELECT * FROM $tableName1");
if ($stmt7) {
echo "Statement 7 successful.\n";
}
} catch (PDOException $e) {
echo "Error executing statement 7.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
try
{
$stmt8 = $conn->query( "SELECT * FROM $tableName2" );
if ( $stmt8 ) echo "Statement 8 successful.\n";
}
catch( PDOException $e )
{
try {
$stmt8 = $conn->query("SELECT * FROM $tableName2");
if ($stmt8) {
echo "Statement 8 successful.\n";
}
} catch (PDOException $e) {
echo "Error executing statement 8.\n";
print_r( $e->getMessage() );
print_r($e->getMessage());
}
$conn = null;
$conn_break = null;
unset($conn);
unset($conn_break);
?>
--EXPECTREGEX--

View file

@ -0,0 +1,64 @@
--TEST--
Insert into decimal columns with inputs of various scale and precision
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect();
$tableName = "decimal_table";
createTable($conn, $tableName, array("c1_decimal0" => "decimal", "c2_decimal4" => "decimal(19,4)"));
insertRow($conn, $tableName, array("c1_decimal0" => 0.9, "c2_decimal4" => 0.9));
insertRow($conn, $tableName, array("c1_decimal0" => 9.9, "c2_decimal4" => 9.9));
insertRow($conn, $tableName, array("c1_decimal0" => 999.999, "c2_decimal4" => 999.999));
insertRow($conn, $tableName, array("c1_decimal0" => 99999.99999, "c2_decimal4" => 99999.99999));
$query = "SELECT * FROM $tableName";
$stmt = $conn->query($query);
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($row);
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
?>
--EXPECT--
array(4) {
[0]=>
array(2) {
["c1_decimal0"]=>
string(1) "1"
["c2_decimal4"]=>
string(5) ".9000"
}
[1]=>
array(2) {
["c1_decimal0"]=>
string(2) "10"
["c2_decimal4"]=>
string(6) "9.9000"
}
[2]=>
array(2) {
["c1_decimal0"]=>
string(4) "1000"
["c2_decimal4"]=>
string(8) "999.9990"
}
[3]=>
array(2) {
["c1_decimal0"]=>
string(6) "100000"
["c2_decimal4"]=>
string(11) "100000.0000"
}
}

View file

@ -1,100 +1,179 @@
--TEST--
Error messages from null result sets
--DESCRIPTION--
Test that calling nextRowset() on an empty result set produces the correct error message. Fix for Github 507.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon.inc");
$conn = new PDO( "sqlsrv:Server = $server; Database = $databaseName; ", $uid, $pwd );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
DropTable($conn, 'TestEmptySetTable');
$stmt = $conn->query("CREATE TABLE TestEmptySetTable ([c1] nvarchar(10),[c2] nvarchar(10))");
$stmt = $conn->query("INSERT INTO TestEmptySetTable (c1, c2) VALUES ('a', 'b')");
// Create a procedure that can return a result set or can return nothing
DropProc($conn, 'TestEmptySetProc');
$stmt = $conn->query("CREATE PROCEDURE TestEmptySetProc @a nvarchar(10), @b nvarchar(10)
AS SET NOCOUNT ON
BEGIN
IF @b='b'
BEGIN
SELECT 'a' as testValue
END
ELSE
BEGIN
UPDATE TestEmptySetTable SET c2 = 'c' WHERE c1 = @a
END
END");
// errors out when reaching the second nextRowset() call
// returned error indicates there are no more results
echo "Return a nonempty result set:\n";
try
{
$stmt = $conn->query("TestEmptySetProc @a='a', @b='b'");
$result = $stmt->fetchAll();
print_r($result);
$stmt->nextRowset();
$result = $stmt->fetchAll();
print_r($result);
$stmt->nextRowset();
}
catch(Exception $e)
{
echo $e->getMessage()."\n";
}
// errors out indicating the result set contains no fields
echo "Return an empty result set, call nextRowset on it before fetching anything:\n";
try
{
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'");
$stmt->nextRowset();
}
catch(Exception $e)
{
echo $e->getMessage()."\n";
}
// errors out indicating the result set contains no fields
echo "Return an empty result set, call fetch on it:\n";
try
{
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'");
$result = $stmt->fetchAll();
print_r($result);
}
catch(Exception $e)
{
echo $e->getMessage()."\n";
}
$stmt = $conn->query("DROP TABLE TestEmptySetTable");
$stmt = $conn->query("DROP PROCEDURE TestEmptySetProc");
$conn = null;
?>
--EXPECT--
Return a nonempty result set:
Array
(
[0] => Array
(
[testValue] => a
[0] => a
)
)
Array
(
)
SQLSTATE[IMSSP]: There are no more results returned by the query.
Return an empty result set, call nextRowset on it before fetching anything:
SQLSTATE[IMSSP]: The active result for the query contains no fields.
Return an empty result set, call fetch on it:
SQLSTATE[IMSSP]: The active result for the query contains no fields.
--TEST--
Error messages from nonempty, empty, and null result sets
--DESCRIPTION--
Test that calling nextRowset() and fetching on nonempty, empty, and null result sets produces the correct results or error messages.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon.inc");
// These are the error messages we expect at various points below
$errorNoMoreResults = "There are no more results returned by the query.";
$errorNoFields = "The active result for the query contains no fields.";
// This function compares the expected error message and the error returned by errorInfo().
function CheckError($stmt, $expectedError=NULL)
{
$actualError = $stmt->errorInfo();
if ($actualError[2] != $expectedError) {
echo "Wrong error message:\n";
print_r($actualError);
}
}
function Fetch($stmt, $error=NULL)
{
echo "Fetch...\n";
$result = $stmt->fetchObject();
print_r($result);
CheckError($stmt, $error);
}
function NextResult($stmt, $error=NULL)
{
echo "Next result...\n";
$stmt->nextRowset();
CheckError($stmt, $error);
}
$conn = new PDO( "sqlsrv:Server = $server; Database = $databaseName; ", $uid, $pwd );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
DropTable($conn, 'TestEmptySetTable');
$stmt = $conn->query("CREATE TABLE TestEmptySetTable ([c1] nvarchar(10),[c2] nvarchar(10))");
$stmt = $conn->query("INSERT INTO TestEmptySetTable (c1, c2) VALUES ('a', 'b')");
// Create a procedure that can return a nonempty result set, an empty result set, or a null result
DropProc($conn, 'TestEmptySetProc');
$stmt = $conn->query("CREATE PROCEDURE TestEmptySetProc @a nvarchar(10), @b nvarchar(10)
AS SET NOCOUNT ON
BEGIN
IF @b='b'
BEGIN
SELECT 'a' as testValue
END
ELSE IF @b='w'
BEGIN
SELECT * FROM TestEmptySetTable WHERE c1 = @b
END
ELSE
BEGIN
UPDATE TestEmptySetTable SET c2 = 'c' WHERE c1 = @a
END
END");
// Call fetch on a nonempty result set
echo "Nonempty result set, call fetch first: ###############################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='b'");
Fetch($stmt);
NextResult($stmt);
Fetch($stmt);
NextResult($stmt, $errorNoMoreResults);
// Call nextRowset on a nonempty result set
echo "Nonempty result set, call nextRowset first: #########################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='b'");
NextResult($stmt);
Fetch($stmt);
NextResult($stmt, $errorNoMoreResults);
// Call nextRowset twice in succession on a nonempty result set
echo "Nonempty result set, call nextRowset twice: #########################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='b'");
NextResult($stmt);
NextResult($stmt, $errorNoMoreResults);
// Call fetch on an empty result set
echo "Empty result set, call fetch first: ##################################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='w'");
Fetch($stmt);
NextResult($stmt);
Fetch($stmt);
NextResult($stmt, $errorNoMoreResults);
// Call nextRowset on an empty result set
echo "Empty result set, call nextRowset first: ############################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='w'");
NextResult($stmt);
Fetch($stmt);
NextResult($stmt, $errorNoMoreResults);
// Call nextRowset twice in succession on an empty result set
echo "Empty result set, call nextRowset twice: ############################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='w'");
NextResult($stmt);
NextResult($stmt, $errorNoMoreResults);
// Call fetch on a null result set
echo "Null result set, call fetch first: ###################################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'");
Fetch($stmt, $errorNoFields);
NextResult($stmt);
// Call nextRowset on a null result set
echo "Null result set, call next result first: #############################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'");
NextResult($stmt);
Fetch($stmt);
// Call nextRowset twice in succession on a null result set
echo "Null result set, call next result twice: #############################\n";
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'");
NextResult($stmt);
NextResult($stmt, $errorNoMoreResults);
$stmt = $conn->query("DROP TABLE TestEmptySetTable");
$stmt = $conn->query("DROP PROCEDURE TestEmptySetProc");
$stmt = null;
$conn = null;
?>
--EXPECT--
Nonempty result set, call fetch first: ###############################
Fetch...
stdClass Object
(
[testValue] => a
)
Next result...
Fetch...
Next result...
Nonempty result set, call nextRowset first: #########################
Next result...
Fetch...
Next result...
Nonempty result set, call nextRowset twice: #########################
Next result...
Next result...
Empty result set, call fetch first: ##################################
Fetch...
Next result...
Fetch...
Next result...
Empty result set, call nextRowset first: ############################
Next result...
Fetch...
Next result...
Empty result set, call nextRowset twice: ############################
Next result...
Next result...
Null result set, call fetch first: ###################################
Fetch...
Next result...
Null result set, call next result first: #############################
Next result...
Fetch...
Null result set, call next result twice: #############################
Next result...
Next result...

View file

@ -1,28 +1,27 @@
--TEST--
Test the PDO::errorCode() and PDO::errorInfo() methods.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try
{
$db = connect();
// query with a wrong column name.
$db->query( "Select * from " . $table1 . " where IntColX = 1" );
}
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
catch( PDOException $e ) {
try {
$db = connect();
$tbname = "PDO_MainTypes";
createTableMainTypes($db, $tbname);
// query with a wrong column name.
$db->query("SELECT * FROM $tbname WHERE IntColX = 1");
dropTable($db, $tbname);
unset($conn);
} catch (PDOException $e) {
print($db->errorCode());
echo "\n";
print_r($db->errorInfo());
exit;
}
?>
?>
--EXPECTREGEX--
42S22
Array

View file

@ -1,50 +1,59 @@
--TEST--
Test the different type of data for retrieving
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
try
{
try {
$db = connect();
$query = "INSERT INTO PDO_AllTypes (";
$query .= "BigIntCol,BitCol,IntCol,";
$query .= "SmallIntCol,TinyIntCol,";
$query .= "DecimalCol,NumCol,MoneyCol,";
$query .= "SmallMoneyCol,FloatCol,RealCol,";
$query .= "CharCol,VarcharCol,TextCol,";
$query .= "NCharCol,NVarcharCol,ImageCol,";
$query .= "BinaryCol,VarbinaryCol,SmallDTCol,";
$query .= "DateTimeCol,DTOffsetCol,";
$query .= "TimeCol,Guidcol,VarbinaryMaxCol,";
$query .= "VarcharMaxCol,XmlCol,NTextCol,";
$query .= "NVarCharMaxCol) VALUES (1,'0',1,1,1,111,1,";
$query .= "111.1110,111.1110,111.111,111.111,";
$query .= "'STRINGCOL1','STRINGCOL1',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'STRINGCOL1','STRINGCOL1','00',";
$query .= "CONVERT(BINARY(2),'0000000000',2),CONVERT(VARBINARY(2),CAST('00' AS VARCHAR(2)),2),'2000-11-11 11:11:00',";
$query .= "'2000-11-11 11:11:11.110',";
$query .= "'2000-11-11 11:11:11.1110000 +00:00','11:11:11.1110000',";
$query .= "'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',CONVERT(VARBINARY(MAX),CAST('00' AS VARCHAR(MAX)),2) ,";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.')";
$numRows = $db->exec($query);
echo "Insert complete!";
}
catch(PDOException $e)
{
$tbname = "PDO_AllTypes";
createTableAllTypes($db, $tbname);
$bin = fopen('php://memory', 'a');
fwrite($bin, '00');
rewind($bin);
$inputs = array("BigIntCol" => 0,
"BitCol" => '0',
"IntCol" => 1,
"SmallIntCol" => 1,
"TinyIntCol" => 1,
"DecimalCol" => 111,
"NumCol" => 1,
"MoneyCol" => 111.1110,
"SmallMoneyCol" => 111.1110,
"FloatCol" => 111.111,
"RealCol" => 111.111,
"CharCol" => 'STRINGCOL1',
"VarcharCol" => 'STRINGCOL1',
"TextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',
"NCharCol" => 'STRINGCOL1',
"NVarcharCol" => 'STRINGCOL1',
"ImageCol" => new BindParamOp(17, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"BinaryCol" => new BindParamOp(18, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"VarbinaryCol" => new BindParamOp(19, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"SmallDTCol" => '2000-11-11 11:11:00',
"DateTimeCol" => '2000-11-11 11:11:11.110',
"DTOffsetCol" => '2000-11-11 11:11:11.1110000 +00:00',
"TimeCol" => '11:11:11.1110000',
"Guidcol" => 'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',
"VarbinaryMaxCol" => new BindParamOp(25, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"VarcharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',
"XmlCol" => '<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>',
"NTextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',
"NVarCharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.');
$stmt = insertRow($db, $tbname, $inputs, "prepareBindParam");
dropTable($db, $tbname);
unset($stmt);
unset($conn);
echo "Insert complete!\n";
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
Insert complete!
Insert complete!

View file

@ -3,94 +3,84 @@ Test the PDO::prepare() method.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
require 'MsSetup.inc';
require_once 'MsCommon.inc';
try
{
try {
$db = connect();
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
// Test_1 : Test with no parameters
echo "Test_1 : Test with no parameters :\n";
$stmt = $db->prepare('select * from ' . $table1);
if(!$stmt->execute())
{
$stmt = $db->prepare("select * from $tbname");
if (!$stmt->execute()) {
die("Test_1 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
var_dump($result);
// Test_2 : Test with indexed parameters
echo "Test_2 : Test with indexed parameters :\n";
$stmt = $db->prepare('select IntCol, CharCol from ' . $table1 . ' where IntCol = ? and CharCol = ?');
if(!$stmt->execute(array(1, 'STRINGCOL1')))
{
$stmt = $db->prepare("select IntCol, CharCol from $tbname where IntCol = ? and CharCol = ?");
if (!$stmt->execute(array(1, 'STRINGCOL1'))) {
die("Test_2 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
var_dump($result);
// Test_3 : Test with named parameters
echo "Test_3 : Test with named parameters :\n";
$IntColVal = 2;
$CharColVal = 'STRINGCOL2';
$stmt = $db->prepare('select IntCol, CharCol from ' . $table1 . ' where IntCol = :IntColVal and CharCol = :CharColVal');
if(!$stmt->execute(array(':IntColVal' => $IntColVal, ':CharColVal' => $CharColVal)))
{
$stmt = $db->prepare("select IntCol, CharCol from $tbname where IntCol = :IntColVal and CharCol = :CharColVal");
if (!$stmt->execute(array(':IntColVal' => $IntColVal, ':CharColVal' => $CharColVal))) {
die("Test_3 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
var_dump($result);
// Test_4: Test single prepare, multiple execution with indexed parameters
echo "Test_4 : Test single prepare, multiple execution with indexed parameters :\n";
$IntColVal = 1;
$stmt = $db->prepare('select IntCol from ' . $table1 . ' where IntCol = ?');
$stmt = $db->prepare("select IntCol from $tbname where IntCol = ?");
$stmt->bindParam(1, $IntColVal);
if(!$stmt->execute())
{
if (!$stmt->execute()) {
die("Test_4 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
var_dump($result);
// Execute the stmt again
$IntColVal = 2;
if(!$stmt->execute())
{
if (!$stmt->execute()) {
die("Test_4 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
var_dump($result);
// Test_5: Test single prepare, multiple execution with named parameters
echo "Test_5 : Test single prepare, multiple execution with named parameters :\n";
$IntColVal = 1;
$stmt = $db->prepare('select IntCol from ' . $table1 . ' where IntCol = :IntColVal');
$stmt = $db->prepare("select IntCol from $tbname where IntCol = :IntColVal");
$stmt->bindParam(':IntColVal', $IntColVal);
if(!$stmt->execute())
{
if (!$stmt->execute()) {
die("Test_5 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
var_dump($result);
// Execute the stmt again
$IntColVal = 2;
if(!$stmt->execute())
{
if (!$stmt->execute()) {
die("Test_5 failed.");
}
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
catch(PDOException $err)
{
var_dump($result);
} catch (PDOException $err) {
var_dump($err);
exit();
}

View file

@ -1,81 +1,82 @@
--TEST--
prepare with emulate prepare and binding integer
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require('MsSetup.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", $uid, $pwd);
require_once('MsCommon_mid-refactor.inc');
$tableName = "number_types";
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
$query = "IF OBJECT_ID('number_types') IS NOT NULL DROP TABLE [$tableName]";
$stmt = $conn->query($query);
$tableName = "number_types";
if (!isColEncrypted()) {
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float"));
} else {
// money is not supported for column encryption, use decimal(19,4) instead
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "decimal(19,4)", "c3_float" => "float"));
}
$query = "CREATE TABLE [$tableName] (c1_decimal decimal, c2_money money, c3_float float)";
$stmt = $conn->query($query);
insertRow($conn, $tableName, array("c1_decimal" => 411.1, "c2_money" => 131.11, "c3_float" => 611.111));
insertRow($conn, $tableName, array("c1_decimal" => 422.2222, "c2_money" => 132.22, "c3_float" => 622.22));
insertRow($conn, $tableName, array("c1_decimal" => 433.333, "c2_money" => 133.3333, "c3_float" => 633.33333));
$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (411.1, 131.11, 611.111)";
$stmt = $conn->query($query);
$query = "SELECT * FROM [$tableName] WHERE c3_float = :c3";
$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (422.2222, 132.222, 622.22)";
$stmt = $conn->query($query);
// prepare without emulate prepare
print_r("Prepare without emulate prepare:\n");
$options = array(PDO::ATTR_EMULATE_PREPARES => false);
$stmt = $conn->prepare($query, $options);
$c3 = 611.111;
$stmt->bindParam(':c3', $c3);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (433.333, 133.3333, 633.33333 )";
$stmt = $conn->query($query);
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
if (!isColEncrypted()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c3', $c3);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
$query = "SELECT * FROM [$tableName] WHERE c3_float = :c3";
//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
// prepare without emulate prepare
print_r("Prepare without emulate prepare:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false));
$c3 = 611.111;
$stmt->bindParam(':c3', $c3);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c3 = 611.111;
$stmt->bindParam(':c3', $c3);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c3 = 611.111;
$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c3 = 611.111;
$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c3 = 611.111;
$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
if ($stmt->rowCount() == 0){
print_r("No results for this query\n");
//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n");
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if ($stmt->rowCount() == 0) {
print_r("No results for this query\n");
}
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
$stmt = null;
$conn=null;
?>
--EXPECT--
@ -108,4 +109,4 @@ Array
[c3_float] => 611.11099999999999
)
Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:
No results for this query
No results for this query

View file

@ -1,80 +1,81 @@
--TEST--
prepare with emulate prepare and binding integer
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require('MsSetup.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", $uid, $pwd);
require_once('MsCommon_mid-refactor.inc');
try {
$conn = connect();
$tableName = "fruit";
$tableName = "fruit";
createTable($conn, $tableName, array("name" => "varchar(max)", "calories" => "int"));
$query = "IF OBJECT_ID('fruit') IS NOT NULL DROP TABLE [$tableName]";
$stmt = $conn->query($query);
insertRow($conn, $tableName, array("name" => "apple", "calories" => 150));
insertRow($conn, $tableName, array("name" => "banana", "calories" => 175));
insertRow($conn, $tableName, array("name" => "blueberry", "calories" => 1));
$query = "CREATE TABLE [$tableName] (name varchar(max), calories int)";
$stmt = $conn->query($query);
$query = "SELECT * FROM [$tableName] WHERE calories = :cal";
$query = "INSERT INTO [$tableName] (name, calories) VALUES ('apple', 150)";
$stmt = $conn->query($query);
// prepare without emulate prepare
print_r("Prepare without emulate prepare:\n");
$options = array(PDO::ATTR_EMULATE_PREPARES => false);
$stmt = $conn->prepare($query, $options);
$cal = 1;
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
$query = "INSERT INTO [$tableName] (name, calories) VALUES ('banana', 175)";
$stmt = $conn->query($query);
// prepare with emulate prepare
print_r("Prepare with emulate prepare and no bindParam options:\n");
if (!isColEncrypted()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
$query = "INSERT INTO [$tableName] (name, calories) VALUES ('blueberry', 1)";
$stmt = $conn->query($query);
if (!isColEncrypted()) {
// without emulate prepare, binding PARAM_INT with SQLSRV_ENCODING_SYSTEM is not allowed
// thus the following will not be tested when Column Encryption is enabled
$query = "SELECT * FROM [$tableName] WHERE calories = :cal";
$results = array();
//prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$results["SYSTEM"] = $stmt->fetch(PDO::FETCH_ASSOC);
// prepare without emulate prepare
print_r("Prepare without emulate prepare:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false));
$cal = 1;
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$results["UTF8"] = $stmt->fetch(PDO::FETCH_ASSOC);
// prepare with emulate prepare
print_r("Prepare with emulate prepare and no bindParam options:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$cal = 1;
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$results["BINARY"] = $stmt->fetch(PDO::FETCH_ASSOC);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$cal = 1;
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
foreach ($results as $key => $value) {
if ($value['name'] != "blueberry" || $value['calories'] != 1) {
echo "Failed to fetch when binding parameter with $key encoding.\n";
}
}
}
//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$cal = 1;
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$cal = 1;
$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
$stmt = null;
$conn=null;
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
?>
--EXPECT--
Prepare without emulate prepare:
Array
@ -88,21 +89,3 @@ Array
[name] => blueberry
[calories] => 1
)
Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:
Array
(
[name] => blueberry
[calories] => 1
)
Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:
Array
(
[name] => blueberry
[calories] => 1
)
Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:
Array
(
[name] => blueberry
[calories] => 1
)

View file

@ -1,81 +1,83 @@
--TEST--
prepare with emulate prepare and binding integer
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require('MsSetup.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", $uid, $pwd);
require_once('MsCommon_mid-refactor.inc');
$tableName = "number_types";
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
$query = "IF OBJECT_ID('number_types') IS NOT NULL DROP TABLE [$tableName]";
$stmt = $conn->query($query);
$tableName = "number_types";
if (!isColEncrypted()) {
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float"));
} else {
// money is not supported for column encryption, use decimal(19,4) instead
createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "decimal(19,4)", "c3_float" => "float"));
}
$query = "CREATE TABLE [$tableName] (c1_decimal decimal, c2_money money, c3_float float)";
$stmt = $conn->query($query);
insertRow($conn, $tableName, array("c1_decimal" => 411.1, "c2_money" => 131.11, "c3_float" => 611.111));
insertRow($conn, $tableName, array("c1_decimal" => 422.2222, "c2_money" => 132.22, "c3_float" => 622.22));
insertRow($conn, $tableName, array("c1_decimal" => 433.333, "c2_money" => 133.3333, "c3_float" => 633.33333));
$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (411.1, 131.11, 611.111)";
$stmt = $conn->query($query);
$query = "SELECT * FROM [$tableName] WHERE c2_money = :c2";
$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (422.2222, 132.222, 622.22)";
$stmt = $conn->query($query);
// prepare without emulate prepare
print_r("Prepare without emulate prepare:\n");
$options = array(PDO::ATTR_EMULATE_PREPARES => false);
$stmt = $conn->prepare($query, $options);
$c2 = 133.3333;
$stmt->bindParam(':c2', $c2);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (433.333, 133.3333, 633.33333 )";
$stmt = $conn->query($query);
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
if (!isColEncrypted()) {
// emulate prepare is not supported for encrypted columns
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
}
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c2', $c2);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
$query = "SELECT * FROM [$tableName] WHERE c2_money = :c2";
//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
// prepare without emulate prepare
print_r("Prepare without emulate prepare:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false));
$c2 = 133.3333;
$stmt->bindParam(':c2', $c2);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bind param options:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c2 = 133.3333;
$stmt->bindParam(':c2', $c2);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n");
$stmt = $conn->prepare($query, $options);
$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if ($stmt->rowCount() == 0) {
print_r("No results for this query\n");
}
//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c2 = 133.3333;
$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c2 = 133.3333;
$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$c2 = 133.3333;
$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
if ($stmt->rowCount() == 0){
print_r("No results for this query\n");
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
$stmt = null;
$conn=null;
?>
--EXPECT--
@ -108,4 +110,4 @@ Array
[c3_float] => 633.33333000000005
)
Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:
No results for this query
No results for this query

View file

@ -1,89 +1,95 @@
--TEST--
prepare with emulate prepare and binding uft8 characters
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require('MsSetup.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", $uid, $pwd);
//$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
//$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 );
require_once('MsCommon_mid-refactor.inc');
$tableName = "users";
$query = "IF OBJECT_ID('users') IS NOT NULL DROP TABLE [$tableName]";
$stmt = $conn->query($query);
$query = "CREATE TABLE [$tableName] (name nvarchar(max), status int, age int)";
$stmt = $conn->query($query);
$query = "INSERT INTO [$tableName] (name, status, age) VALUES (N'Belle', 1, 34)";
$stmt = $conn->query($query);
$query = "INSERT INTO [$tableName] (name, status, age) VALUES (N'Абрам', 1, 40)";
$stmt = $conn->query($query);
$query = "INSERT INTO [$tableName] (name, status, age) VALUES (N'가각', 1, 30)";
$stmt = $conn->query($query);
$name = "가각";
$query = "SELECT * FROM [$tableName] WHERE name = :name AND status = 1";
//without emulate prepare
print_r("Prepare without emulate prepare:\n");
$stmt = $conn->prepare($query);
$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bindParam options:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam(':name', $name );
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
if ($stmt->rowCount() == 0){
print_r("No results for this query\n");
function prepareStmt($conn, $query, $prepareOptions = array(), $dataType = null, $length = null, $driverOptions = null)
{
$name = "가각";
if (!isColEncrypted()) {
$stmt = $conn->prepare($query, $prepareOptions);
$stmt->bindParam(':name', $name, $dataType, $length, $driverOptions);
} else {
$status = 1;
$stmt = $conn->prepare($query, $prepareOptions);
$stmt->bindParam(':name', $name, $dataType, $length, $driverOptions);
$stmt->bindParam(':status', $status);
}
$stmt->execute();
return $stmt;
}
//with emulate prepare and SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
//with emulate prepare and SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
if ($stmt->rowCount() == 0){
print_r("No results for this query\n");
$tableName = "users";
createTable($conn, $tableName, array("name" => "nvarchar(max)", "status" => "int", "age" => "int"));
if (!isColEncrypted()) {
$conn->exec("INSERT INTO [$tableName] (name, status, age) VALUES (N'Belle', 1, 34)");
$conn->exec("INSERT INTO [$tableName] (name, status, age) VALUES (N'Абрам', 1, 40)");
$conn->exec("INSERT INTO [$tableName] (name, status, age) VALUES (N'가각', 1, 30)");
$query = "SELECT * FROM [$tableName] WHERE name = :name AND status = 1";
} else {
insertRow($conn, $tableName, array("name" => "Belle", "status" => 1, "age" => 34));
insertRow($conn, $tableName, array("name" => "Абрам", "status" => 1, "age" => 40));
insertRow($conn, $tableName, array("name" => "가각", "status" => 1, "age" => 30));
$query = "SELECT * FROM [$tableName] WHERE name = :name AND status = :status";
}
//without emulate prepare
print_r("Prepare without emulate prepare:\n");
$stmt = prepareStmt($conn, $query, array(), PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
//with emulate prepare and no bind param options
print_r("Prepare with emulate prepare and no bindParam options:\n");
if (!isColEncrypted()) {
$options = array(PDO::ATTR_EMULATE_PREPARES => true);
} else {
$options = array(PDO::ATTR_EMULATE_PREPARES => false);
}
$stmt = prepareStmt($conn, $query, $options);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if ($stmt->rowCount() == 0) {
print_r("No results for this query\n");
}
//with emulate prepare and SQLSRV_ENCODING_UTF8
print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n");
$stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
//with emulate prepare and SQLSRV_ENCODING_SYSTEM
print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if ($stmt->rowCount() == 0) {
print_r("No results for this query\n");
}
//with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n");
$stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if ($stmt->rowCount() == 0) {
print_r("No results for this query\n");
}
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
//with emulate prepare and encoding SQLSRV_ENCODING_BINARY
print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n");
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$row = $stmt->fetch( PDO::FETCH_ASSOC );
print_r($row);
if ($stmt->rowCount() == 0){
print_r("No results for this query\n");
}
//$query = "DROP TABLE [$tableName]";
//$stmt = $conn->query($query);
$stmt = null;
$conn=null;
?>
--EXPECT--
@ -106,4 +112,4 @@ Array
Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:
No results for this query
Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:
No results for this query
No results for this query

View file

@ -1,33 +1,28 @@
--TEST--
Test PDO::prepare by passing in invalid cursor value
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
try
{
$conn = new PDO( "sqlsrv:Server = $server; database = $databaseName", $uid, $pwd);
// PDO::CURSOR_FWDONLY should not be quoted
$stmt1 = $conn->prepare( "SELECT 1", array( PDO::ATTR_CURSOR => "PDO::CURSOR_FWDONLY" ));
print_r(($conn->errorInfo())[2]);
echo "\n";
// 10 is an invalid value for PDO::ATTR_CURSOR
$stmt2 = $conn->prepare( "SELECT 2", array( PDO::ATTR_CURSOR => 10 ));
$stmt1 = $conn->prepare("SELECT 1", array( PDO::ATTR_CURSOR => "PDO::CURSOR_FWDONLY" ));
print_r(($conn->errorInfo())[2]);
echo "\n";
// 10 is an invalid value for PDO::ATTR_CURSOR
$stmt2 = $conn->prepare("SELECT 2", array( PDO::ATTR_CURSOR => 10 ));
print_r(($conn->errorInfo())[2]);
echo "\n";
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
catch( PDOException $e ) {
var_dump( $e->errorInfo );
}
?>
?>
--EXPECT--
An invalid cursor type was specified for either PDO::ATTR_CURSOR or PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE
An invalid cursor type was specified for either PDO::ATTR_CURSOR or PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE
An invalid cursor type was specified for either PDO::ATTR_CURSOR or PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE

View file

@ -1,32 +1,28 @@
--TEST--
Test PDO::prepare by passing in invalid encoding values
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
try
{
$conn = new PDO( "sqlsrv:Server = $server; database = $databaseName", $uid, $pwd);
// PDO::SQLSRV_ENCODING_SYSTEM should not be quoted
$stmt1 = $conn->prepare( "SELECT 1", array( PDO::SQLSRV_ATTR_ENCODING => "PDO::SQLSRV_ENCODING_SYSTEM" ));
$stmt1 = $conn->prepare("SELECT 1", array( PDO::SQLSRV_ATTR_ENCODING => "PDO::SQLSRV_ENCODING_SYSTEM" ));
print_r(($conn->errorInfo())[2]);
echo "\n";
// 10 is an invalid value for PDO::SQLSRV_ATTR_ENCODING
$stmt2 = $conn->prepare( "SELECT 2", array( PDO::SQLSRV_ATTR_ENCODING => 10 ));
$stmt2 = $conn->prepare("SELECT 2", array( PDO::SQLSRV_ATTR_ENCODING => 10 ));
print_r(($conn->errorInfo())[2]);
echo "\n";
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
catch( PDOException $e ) {
var_dump( $e->errorInfo );
}
?>
?>
--EXPECT--
An invalid encoding was specified for SQLSRV_ATTR_ENCODING.
An invalid encoding was specified for SQLSRV_ATTR_ENCODING.
An invalid encoding was specified for SQLSRV_ATTR_ENCODING.

View file

@ -1,28 +1,23 @@
--TEST--
Test PDO::prepare by passing in a string key
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try
{
$dsn = "sqlsrv:Server = $server; database = $databaseName";
$attr = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$conn = new PDO( $dsn, $uid, $pwd, $attr);
$stmt = $conn->prepare( "SELECT 1", array( "PDO::ATTR_CURSOR" => PDO::CURSOR_FWDONLY ));
try {
$conn = connect();
$stmt = $conn->prepare("SELECT 1", array( "PDO::ATTR_CURSOR" => PDO::CURSOR_FWDONLY ));
echo "Test Successful";
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
catch( PDOException $e ) {
var_dump( $e->errorInfo );
}
?>
?>
--EXPECT--
array(3) {
[0]=>
string(5) "IMSSP"
@ -30,4 +25,4 @@ array(3) {
int(-43)
[2]=>
string(42) "An invalid statement option was specified."
}
}

View file

@ -1,33 +1,29 @@
--TEST--
Test PDO::prepare by passing in invalid scrollable type value
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
try
{
$conn = new PDO( "sqlsrv:Server = $server; database = $databaseName", $uid, $pwd);
// PDO::SQLSRV_CURSOR_BUFFERED should not be quoted
$stmt1 = $conn->prepare( "SELECT 1", array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => "PDO::SQLSRV_CURSOR_BUFFERED" ));
// if ATTR_CURSOR is FWDONLY, cannot set SCROLL_TYPE
$stmt2 = $conn->prepare( "SELECT 2", array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED ));
$stmt1 = $conn->prepare("SELECT 1", array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => "PDO::SQLSRV_CURSOR_BUFFERED" ));
if ( $stmt1 || $stmt2 ){
// if ATTR_CURSOR is FWDONLY, cannot set SCROLL_TYPE
$stmt2 = $conn->prepare("SELECT 2", array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED ));
if ($stmt1 || $stmt2) {
echo "Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE should return false.\n";
} else {
echo "Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE return false.\n";
}
}
catch( PDOException $e ) {
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
?>
--EXPECT--
Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE return false.
Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE return false.

View file

@ -1,38 +1,34 @@
--TEST--
Test PDO::prepare by passing in attributes
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
try
{
require_once("MsCommon_mid-refactor.inc");
try {
class CustomPDOStatement extends PDOStatement
{
protected function __construct() {
protected function __construct()
{
}
}
$dsn = "sqlsrv:Server = $server; database = $databaseName";
$conn = connect();
$prep_attr = array(PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_UTF8,
PDO::ATTR_STATEMENT_CLASS => array('CustomPDOStatement', array()),
PDO::SQLSRV_ATTR_DIRECT_QUERY => true,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true
);
$conn = new PDO( $dsn, $uid, $pwd);
$stmt = $conn->prepare( "SELECT 1", $prep_attr );
PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true);
$stmt = $conn->prepare("SELECT 1", $prep_attr);
echo "Test Successful";
}
catch( PDOException $e ) {
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
?>
--EXPECT--
Test Successful
Test Successful

View file

@ -3,83 +3,80 @@ Test the PDO::query() method.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
function query_default( $conn )
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
function queryDefault($conn, $tbname)
{
global $table1;
$stmt = $conn->query( "Select * from " . $table1 );
$stmt = $conn->query("Select * from $tbname");
$result = $stmt->fetch();
var_dump($result);
}
function query_column( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_COLUMN, 2 );
$result = $stmt->fetch();
var_dump($result);
}
function query_class( $conn )
{
global $table1;
global $table1_class;
$stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_CLASS, $table1_class );
$result = $stmt->fetch();
$result->dumpAll();
}
function query_into( $conn )
{
global $table1;
global $table1_class;
$obj = new $table1_class;
$stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_INTO, $obj );
$result = $stmt->fetch();
$result->dumpAll();
}
function query_empty_table( $conn )
{
CreateTableEx($conn, 'emptyTable', "c1 INT, c2 INT");
$stmt = $conn->query( "Select * from emptyTable");
$result = $stmt->fetch();
var_dump($result);
DropTable($conn, 'emptyTable');
}
try
{
function queryColumn($conn, $tbname)
{
$stmt = $conn->query("Select * from $tbname", PDO::FETCH_COLUMN, 2);
$result = $stmt->fetch();
var_dump($result);
}
function queryClass($conn, $tbname)
{
global $mainTypesClass;
$stmt = $conn->query("Select * from $tbname", PDO::FETCH_CLASS, $mainTypesClass);
$result = $stmt->fetch();
$result->dumpAll();
}
function queryInto($conn, $tbname)
{
global $mainTypesClass;
$obj = new $mainTypesClass;
$stmt = $conn->query("Select * from $tbname", PDO::FETCH_INTO, $obj);
$result = $stmt->fetch();
$result->dumpAll();
}
function queryEmptyTable($conn)
{
createTable($conn, 'emptyTable', array("c1" => "int", "c2" => "int"));
$stmt = $conn->query("Select * from emptyTable");
$result = $stmt->fetch();
var_dump($result);
dropTable($conn, 'emptyTable');
}
try {
$db = connect();
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
echo "TEST_1 : query with default fetch style :\n";
query_default($db);
queryDefault($db, $tbname);
echo "TEST_2 : query with FETCH_COLUMN :\n";
query_column($db);
queryColumn($db, $tbname);
echo "TEST_3 : query with FETCH_CLASS :\n";
query_class($db);
queryClass($db, $tbname);
echo "TEST_4 : query with FETCH_INTO :\n";
query_into($db);
echo "TEST_5 : query an empty table :\n";
query_empty_table($db);
}
queryInto($db, $tbname);
catch( PDOException $e ) {
var_dump( $e );
echo "TEST_5 : query an empty table :\n";
queryEmptyTable($db);
dropTable($db, $tbname);
unset($db);
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECT--
TEST_1 : query with default fetch style :
array(16) {
@ -137,4 +134,4 @@ string(10) "STRINGCOL1"
string(7) "111.111"
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
TEST_5 : query an empty table :
bool(false)
bool(false)

View file

@ -1,73 +1,50 @@
--TEST--
test query time out at the connection level and statement level
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
include 'MsCommon.inc';
function QueryTimeout($connLevel)
function queryTimeout($connLevel)
{
require("MsSetup.inc");
$tableName = GetTempTableName();
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
$stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(25))");
$query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (1, 'QueryTimeout 1')";
$stmt = $conn->query($query);
$query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (2, 'QueryTimeout 2')";
$stmt = $conn->query($query);
$conn = connect('', array(), PDO::ERRMODE_SILENT);
$tableName = getTableName();
createTable($conn, $tableName, array("c1_int" => "int", "c2_varchar" => "varchar(25)"));
insertRow($conn, $tableName, array("c1_int" => 1, "c2_varchar" => "QueryTimeout 1"));
insertRow($conn, $tableName, array("c1_int" => 2, "c2_varchar" => "QueryTimeout 2"));
$query = "SELECT * FROM $tableName";
if ($connLevel)
{
if ($connLevel) {
echo "Setting query timeout as an attribute in connection\n";
$conn->setAttribute(constant('PDO::SQLSRV_ATTR_QUERY_TIMEOUT'), 1);
$stmt = $conn->query("WAITFOR DELAY '00:00:03'; $query");
var_dump($conn->errorInfo());
}
else
{
} else {
echo "Setting query timeout in the statement\n";
$stmt = $conn->prepare("WAITFOR DELAY '00:00:03'; $query", array(constant('PDO::SQLSRV_ATTR_QUERY_TIMEOUT') => 1));
$stmt->execute();
var_dump($stmt->errorInfo());
}
$stmt = null;
$conn = null;
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
}
function RunTest()
{
StartTest("pdo_query_timeout");
echo "\nStarting test...\n";
try
{
QueryTimeout(true);
QueryTimeout(false);
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("pdo_query_timeout");
echo "Starting test...\n";
try {
queryTimeout(true);
queryTimeout(false);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "Done\n";
?>
--EXPECTREGEX--
Starting test\.\.\.
Setting query timeout as an attribute in connection
array\(3\) \{
@ -87,6 +64,4 @@ array\(3\) \{
\[2\]=>
string\(63\) \"\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired\"
\}
Done
Test \"pdo_query_timeout\" completed successfully\.

View file

@ -1,30 +1,26 @@
--TEST--
Test the PDO::quote() method.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
try
{
$conn = connect(array(PDO::SQLSRV_ATTR_ENCODING => 3, PDO::ATTR_CASE => 2));
try {
$conn = connect("", array(PDO::SQLSRV_ATTR_ENCODING => 3, PDO::ATTR_CASE => 2));
$unquoted = "ABC'DE";
$quoted1 = $conn->quote($unquoted);
$quoted2 = $conn->quote($quoted1);
$quoted2 = $conn->quote($quoted1);
var_dump($unquoted);
var_dump($quoted1);
var_dump($quoted2);
}
catch( PDOException $e ) {
var_dump( $e );
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECT--
string(6) "ABC'DE"

View file

@ -1,33 +1,27 @@
--TEST--
Test setting invalid value or key in connection attributes
Test setting invalid value or key in connection attributes
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
try{
$dsn = "sqlsrv:Server = $server; database = $databaseName";
$conn = new PDO( $dsn, $uid, $pwd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT));
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
// Negative value for query timeout: should raise error
@$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, -1 );
print_r (($conn->errorInfo())[2]);
@$conn->setAttribute(PDO::SQLSRV_ATTR_QUERY_TIMEOUT, -1);
print_r(($conn->errorInfo())[2]);
echo "\n";
// PDO::ATTR_CURSOR is a Statement Level Attribute only
@$conn->setAttribute( PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL );
print_r (($conn->errorInfo())[2]);
}
catch ( PDOException $e ){
@$conn->setAttribute(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL);
print_r(($conn->errorInfo())[2]);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
?>
--EXPECT--
Invalid value -1 specified for option PDO::SQLSRV_ATTR_QUERY_TIMEOUT.
The given attribute is only supported on the PDOStatement object.
The given attribute is only supported on the PDOStatement object.

View file

@ -1,39 +1,35 @@
--TEST--
Test setting invalid encoding attributes
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
try{
$dsn = "sqlsrv:Server = $server; database = $databaseName";
require_once("MsCommon_mid-refactor.inc");
$conn = new PDO( $dsn, $uid, $pwd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT));
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
// valid option: should have no error
@$conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_DEFAULT );
print_r (($conn->errorInfo())[2]);
@$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_DEFAULT);
print_r(($conn->errorInfo())[2]);
echo "\n";
// PDO::SQLSRV_ENCODING_UTF8 should not be quoted
@$conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, "PDO::SQLSRV_ENCODING_UTF8" );
print_r (($conn->errorInfo())[2]);
@$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, "PDO::SQLSRV_ENCODING_UTF8");
print_r(($conn->errorInfo())[2]);
echo "\n";
// PDO::SQLSRV_ENCODING_BINARY is not supported
@$conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY );
print_r (($conn->errorInfo())[2]);
@$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY);
print_r(($conn->errorInfo())[2]);
echo "\n";
}
catch ( PDOException $e ){
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
?>
--EXPECT--
An invalid encoding was specified for SQLSRV_ATTR_ENCODING.
An invalid encoding was specified for SQLSRV_ATTR_ENCODING.
An invalid encoding was specified for SQLSRV_ATTR_ENCODING.

View file

@ -1,180 +1,161 @@
--TEST--
test rowCount() with different querying method and test nextRowset() with different fetch
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include_once("MsCommon_mid-refactor.inc");
function RowCount_Query($exec)
function rowCountQuery($exec)
{
require("MsSetup.inc");
$tableName = GetTempTableName('testRowCount');
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
$stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_real] real)");
$conn = connect();
$tableName = getTableName('testRowCount');
createTable($conn, $tableName, array("c1_int" => "int", "c2_real" => "real"));
$numRows = 5;
for ($i = 1; $i <= $numRows; $i++)
{
InsertData($conn, $tableName, $i);
for ($i = 1; $i <= $numRows; $i++) {
$r = $i * 1.0;
insertRow($conn, $tableName, array("c1_int" => $i, "c2_real" => $r));
}
FetchRowsets($conn, $tableName, $numRows);
for ($i = 1; $i <= $numRows; $i++)
{
UpdateData($conn, $tableName, $i, $exec);
fetchRowsets($conn, $tableName, $numRows);
for ($i = 1; $i <= $numRows; $i++) {
updateData($conn, $tableName, $i, $exec);
}
DeleteData($conn, $tableName, $exec);
$stmt = null;
$conn = null;
deleteData($conn, $tableName, $exec);
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
}
function InsertData($conn, $tableName, $value)
{
$query = "INSERT INTO $tableName VALUES ($value, $value * 1.0)";
$stmt = $conn->query($query);
}
function UpdateData($conn, $tableName, $value, $exec)
function updateData($conn, $tableName, $value, $exec)
{
$newValue = $value * 100;
$query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)";
$rowCount = 0;
if ($exec)
{
$rowCount = $conn->exec($query);
}
else
{
$stmt = $conn->prepare($query);
$rowCount = $stmt->rowCount();
if ($rowCount > 0)
echo "Number of rows affected prior to execution should be 0!\n";
if (isColEncrypted()) {
// need to bind parameters for updating encrypted columns
$query = "UPDATE $tableName SET c1_int = ? WHERE (c1_int = ?)";
$stmt = $conn->prepare($query);
if ($rowCount > 0) {
echo "Number of rows affected prior to execution should be 0!\n";
}
$stmt->bindParam(1, $newValue);
$stmt->bindParam(2, $value);
$stmt->execute();
$rowCount = $stmt->rowCount();
} else {
$query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)";
if ($exec) {
$rowCount = $conn->exec($query);
} else {
$stmt = $conn->prepare($query);
$rowCount = $stmt->rowCount();
if ($rowCount > 0) {
echo "Number of rows affected prior to execution should be 0!\n";
}
$stmt->execute();
$rowCount = $stmt->rowCount();
}
}
if ($rowCount !== 1)
if ($rowCount !== 1) {
echo "Number of rows affected should be 1!\n";
$stmt = null;
}
unset($stmt);
}
function CompareValues($actual, $expected)
function compareValues($actual, $expected)
{
if ($actual != $expected)
{
if ($actual != $expected) {
echo "Unexpected value $value returned! Expected $expected.\n";
}
}
function FetchRowsets($conn, $tableName, $numRows)
function fetchRowsets($conn, $tableName, $numRows)
{
$query = "SELECT [c1_int] FROM $tableName ORDER BY [c1_int]";
if (!isColEncrypted()) {
$query = "SELECT [c1_int] FROM $tableName ORDER BY [c1_int]";
} else {
// ORDER BY is not supported in encrypted columns
$query = "SELECT [c1_int] FROM $tableName";
}
$queries = $query . ';' . $query . ';' . $query;
$stmt = $conn->query($queries);
$i = 0;
while ($row = $stmt->fetch(PDO::FETCH_LAZY))
{
while ($row = $stmt->fetch(PDO::FETCH_LAZY)) {
$value = (int)$row['c1_int'];
CompareValues($value, ++$i);
compareValues($value, ++$i);
}
if ($i != $numRows)
{
if ($i != $numRows) {
echo "Number of rows fetched $i is unexpected!\n";
}
$result = $stmt->nextRowset();
if ($result == false)
{
echo "Missing result sets!\n";
}
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
$i = 0;
foreach ($rows as $row)
{
foreach ($row as $key => $value)
{
$value = (int)$value;
CompareValues($value, ++$i);
}
}
$result = $stmt->nextRowset();
if ($result == false)
{
if ($result == false) {
echo "Missing result sets!\n";
}
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
$i = 0;
foreach ($rows as $row) {
foreach ($row as $key => $value) {
$value = (int)$value;
compareValues($value, ++$i);
}
}
$result = $stmt->nextRowset();
if ($result == false) {
echo "Missing result sets!\n";
}
$stmt->bindColumn('c1_int', $value);
$i = 0;
while ($row = $stmt->fetch(PDO::FETCH_BOUND))
{
CompareValues($value, ++$i);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
compareValues($value, ++$i);
}
$result = $stmt->nextRowset();
if ($result != false)
{
if ($result != false) {
echo "Number of result sets exceeding expectation!\n";
}
}
function DeleteData($conn, $tableName, $exec)
function deleteData($conn, $tableName, $exec)
{
$query = "DELETE TOP(3) FROM $tableName";
$query = "DELETE TOP(3) FROM $tableName";
$rowCount = 0;
if ($exec)
{
if ($exec) {
$rowCount = $conn->exec($query);
}
else
{
} else {
$stmt = $conn->query($query);
$rowCount = $stmt->rowCount();
}
if ($rowCount <= 0)
if ($rowCount <= 0) {
echo "Number of rows affected should be > 0!\n";
$stmt = null;
}
unset($stmt);
}
function RunTest()
{
StartTest("pdo_statement_rowcount_query");
echo "\nStarting test...\n";
try
{
RowCount_Query(true);
RowCount_Query(false);
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("pdo_statement_rowcount_query");
echo "Starting test...\n";
try {
rowCountQuery(true);
rowCountQuery(false);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "Done\n";
?>
--EXPECT--
Starting test...
Done
Test "pdo_statement_rowcount_query" completed successfully.

View file

@ -1,320 +1,303 @@
--TEST--
call stored procedures with inputs of ten different datatypes to get outputs of various types
call stored procedures with inputs of ten different datatypes to get outputs of various types
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include_once("MsCommon_mid-refactor.inc");
function ProcFetch_BigInt($conn)
function procFetchBigInt($conn)
{
$procName = GetTempProcName('bigint');
$procName = getProcName('bigint');
$stmt = $conn->exec("CREATE PROC $procName (@p1 BIGINT, @p2 BIGINT, @p3 NCHAR(128) OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(NCHAR(128), @p1 + @p2) END");
$inValue1 = '12345678';
$inValue2 = '11111111';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindValue(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "23456789";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_Decimal($conn)
function procFetchDecimal($conn)
{
$procName = GetTempProcName('decimal');
$procName = getProcName('decimal');
$stmt = $conn->exec("CREATE PROC $procName (@p1 DECIMAL, @p2 DECIMAL, @p3 CHAR(128) OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(CHAR(128), @p1 + @p2) END");
$inValue1 = '2.1';
$inValue2 = '5.3';
$outValue = '0';
$inValue1 = '2.1';
$inValue2 = '5.3';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindValue(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "7";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_Float($conn)
function procFetchFloat($conn)
{
$procName = GetTempProcName('float');
$procName = getProcName('float');
$stmt = $conn->exec("CREATE PROC $procName (@p1 FLOAT, @p2 FLOAT, @p3 FLOAT OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(FLOAT, @p1 + @p2) END");
$inValue1 = '2.25';
$inValue2 = '5.5';
$outValue = '0';
$inValue1 = '2.25';
$inValue2 = '5.5';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindValue(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "7.75";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_Int($conn)
function procFetchInt($conn)
{
$procName = GetTempProcName('int');
$procName = getProcName('int');
$stmt = $conn->exec("CREATE PROC $procName (@p1 INT, @p2 INT, @p3 INT OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(INT, @p1 + @p2) END");
$inValue1 = '1234';
$inValue2 = '5678';
$outValue = '0';
$inValue1 = '1234';
$inValue2 = '5678';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindValue(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "6912";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_Money($conn)
function procFetchMoney($conn)
{
$procName = GetTempProcName('money');
$procName = getProcName('money');
$stmt = $conn->exec("CREATE PROC $procName (@p1 MONEY, @p2 MONEY, @p3 MONEY OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(MONEY, @p1 + @p2) END");
$inValue1 = '22.3';
$inValue2 = '16.1';
$outValue = '0';
$inValue1 = '22.3';
$inValue2 = '16.1';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1, PDO::PARAM_STR);
$stmt->bindParam(2, $inValue2, PDO::PARAM_STR);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->bindValue(1, $inValue1, PDO::PARAM_STR);
$stmt->bindParam(2, $inValue2, PDO::PARAM_STR);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "38.40";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_Numeric($conn)
function procFetchNumeric($conn)
{
$procName = GetTempProcName('numeric');
$procName = getProcName('numeric');
$stmt = $conn->exec("CREATE PROC $procName (@p1 NUMERIC, @p2 NUMERIC, @p3 NCHAR(128) OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(NCHAR(128), @p1 + @p2) END");
$inValue1 = '2.8';
$inValue2 = '5.4';
$outValue = '0';
$inValue1 = '2.8';
$inValue2 = '5.4';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "8";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_Real($conn)
function procFetchReal($conn)
{
$procName = GetTempProcName('real');
$procName = getProcName('real');
$stmt = $conn->exec("CREATE PROC $procName (@p1 REAL, @p2 REAL, @p3 REAL OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(REAL, @p1 + @p2) END");
$inValue1 = '3.4';
$inValue2 = '6.6';
$outValue = '0';
$inValue1 = '3.4';
$inValue2 = '6.6';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "10";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_SmallInt($conn)
function procFetchSmallInt($conn)
{
$procName = GetTempProcName('smallint');
$procName = getProcName('smallint');
$stmt = $conn->exec("CREATE PROC $procName (@p1 SMALLINT, @p2 SMALLINT, @p3 NCHAR(32) OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(NCHAR(32), @p1 + @p2) END");
$inValue1 = '34';
$inValue2 = '56';
$outValue = '0';
$inValue1 = '34';
$inValue2 = '56';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "90";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($conn);
}
function ProcFetch_SmallMoney($conn)
function procFetchSmallMoney($conn)
{
$procName = GetTempProcName('smallmoney');
$procName = getProcName('smallmoney');
$stmt = $conn->exec("CREATE PROC $procName (@p1 SMALLMONEY, @p2 SMALLMONEY, @p3 SMALLMONEY OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(SMALLMONEY, @p1 + @p2) END");
$inValue1 = '10';
$inValue2 = '11.7';
$outValue = '0';
$inValue1 = '10';
$inValue2 = '11.7';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1, PDO::PARAM_STR);
$stmt->bindParam(2, $inValue2, PDO::PARAM_STR);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->bindValue(1, $inValue1, PDO::PARAM_STR);
$stmt->bindParam(2, $inValue2, PDO::PARAM_STR);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "21.70";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function ProcFetch_TinyInt($conn)
{
$procName = GetTempProcName('tinyint');
$procName = getProcName('tinyint');
$stmt = $conn->exec("CREATE PROC $procName (@p1 TINYINT, @p2 TINYINT, @p3 CHAR(32) OUTPUT)
AS BEGIN SELECT @p3 = CONVERT(CHAR(32), @p1 + @p2) END");
$inValue1 = '11';
$inValue2 = '12';
$outValue = '0';
$inValue1 = '11';
$inValue2 = '12';
$outValue = '0';
$stmt = $conn->prepare("{CALL $procName (?, ?, ?)}");
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->bindValue(1, $inValue1);
$stmt->bindParam(2, $inValue2);
$stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300);
$stmt->execute();
$expected = "23";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
if (strncasecmp($outValue, $expected, strlen($expected))) {
echo "Output value $outValue is unexpected! Expected $expected\n";
}
$stmt = null;
}
dropProc($conn, $procName);
unset($stmt);
}
function RunTest()
{
set_time_limit(0);
StartTest("pdo_stored_proc_fetch_datatypes");
echo "\nStarting test...\n";
try
{
include("MsSetup.inc");
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
set_time_limit(0);
echo "Starting test...\n";
try {
$conn = connect();
ProcFetch_BigInt($conn);
ProcFetch_Decimal($conn);
ProcFetch_Float($conn);
ProcFetch_Int($conn);
ProcFetch_Money($conn);
ProcFetch_Numeric($conn);
ProcFetch_Real($conn);
ProcFetch_SmallInt($conn);
ProcFetch_SmallMoney($conn);
ProcFetch_TinyInt($conn);
$conn = null;
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("pdo_stored_proc_fetch_datatypes");
procFetchBigInt($conn);
procFetchDecimal($conn);
procFetchFloat($conn);
procFetchInt($conn);
procFetchMoney($conn);
procFetchNumeric($conn);
procFetchReal($conn);
procFetchSmallInt($conn);
procFetchSmallMoney($conn);
ProcFetch_TinyInt($conn);
unset($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "Done\n";
?>
--EXPECT--
Starting test...
Done
Test "pdo_stored_proc_fetch_datatypes" completed successfully.

View file

@ -1,494 +0,0 @@
--TEST--
Test the different type of data for retrieving
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
function testBigInt()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT BigIntCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testBit()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT BitCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testInt()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT IntCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testSmallInt()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT SmallIntCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testTinyInt()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT TinyIntCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testDecimal()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT DecimalCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testNumeric()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT NumCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testMoney()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT MoneyCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testSmallMoney()
{
$db = connect();
// Retrieve data type
$stmt = $db->query("SELECT SmallMoneyCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testFloat()
{
$db = connect();
$stmt = $db->query("SELECT FloatCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testReal()
{
$db = connect();
$stmt = $db->query("SELECT RealCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testChar()
{
$db = connect();
$stmt = $db->query("SELECT CharCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testVarchar()
{
$db = connect();
$stmt = $db->query("SELECT VarcharCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testText()
{
$db = connect();
$stmt = $db->query("SELECT TextCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testNText()
{
$db = connect();
$stmt = $db->query("SELECT NTextCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testNChar()
{
$db = connect();
$stmt = $db->query("SELECT NCharCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testNVarchar()
{
$db = connect();
$stmt = $db->query("SELECT NVarcharCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testImage()
{
$db = connect();
$stmt = $db->query("SELECT ImageCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testBinary()
{
$db = connect();
$stmt = $db->query("SELECT BinaryCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testVarbinary()
{
$db = connect();
$stmt = $db->query("SELECT VarbinaryCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testDateTime2()
{
$db = connect();
$stmt = $db->query("SELECT DateTime2Col FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testDatetimeoffset()
{
$db = connect();
$stmt = $db->query("SELECT DTOffsetCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testsmalldatetime()
{
$db = connect();
$stmt = $db->query("SELECT SmallDTCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testDateTime()
{
$db = connect();
$stmt = $db->query("SELECT DateTimeCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testDate()
{
$db = connect();
$stmt = $db->query("SELECT DateCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testNVarcharMax()
{
$db = connect();
$stmt = $db->query("SELECT NVarCharMaxCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testTime()
{
$db = connect();
$stmt = $db->query("SELECT TimeCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testUniqueidentifier()
{
$db = connect();
$stmt = $db->query("SELECT Guidcol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testVarbinaryMax()
{
$db = connect();
$stmt = $db->query("SELECT VarbinaryMaxCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testVarcharMax()
{
$db = connect();
$stmt = $db->query("SELECT VarcharMaxCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
function testXml()
{
$db = connect();
$stmt = $db->query("SELECT XmlCol FROM PDO_AllTypes");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
}
try
{
//$db = connect();
//$sql = "INSERT INTO PDO_AllTypes(BigIntCol,BitCol,IntCol,) VALUES(" . GetSampleData(4) . ",1,)";
//$numRows = $db->exec($sql);
echo "Test_1 : bigint data type :\n";
testBigInt();
echo "Test_2 : bit data type :\n";
testBit();
echo "Test_3 : int data type :\n";
testInt();
echo "Test_4 : smallint data type:\n";
testSmallInt();
echo "Test_5 : tinyint data type:\n";
testTinyInt();
echo "Test_6 : decimal data type:\n";
testDecimal();
echo "Test_7 : numeric data type:\n";
testNumeric();
echo "Test_8 : money data type:\n";
testMoney();
echo "Test_9 : smallmoney data type:\n";
testSmallMoney();
echo "Test_10 : float data type:\n";
testFloat();
echo "Test_11 : real data type:\n";
testReal();
echo "Test_12 : char data type:\n";
testChar();
echo "Test_13 : varchar data type:\n";
testVarchar();
echo "Test_14 : text data type:\n";
testText();
echo "Test_15 : nchar data type:\n";
testNChar();
echo "Test_16 : nvarchar data type:\n";
testNVarchar();
echo "Test_17 : image data type:\n";
testImage();
echo "Test_18 : binary data type:\n";
testBinary();
echo "Test_19 : varbinary data type:\n";
testVarbinary();
echo "Test_20 : smalldatetime data type:\n";
testsmalldatetime();
echo "Test_21 : datetime data type:\n";
testDateTime();
echo "Test_22 : datetime2 data type:\n";
testsmalldatetime();
echo "Test_23 : datetimeoffset data type:\n";
testDatetimeoffset();
echo "Test_24 : time data type:\n";
testTime();
echo "Test_25 : Uniqueidentifier data type:\n";
testUniqueidentifier();
echo "Test_26 : VarbinaryMax data type:\n";
testVarbinaryMax();
echo "Test_27 : VarcharMax data type:\n";
testVarcharMax();
echo "Test_28 : xml data type:\n";
testXml();
echo "Test_29 : ntext data type:\n";
testNText();
echo "Test_30 : nvarcharmax data type:\n";
testNVarcharMax();
}
catch (PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
Test_1 : bigint data type :
array(1) {
["BigIntCol"]=>
string(1) "1"
}
Test_2 : bit data type :
array(1) {
["BitCol"]=>
string(1) "0"
}
Test_3 : int data type :
array(1) {
["IntCol"]=>
string(1) "1"
}
Test_4 : smallint data type:
array(1) {
["SmallIntCol"]=>
string(1) "1"
}
Test_5 : tinyint data type:
array(1) {
["TinyIntCol"]=>
string(1) "1"
}
Test_6 : decimal data type:
array(1) {
["DecimalCol"]=>
string(3) "111"
}
Test_7 : numeric data type:
array(1) {
["NumCol"]=>
string(1) "1"
}
Test_8 : money data type:
array(1) {
["MoneyCol"]=>
string(8) "111.1110"
}
Test_9 : smallmoney data type:
array(1) {
["SmallMoneyCol"]=>
string(8) "111.1110"
}
Test_10 : float data type:
array(1) {
["FloatCol"]=>
string(7) "111.111"
}
Test_11 : real data type:
array(1) {
["RealCol"]=>
string(7) "111.111"
}
Test_12 : char data type:
array(1) {
["CharCol"]=>
string(10) "STRINGCOL1"
}
Test_13 : varchar data type:
array(1) {
["VarcharCol"]=>
string(10) "STRINGCOL1"
}
Test_14 : text data type:
array(1) {
["TextCol"]=>
string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417."
}
Test_15 : nchar data type:
array(1) {
["NCharCol"]=>
string(10) "STRINGCOL1"
}
Test_16 : nvarchar data type:
array(1) {
["NVarcharCol"]=>
string(10) "STRINGCOL1"
}
Test_17 : image data type:
array(1) {
["ImageCol"]=>
string(1) ""
}
Test_18 : binary data type:
array(1) {
["BinaryCol"]=>
string(5) ""
}
Test_19 : varbinary data type:
array(1) {
["VarbinaryCol"]=>
string(1) ""
}
Test_20 : smalldatetime data type:
array(1) {
["SmallDTCol"]=>
string(19) "2000-11-11 11:11:00"
}
Test_21 : datetime data type:
array(1) {
["DateTimeCol"]=>
string(23) "2000-11-11 11:11:11.110"
}
Test_22 : datetime2 data type:
array(1) {
["SmallDTCol"]=>
string(19) "2000-11-11 11:11:00"
}
Test_23 : datetimeoffset data type:
array(1) {
["DTOffsetCol"]=>
string(34) "2000-11-11 11:11:11.1110000 +00:00"
}
Test_24 : time data type:
array(1) {
["TimeCol"]=>
string(16) "11:11:11.1110000"
}
Test_25 : Uniqueidentifier data type:
array(1) {
["Guidcol"]=>
string(36) "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
}
Test_26 : VarbinaryMax data type:
array(1) {
["VarbinaryMaxCol"]=>
string(1) ""
}
Test_27 : VarcharMax data type:
array(1) {
["VarcharMaxCol"]=>
string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417."
}
Test_28 : xml data type:
array(1) {
["XmlCol"]=>
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
}
Test_29 : ntext data type:
array(1) {
["NTextCol"]=>
string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417."
}
Test_30 : nvarcharmax data type:
array(1) {
["NVarCharMaxCol"]=>
string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417."
}

View file

@ -3,51 +3,73 @@ test transaction rollback and commit
--DESCRIPTION--
starts a transaction, delete rows and rollback the transaction; starts a transaction, delete rows and commit
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");
function deleteRows($conn, $tbname)
{
try {
if (!isColEncrypted()) {
$rows = $conn->exec("DELETE FROM $tbname WHERE col1 = 'a'");
} else {
// needs to find parameter for encrypted columns
$sql = "DELETE FROM $tbname WHERE col1 = ?";
$stmt = $conn->prepare($sql);
$col1 = "a";
$stmt->execute(array($col1));
$rows = $stmt->rowCount();
}
return $rows;
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
}
try {
$conn = connect();
$tbname = "Table1";
createTable($conn, $tbname, array("col1" => "char(1)", "col2" => "char(1)"));
insertRow($conn, $tbname, array("col1" => "a", "col2" => "b"));
insertRow($conn, $tbname, array("col1" => "a", "col2" => "c"));
$conn = new PDO( "sqlsrv:Server=$server; database = $databaseName", $uid, $pwd);
$conn->exec("IF OBJECT_ID('Table1', 'U') IS NOT NULL DROP TABLE Table1");
$conn->exec("CREATE TABLE Table1(col1 CHARACTER(1), col2 CHARACTER(1))");
$ret = $conn->exec("INSERT INTO Table1(col1, col2) VALUES('a', 'b')");
$ret = $conn->exec("INSERT INTO Table1(col1, col2) VALUES('a', 'c')");
//revert the inserts but roll back
$conn->beginTransaction();
$rows = $conn->exec("DELETE FROM Table1 WHERE col1 = 'a'");
$rows = deleteRows($conn, $tbname);
$conn->rollback();
$stmt = $conn->query("SELECT * FROM Table1");
$stmt = $conn->query("SELECT * FROM $tbname");
// Table1 should still have 2 rows since delete was rolled back
if ( count( $stmt->fetchAll() ) == 2 )
if (count($stmt->fetchAll()) == 2) {
echo "Transaction rolled back successfully\n";
else
} else {
echo "Transaction failed to roll back\n";
}
//revert the inserts then commit
$conn->beginTransaction();
$rows = $conn->exec("DELETE FROM Table1 WHERE col1 = 'a'");
$rows = deleteRows($conn, $tbname);
$conn->commit();
echo $rows." rows affected\n";
$stmt = $conn->query("SELECT * FROM Table1");
if ( count( $stmt->fetchAll() ) == 0 )
$stmt = $conn->query("SELECT * FROM $tbname");
if (count($stmt->fetchAll()) == 0) {
echo "Transaction committed successfully\n";
else
} else {
echo "Transaction failed to commit\n";
//drop the created temp table
$conn->exec("DROP TABLE Table1");
//free statement and connection
$stmt = NULL;
$conn = NULL;
}
dropTable($conn, $tbname);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
?>
--EXPECT--
Transaction rolled back successfully
2 rows affected
Transaction committed successfully
Transaction committed successfully

View file

@ -1,112 +1,98 @@
--TEST--
Test Transactions.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
// commit
function test1($conn)
function test1($conn, $tbname)
{
global $table1;
$conn->beginTransaction();
$stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" );
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
$conn->commit();
echo "\nTest 1 Passed]\n";
echo "Test 1 Passed\n";
}
// rollback
function test2($conn)
function test2($conn, $tbname)
{
global $table1;
$conn->beginTransaction();
$stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" );
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
$conn->rollBack();
echo "Test 2 Passed\n";
}
// commit
function test3($conn)
function test3($conn, $tbname)
{
global $table1;
$conn->beginTransaction();
$stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" );
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
$conn->commit();
echo "Test 3 Passed\n";
}
// Rollback twice. Verify that error is thrown
function test4($conn)
function test4($conn, $tbname)
{
try {
global $table1;
$conn->beginTransaction();
$stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" );
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
$conn->rollBack();
$conn->rollBack();
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Test4: ". $e->getMessage() . "\n";
}
}
// Commit twice Verify that error is thrown
function test5($conn)
function test5($conn, $tbname)
{
try {
global $table1;
$conn->beginTransaction();
$stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" );
insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3));
$conn->commit();
$conn->commit();
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Test5: ". $e->getMessage() . "\n";
}
}
// begin transaction twice. Verify that error is thrown
function test6($conn)
{
try {
$conn->beginTransaction();
$conn->beginTransaction();
}
catch( PDOException $e )
{
} catch (PDOException $e) {
echo "Test6: ". $e->getMessage() . "\n";
}
}
try
{
$db = connect();
create_and_insert_table1( $db );
test1($db);
test2($db);
test3($db);
test4($db);
test5($db);
test6($db);
}
try {
$db = connect();
$tbname = "PDO_MainTypes";
createTableMainTypes($db, $tbname);
test1($db, $tbname);
test2($db, $tbname);
test3($db, $tbname);
test4($db, $tbname);
test5($db, $tbname);
test6($db);
catch( PDOException $e ) {
var_dump( $e );
dropTable($db, $tbname);
unset($conn);
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECT--
Test 1 Passed]
Test 1 Passed
Test 2 Passed
Test 3 Passed
Test4: There is no active transaction
Test5: There is no active transaction
Test6: There is already an active transaction
Test6: There is already an active transaction

View file

@ -0,0 +1,82 @@
--TEST--
Checks that calling query() after beginTransaction() with an invalid query does not cause a crash. Fix for Github 434.
--DESCRIPTION--
Calling beginTransaction() and then query() with an invalid query can cause a crash in php.exe or php-cgi.exe,
which may manifest as a CLI crash or produce an error message saying "Faulting Module[...]odbc32.dll". The
cause is an attempt to double free a statement handle after script execution which had not been properly freed
during rollback. This test tells us nothing under run-tests.php because the crash only occurs at the end of
script execution, so any expected output already exists and the test would pass. Therefore manual verification
is necessary - this test should be run separately to verify no crash occurs.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
$conn = new PDO("sqlsrv:Server=$server; database = $databaseName", $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
for ($i = 0; $i < 50; $i++) {
echo "Iteration $i\n";
if ($conn->beginTransaction()) {
$stmt = $conn->query('SELECT fakecolumn FROM faketable');
}
$conn->commit();
}
$conn = null;
echo "Done.\n";
?>
--EXPECT--
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 7
Iteration 8
Iteration 9
Iteration 10
Iteration 11
Iteration 12
Iteration 13
Iteration 14
Iteration 15
Iteration 16
Iteration 17
Iteration 18
Iteration 19
Iteration 20
Iteration 21
Iteration 22
Iteration 23
Iteration 24
Iteration 25
Iteration 26
Iteration 27
Iteration 28
Iteration 29
Iteration 30
Iteration 31
Iteration 32
Iteration 33
Iteration 34
Iteration 35
Iteration 36
Iteration 37
Iteration 38
Iteration 39
Iteration 40
Iteration 41
Iteration 42
Iteration 43
Iteration 44
Iteration 45
Iteration 46
Iteration 47
Iteration 48
Iteration 49
Done.

View file

@ -1,26 +1,27 @@
--TEST--
UTF-8 connection strings
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
$server = 'localhost';
$databaseName = 'test';
$uid = 'sa';
$pwd = 'Sunshine4u';
$server = 'localhost';
$databaseName = 'test';
$uid = 'sa';
$pwd = 'Sunshine4u';
// test an invalid connection credentials
$c = new PDO('sqlsrv:Server=' . $server . ';Database=' . $databaseName, $uid, $pwd);
if( $c !== false )
{
die( "Should have failed to connect." );
}
$dsn = getDSN($server, $databaseName);
// test an invalid connection credentials
$c = new PDO($dsn, $uid, $pwd);
if ($c !== false) {
die("Should have failed to connect.");
}
?>
--EXPECTREGEX--
Fatal error: Uncaught PDOException: SQLSTATE\[(28000|08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\](\[SQL Server\])?(Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |Login timeout expired|Login failed for user 'sa'\.) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+
Fatal error: Uncaught PDOException: SQLSTATE\[(28000|08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\](\[SQL Server\])?(Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |Login timeout expired|Login failed for user 'sa'\.) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+
Stack trace:
#0 .+(\/|\\)pdo_utf8_conn\.php\([0-9]+\): PDO->__construct\('sqlsrv:Server=l\.\.\.', 'sa', 'Sunshine4u'\)
#1 {main}

View file

@ -1,200 +1,206 @@
--TEST--
PDOStatement::BindParam for predefined constants and buffered query.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
//*************************************************************************************
// Test binding with different predefined constants and using buffered query to update and
// Test binding with different predefined constants and using buffered query to update and
// select data.
//*************************************************************************************
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
function insert($db)
function insert($db, $tbname)
{
$query = "DECLARE @string VARCHAR(MAX) = '0000000000'";
$query .= "DECLARE @string1 VARCHAR(MAX) = '00'";
$query .= "DECLARE @bin VARBINARY(MAX)";
$query .= "DECLARE @bin1 VARBINARY(2)";
$query .= "SET @bin = CAST(@string AS VARBINARY(MAX))";
$query .= "SET @bin1 = CAST(@string1 AS VARBINARY(2))";
$query .= "INSERT INTO PDO_AllTypes (";
$query .= "BigIntCol,BitCol,IntCol,";
$query .= "SmallIntCol,TinyIntCol,";
$query .= "DecimalCol,NumCol,MoneyCol,";
$query .= "SmallMoneyCol,FloatCol,RealCol,";
$query .= "CharCol,VarcharCol,TextCol,";
$query .= "NCharCol,NVarcharCol,ImageCol,";
$query .= "BinaryCol,VarbinaryCol,SmallDTCol,";
$query .= "DateTimeCol,DTOffsetCol,";
$query .= "TimeCol,Guidcol,VarbinaryMaxCol,";
$query .= "VarcharMaxCol,XmlCol,NTextCol,";
$query .= "NVarCharMaxCol) VALUES (0,'0',0,1,1,111,1,";
$query .= "111.1110,111.1110,111.111,111.111,";
$query .= "'STRINGCOL2','STRINGCOL2',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'STRINGCOL2','STRINGCOL2','00',";
$query .= "CONVERT(BINARY(2),@bin),CONVERT(VARBINARY(2),@bin1),'2000-11-11 11:11:00',";
$query .= "'2000-11-11 11:11:11.110',";
$query .= "'2000-11-11 11:11:11.1110000 +00:00','11:11:11.1110000',";
$query .= "'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',CONVERT(VARBINARY(MAX),@bin1) ,";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.')";
$bin = fopen('php://memory', 'a');
fwrite($bin, '00');
rewind($bin);
$numRows = $db->exec($query);
echo "Insert complete!\n";
$inputs = array("BigIntCol" => 0,
"BitCol" => '0',
"IntCol" => 0,
"SmallIntCol" => 1,
"TinyIntCol" => 1,
"DecimalCol" => 111,
"NumCol" => 1,
"MoneyCol" => 111.1110,
"SmallMoneyCol" => 111.1110,
"FloatCol" => 111.111,
"RealCol" => 111.111,
"CharCol" => 'STRINGCOL2',
"VarcharCol" => 'STRINGCOL2',
"TextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',
"NCharCol" => 'STRINGCOL2',
"NVarcharCol" => 'STRINGCOL2',
"ImageCol" => new BindParamOp(17, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"BinaryCol" => new BindParamOp(18, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"VarbinaryCol" => new BindParamOp(19, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"SmallDTCol" => '2000-11-11 11:11:00',
"DateTimeCol" => '2000-11-11 11:11:11.110',
"DTOffsetCol" => '2000-11-11 11:11:11.1110000 +00:00',
"TimeCol" => '11:11:11.1110000',
"Guidcol" => 'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',
"VarbinaryMaxCol" => new BindParamOp(25, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"VarcharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',
"XmlCol" => '<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>',
"NTextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',
"NVarCharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.');
$stmt = insertRow($db, $tbname, $inputs, "prepareBindParam");
unset($stmt);
echo "Insert complete!\n";
}
function bindParam_LOB($db)
function bindPARAM_LOB($db, $tbname)
{
// Binding LOB with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = '0';
$query = "UPDATE PDO_AllTypes SET [VarbinaryCol]=:Name WHERE [BitCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '00');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(':value',$data);
$result = $stmt->execute();
$select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$result = $stmt->fetchColumn(26); // Retrieve VarbinaryCol
print("$result\n");
// Binding LOB with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = '0';
$query = "UPDATE $tbname SET [VarbinaryCol]=:Name WHERE [BitCol]=:value";
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '00');
rewind($noteID);
$stmt->bindParam(':Name', $noteID, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(':value', $data);
$result = $stmt->execute();
$select = "SELECT * FROM $tbname WHERE [BitCol]=:value";
$stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value', $data);
$stmt->execute();
$result = $stmt->fetchColumn(26); // Retrieve VarbinaryCol
unset($stmt);
print("$result\n");
}
function bindParam_STR($db)
function bindPARAM_STR($db, $tbname)
{
// Binding STR with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 'STRINGCOL2';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [CharCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(':value',$data);
$stmt->execute();
$select = "SELECT * FROM PDO_AllTypes WHERE [CharCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
$result = str_replace("\0","",$result);
print("$result\n");
// Binding STR with buffered queries activated.
// fopen returns a resource, if using PDO::PARAM_STR, the PDO side converts it to a zend_string "Resource id #*"
// thus a resource is not meant to bind parameter using PDO::PARAM_STR
$noteID = '1';
$data = 'STRINGCOL2';
$query = "UPDATE $tbname SET [BitCol]=:Name WHERE [CharCol]=:value";
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':Name', $noteID, PDO::PARAM_STR);
$stmt->bindParam(':value', $data);
$stmt->execute();
$select = "SELECT * FROM $tbname WHERE [CharCol]=:value";
$stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value', $data);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
unset($stmt);
$result = str_replace("\0", "", $result);
print("$result\n");
}
function bindParam_NULL($db)
function bindPARAM_NULL($db, $tbname)
{
// Binding NULL with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 'STRINGCOL2';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [VarcharCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, null);
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_NULL);
$stmt->bindParam(':value',$data);
$stmt->execute();
// Binding NULL with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 'STRINGCOL2';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [VarcharCol]=:value";
$data = '0';
$select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
$result = str_replace("\0","",$result);
print("$result\n");
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, null);
rewind($noteID);
$stmt->bindParam(':Name', $noteID, PDO::PARAM_NULL);
$stmt->bindParam(':value', $data);
$stmt->execute();
$data = '0';
$select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value";
$stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value', $data);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
unset($stmt);
$result = str_replace("\0", "", $result);
print("$result\n");
}
function bindParam_INT($db)
function bindPARAM_INT($db, $tbname)
{
// Binding INT with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 0;
$query = "UPDATE PDO_ALLTypes SET [IntCol]=:Name WHERE [IntCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_INT);
$stmt->bindParam(':value',$data);
$stmt->execute();
$select = "SELECT * FROM PDO_AllTypes WHERE [BigIntCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data,PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchColumn(11); // Retrieve IntCol
$result = str_replace("\0","",$result);
print("$result\n");
// Binding INT with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 0;
$query = "UPDATE $tbname SET [IntCol]=:Name WHERE [IntCol]=:value";
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name', $noteID, PDO::PARAM_INT);
$stmt->bindParam(':value', $data);
$stmt->execute();
$select = "SELECT * FROM $tbname WHERE [BigIntCol]=:value";
$stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value', $data, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchColumn(11); // Retrieve IntCol
unset($stmt);
$result = str_replace("\0", "", $result);
print("$result\n");
}
function bindParam_BOOL($db)
function bindPARAM_BOOL($db, $tbname)
{
// Binding BOOL with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = '0';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [BigIntCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_BOOL);
$stmt->bindParam(':value',$data);
$stmt->execute();
$query = "SELECT * FROM PDO_AllTypes WHERE [BigIntCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data,PDO::PARAM_BOOL);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
$result = str_replace("\0","",$result);
print("$result\n");
// Binding BOOL with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = '0';
$query = "UPDATE $tbname SET [BitCol]=:Name WHERE [BigIntCol]=:value";
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name', $noteID, PDO::PARAM_BOOL);
$stmt->bindParam(':value', $data);
$stmt->execute();
$query = "SELECT * FROM $tbname WHERE [BigIntCol]=:value";
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value', $data, PDO::PARAM_BOOL);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
unset($stmt);
$result = str_replace("\0", "", $result);
print("$result\n");
}
function delete($db)
function delete($db, $tbname)
{
$data = "STRINGCOL2";
$query = "DELETE FROM PDO_AllTypes WHERE [CharCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$data = "STRINGCOL2";
$query = "DELETE FROM $tbname WHERE [CharCol]=:value";
$stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value', $data);
$stmt->execute();
unset($stmt);
}
try {
$db = connect();
$tbname = "PDO_AllTypes";
createAndInsertTableAllTypes($db, $tbname);
insert($db, $tbname);
bindPARAM_LOB($db, $tbname);
bindPARAM_STR($db, $tbname);
bindPARAM_NULL($db, $tbname);
bindPARAM_INT($db, $tbname);
bindPARAM_BOOL($db, $tbname);
delete($db, $tbname);
$db = connect();
insert($db);
bindParam_LOB($db);
bindParam_STR($db);
bindParam_NULL($db);
bindParam_INT($db);
bindParam_BOOL($db);
delete($db);
echo "Test Completed";
}
catch( PDOException $e ) {
var_dump( $e );
dropTable($db, $tbname);
unset($db);
echo "Test Completed";
} catch (PDOException $e) {
var_dump($e);
exit;
}
@ -207,4 +213,4 @@ Insert complete!
0
1
1
Test Completed
Test Completed

View file

@ -1,53 +1,50 @@
--TEST--
Test the bindColumn method using either by bind by column number or bind by column name
--SKIPIF--
<?php require "skipif.inc"; ?>
<?php require "skipif_mid-refactor.inc"; ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
require_once "MsCommon.inc";
function bindColumn_byName($db)
function bindColumnByName($db, $tbname)
{
global $table1;
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM " . $table1);
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname");
$stmt->execute();
$stmt->bindColumn('IntCol', $intCol);
$stmt->bindColumn('CharCol', $charCol);
$stmt->bindColumn('DateTimeCol', $dateTimeCol);
while($row = $stmt->fetch(PDO::FETCH_BOUND))
{
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n";
}
}
function bindColumn_byNumber($db)
function bindColumnByNumber($db, $tbname)
{
global $table1;
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM " . $table1);
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname");
$stmt->execute();
$stmt->bindColumn(1, $intCol);
$stmt->bindColumn(2, $charCol);
$stmt->bindColumn(3, $dateTimeCol);
while($row = $stmt->fetch(PDO::FETCH_BOUND))
{
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n";
}
}
try
{
try {
$db = connect();
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
echo "Bind Column by name :\n";
bindColumn_byName($db);
bindColumnByName($db, $tbname);
echo "Bind Column by number :\n";
bindColumn_byNumber($db);
}
catch (PDOException $e)
{
bindColumnByNumber($db, $tbname);
dropTable($db, $tbname);
unset($db);
} catch (PDOException $e) {
var_dump($e);
}
@ -58,4 +55,4 @@ Bind Column by name :
2 : STRINGCOL2 : 2000-11-11 11:11:11.223
Bind Column by number :
1 : STRINGCOL1 : 2000-11-11 11:11:11.110
2 : STRINGCOL2 : 2000-11-11 11:11:11.223
2 : STRINGCOL2 : 2000-11-11 11:11:11.223

View file

@ -1,7 +1,7 @@
--TEST--
PDOStatement::BindParam for NULL types and for value types.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
@ -23,141 +23,134 @@ PDOStatement::BindParam for NULL types and for value types.
//*************************************************************************************
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
function bind_params_with_null($db)
function bindParamsWithNull($db, $tbname)
{
global $table2;
$sql = " INSERT INTO " .$table2 . "
([BigIntCol]
,[BinaryCol]
,[BitCol]
,[CharCol]
,[DateCol]
,[DateTimeCol]
,[DateTime2Col]
,[DTOffsetCol]
,[DecimalCol]
,[FloatCol]
,[ImageCol]
,[IntCol]
,[MoneyCol]
,[NCharCol]
,[NTextCol]
,[NumCol]
,[NVarCharCol]
,[NVarCharMaxCol]
,[RealCol]
,[SmallDTCol]
,[SmallIntCol]
,[SmallMoneyCol]
,[TextCol]
,[TimeCol]
,[TinyIntCol]
,[Guidcol]
,[VarbinaryCol]
,[VarbinaryMaxCol]
,[VarcharCol]
,[VarcharMaxCol]
,[XmlCol])
VALUES (?,?,?,?,?,?,?,?,?,? /*10*/,?,?,?,?,?,?,?,?,?,? /*20*/, ?,?,?,?,?,?,?,?,?,?, ? /*31*/)";
$sql = "INSERT INTO $tbname
([BigIntCol],
[BinaryCol],
[BitCol],
[CharCol],
[DateCol],
[DateTimeCol],
[DateTime2Col],
[DTOffsetCol],
[DecimalCol],
[FloatCol],
[ImageCol],
[IntCol],
[MoneyCol],
[NCharCol],
[NTextCol],
[NumCol],
[NVarCharCol],
[NVarCharMaxCol],
[RealCol],
[SmallDTCol],
[SmallIntCol],
[SmallMoneyCol],
[TextCol],
[TimeCol],
[TinyIntCol],
[Guidcol],
[VarbinaryCol],
[VarbinaryMaxCol],
[VarcharCol],
[VarcharMaxCol],
[XmlCol])
VALUES (?,?,?,?,?,?,?,?,?,? /*10*/,?,?,?,?,?,?,?,?,?,? /*20*/, ?,?,?,?,?,?,?,?,?,?, ? /*31*/)";
$stmt = $db->prepare($sql);
$stmt = $db->prepare($sql);
$param = null;
$stmt->bindParam(1, $param);
$stmt->bindParam(2, $param, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY );
$stmt->bindParam(3, $param );
$stmt->bindParam(4, $param );
$stmt->bindParam(5, $param );
$stmt->bindParam(6, $param );
$stmt->bindParam(7, $param );
$stmt->bindParam(8, $param );
$stmt->bindParam(9, $param );
$stmt->bindParam(10, $param );
$stmt->bindParam(11, $param );
$stmt->bindParam(12, $param );
$stmt->bindParam(13, $param );
$stmt->bindParam(14, $param );
$stmt->bindParam(15, $param );
$stmt->bindParam(16, $param );
$stmt->bindParam(17, $param );
$stmt->bindParam(18, $param );
$stmt->bindParam(19, $param );
$stmt->bindParam(20, $param );
$stmt->bindParam(21, $param );
$stmt->bindParam(22, $param );
$stmt->bindParam(23, $param );
$stmt->bindParam(24, $param );
$stmt->bindParam(25, $param );
$stmt->bindParam(26, $param );
$stmt->bindParam(27, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY ); //PDO::PARAM_STR OR PDO::PARAM_LOB DOES NOT MATTER
$stmt->bindParam(28, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY );
$stmt->bindParam(29, $param );
$stmt->bindParam(30, $param );
$stmt->bindParam(31, $param );
$stmt->execute();
$stmt->bindParam(2, $param, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(3, $param);
$stmt->bindParam(4, $param);
$stmt->bindParam(5, $param);
$stmt->bindParam(6, $param);
$stmt->bindParam(7, $param);
$stmt->bindParam(8, $param);
$stmt->bindParam(9, $param);
$stmt->bindParam(10, $param);
$stmt->bindParam(11, $param);
$stmt->bindParam(12, $param);
$stmt->bindParam(13, $param);
$stmt->bindParam(14, $param);
$stmt->bindParam(15, $param);
$stmt->bindParam(16, $param);
$stmt->bindParam(17, $param);
$stmt->bindParam(18, $param);
$stmt->bindParam(19, $param);
$stmt->bindParam(20, $param);
$stmt->bindParam(21, $param);
$stmt->bindParam(22, $param);
$stmt->bindParam(23, $param);
$stmt->bindParam(24, $param);
$stmt->bindParam(25, $param);
$stmt->bindParam(26, $param);
$stmt->bindParam(27, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); //PDO::PARAM_STR OR PDO::PARAM_LOB DOES NOT MATTER
$stmt->bindParam(28, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(29, $param);
$stmt->bindParam(30, $param);
$stmt->bindParam(31, $param);
$stmt->execute();
}
function bind_params_int($db)
function bindParamsInt($db, $tbname)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BigIntCol = :bigIntCol ");
$int = 1;
$stmt->bindParam(":bigIntCol", $int, PDO::PARAM_INT);
$stmt->execute();
$stmt = $db->prepare("SELECT * FROM $tbname WHERE BigIntCol = :bigIntCol");
$int = 1;
$stmt->bindParam(":bigIntCol", $int, PDO::PARAM_INT);
$stmt->execute();
}
function bind_params_str($db)
function bindParamsStr($db, $tbname)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE CharCol = :charCol ");
$char = "STRINGCOL1";
$stmt->bindParam(":charCol", $char, PDO::PARAM_STR);
$stmt->execute();
$stmt = $db->prepare("SELECT * FROM $tbname WHERE CharCol = :charCol");
$char = "STRINGCOL1";
$stmt->bindParam(":charCol", $char, PDO::PARAM_STR);
$stmt->execute();
}
function bind_params_bool($db)
function bindParamsBool($db, $tbname)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BitCol = :bool ");
$bool = 0;
$stmt->bindParam(":bool" , $bool, PDO::PARAM_BOOL);
$stmt->execute();
$stmt = $db->prepare("SELECT * FROM " . $tbname . " WHERE BitCol = :bool");
$bool = 0;
$stmt->bindParam(":bool", $bool, PDO::PARAM_BOOL);
$stmt->execute();
}
function bind_params_lob($db)
function bindParamsLob($db, $tbname)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BinaryCol = :lob ");
$lob = 0;
$stmt->bindParam(":lob" , $lob, PDO::PARAM_LOB);
$stmt->execute();
$stmt = $db->prepare("SELECT * FROM $tbname WHERE BinaryCol = :lob");
$lob = fopen('php://memory', 'a');
fwrite($lob, '00');
rewind($lob);
$stmt->bindParam(":lob", $lob, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
}
try {
$db = connect();
$tbname = "PDO_AllTypes";
createAndInsertTableAllTypes($db, $tbname);
bindParamsWithNull($db, $tbname);
bindParamsInt($db, $tbname);
bindParamsStr($db, $tbname);
bindParamsBool($db, $tbname);
bindParamsLob($db, $tbname);
$db = connect();
create_and_insert_table2( $db );
bind_params_with_null($db);
bind_params_int($db);
bind_params_str($db);
bind_params_bool($db);
bind_params_lob($db);
echo "Test Succeeded";
}
catch( PDOException $e ) {
var_dump( $e );
dropTable($db, $tbname);
unset($db);
echo "Test Succeeded\n";
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
--EXPECT--
Test Succeeded

View file

@ -1,27 +1,30 @@
--TEST--
Test bindValue method.
--SKIPIF--
<?php require "skipif.inc"; ?>
<?php require("skipif_mid-refactor.inc"); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
require_once 'MsCommon.inc';
try{
try {
$db = connect();
global $table2;
$tbname = "PDO_AllTypes";
createAndInsertTableAllTypes($db, $tbname);
$bigint = 1;
$string = "STRINGCOL1";
$stmt = $db->prepare("SELECT IntCol FROM " . $table2 . " WHERE BigIntCol = :bigint AND CharCol = :string");
$stmt = $db->prepare("SELECT IntCol FROM $tbname WHERE BigIntCol = :bigint AND CharCol = :string");
$stmt->bindValue(':bigint', $bigint, PDO::PARAM_INT);
$stmt->bindValue(':string', $string, PDO::PARAM_STR);
$stmt->execute();
dropTable($db, $tbname);
unset($stmt);
unset($db);
echo "Test Complete!\n";
}
catch (PDOException $e)
{
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
Test Complete!
Test Complete!

View file

@ -1,28 +1,27 @@
--TEST--
Test PDOStatement::closeCursor method.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
try{
try {
$db = connect();
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2);
$tbname = "PDO_AllTypes";
createAndInsertTableAllTypes($db, $tbname);
$stmt = $db->prepare("SELECT * FROM $tbname");
$stmt->execute();
$result = $stmt->fetch();
$stmt->closeCursor();
echo "Test complete!";
}
catch ( PDOException $e)
{
dropTable($db, $tbname);
unset($stmt);
unset($db);
echo "Test complete!\n";
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
Test complete!
Test complete!

View file

@ -1,24 +1,23 @@
--TEST--
Test PDOStatement::columnCount if the number of the columns in a result set.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
require_once 'MsCommon.inc';
try
{
$db = connect();
$sql = "SELECT * FROM PDO_AllTypes";
$stmt = $db->prepare($sql);
$stmt->execute();
print_r("Existing table contains: " . $stmt->columnCount());
}
catch(PDOException $e)
{
var_dump($e);
}
try {
$db = connect();
$tbname = "PDO_AllTypes";
createAndInsertTableAllTypes($db, $tbname);
$sql = "SELECT * FROM $tbname";
$stmt = $db->prepare($sql);
$stmt->execute();
print_r("Existing table contains: " . $stmt->columnCount() . "\n");
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
Existing table contains: 31
Existing table contains: 31

View file

@ -1,26 +1,30 @@
--TEST--
Test debugDumpParams method.
--SKIPIF--
<?php require "skipif.inc"; ?>
<?php require("skipif_mid-refactor.inc"); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once('MsCommon_mid-refactor.inc');
require_once("MsData_PDO_AllTypes.inc");
try{
try {
$db = connect();
global $table2;
$tbname = "PDO_AllTypes";
createAndInsertTableAllTypes($db, $tbname);
$bigint = 1;
$string = "STRINGCOL1";
$stmt = $db->prepare("SELECT IntCol FROM " . $table2 . " WHERE BigIntCol = :bigint AND CharCol = :string");
$stmt = $db->prepare("SELECT IntCol FROM $tbname WHERE BigIntCol = :bigint AND CharCol = :string");
$stmt->bindValue(':bigint', $bigint, PDO::PARAM_INT);
$stmt->bindValue(':string', $string, PDO::PARAM_STR);
$stmt->execute();
$stmt->debugDumpParams();
}
catch (PDOException $e)
{
dropTable($db, $tbname);
unset($stmt);
unset($db);
} catch (PDOException $e) {
var_dump($e);
}
?>
@ -36,4 +40,4 @@ Key: Name: [7] :string
paramno=1
name=[7] ":string"
is_param=1
param_type=2
param_type=2

View file

@ -1,31 +1,30 @@
--TEST--
Test PDOStatement::errorInfo and PDOStatement::errorCode methods.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
try
{
try {
$db = connect();
$stmt = $db->prepare("SELECT * FROM PDO_Types_1");
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
$stmt = $db->prepare("SELECT * FROM $tbname");
$stmt->execute();
$arr = $stmt->errorInfo();
print_r("Error Info :\n");
var_dump($arr);
$arr = $stmt->errorCode();
print_r("Error Code : " . $arr . "\n");
$db = null;
}
catch (PDOException $e)
{
dropTable($db, $tbname);
unset($stmt);
unset($db);
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
Error Info :
@ -37,4 +36,4 @@ array(3) {
[2]=>
NULL
}
Error Code : 00000
Error Code : 00000

View file

@ -1,34 +1,52 @@
--TEST--
Test PDOStatement::execute method.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
try
{
$db = connect();
try {
$db = connect();
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
$stmt = $db->prepare("SELECT * FROM PDO_Types_1");
$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($rows);
// Test update table value
$stmt = $db->prepare("UPDATE PDO_Types_1 SET IntCol=1");
$rows = $stmt->execute();
var_dump($rows);
// Test insert value to table
$stmt1 = $db->prepare("INSERT INTO PDO_Types_1 (IntCol,CharCol,NCharCol,DateTimeCol,VarcharCol,NVarCharCol,FloatCol,XmlCol) VALUES (2,'STRINGCOL1','STRINGCOL1','2000-11-11 11:11:11.110','STRINGCOL1','STRINGCOL1',111.111,'<xml> 1 This is a really large string used to test certain large data types like xml data type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>')");
$rows = $stmt1->execute();
var_dump($rows);
$db = null;
}
catch(PDOException $e)
{
var_dump($e);
$stmt = $db->prepare("SELECT * FROM $tbname");
$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($rows);
// Test update table value
if (isColEncrypted()) {
$stmt = $db->prepare("UPDATE $tbname SET IntCol=?");
$r = $stmt->execute(array(1));
} else {
$stmt = $db->prepare("UPDATE $tbname SET IntCol=1");
$r = $stmt->execute();
}
var_dump($r);
// Test insert value to table
$inputs = array("IntCol" => 2,
"CharCol" => 'STRINGCOL1',
"NCharCol" => 'STRINGCOL1',
"DateTimeCol" => '2000-11-11 11:11:11.110',
"VarcharCol" => 'STRINGCOL1',
"NVarCharCol" => 'STRINGCOL1',
"FloatCol" => 111.111,
"XmlCol" => '<xml> 1 This is a really large string used to test certain large data types like xml data type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>');
$r;
$stmt1 = insertRow($db, $tbname, $inputs, "prepareExecuteBind", $r);
var_dump($r);
dropTable($db, $tbname);
unset($stmt);
unset($stmt1);
unset($conn);
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
array(8) {

View file

@ -1,54 +1,42 @@
--TEST--
Test the fetchColumn() method.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
function fetch_column( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
// Fetch the first column from the next row in resultset. (This wud be first row since this is a first call to fetchcol)
$result = $stmt->fetchColumn();
var_dump($result);
// Fetch the second column from the next row. (This would be second row since this is a second call to fetchcol).
$result = $stmt->fetchColumn(1);
var_dump($result);
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
// Test false is returned when there are no more rows.
$result = $stmt->fetchColumn(1);
var_dump($result);
}
try
{
//$verbose = false;
$db = connect();
create_and_insert_table1( $db );
fetch_column($db);
}
try {
$db = connect();
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
catch( PDOException $e ) {
$stmt = $db->query("Select * from $tbname");
var_dump( $e );
// Fetch the first column from the next row in resultset. (This would be first row since this is a first call to fetchcol)
$result = $stmt->fetchColumn();
var_dump($result);
// Fetch the second column from the next row. (This would be second row since this is a second call to fetchcol).
$result = $stmt->fetchColumn(1);
var_dump($result);
// Test false is returned when there are no more rows.
$result = $stmt->fetchColumn(1);
var_dump($result);
dropTable($db, $tbname);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECT--
string(1) "1"
string(10) "STRINGCOL2"
bool(false)

View file

@ -1,153 +1,116 @@
--TEST--
Test the PDOStatement::fetch() method with different fetch styles.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
function fetch_both( $conn )
function fetchWithStyle($conn, $tbname, $style)
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$result = $stmt->fetch(PDO::FETCH_BOTH);
var_dump($result);
$stmt->closeCursor();
}
function fetch_assoc( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$result = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($result);
$stmt->closeCursor();
}
function fetch_lazy( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from " . $table1 );
$result = $stmt->fetch(PDO::FETCH_LAZY);
var_dump($result);
$stmt->closeCursor();
}
function fetch_obj( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$result = $stmt->fetch(PDO::FETCH_OBJ);
var_dump($result);
$stmt->closeCursor();
}
function fetch_num( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$result = $stmt->fetch(PDO::FETCH_NUM);
var_dump($result);
$stmt->closeCursor();
}
function fetch_bound( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$stmt->bindColumn('IntCol', $IntCol);
$stmt->bindColumn('CharCol', $CharCol);
$stmt->bindColumn('NCharCol', $NCharCol);
$stmt->bindColumn('DateTimeCol', $DateTimeCol);
$stmt->bindColumn('VarcharCol', $VarcharCol);
$stmt->bindColumn('NVarCharCol', $NVarCharCol);
$stmt->bindColumn('FloatCol', $FloatCol);
$stmt->bindColumn('XmlCol', $XmlCol);
$result = $stmt->fetch(PDO::FETCH_BOUND);
if (!$result)
{
die("Error in FETCH_BOUND\n");
$stmt = $conn->query("SELECT * FROM $tbname");
switch ($style) {
case PDO::FETCH_BOTH:
case PDO::FETCH_ASSOC:
case PDO::FETCH_LAZY:
case PDO::FETCH_OBJ:
case PDO::FETCH_NUM:
{
$result = $stmt->fetch($style);
var_dump($result);
unset($stmt);
break;
}
case PDO::FETCH_BOUND:
{
$stmt->bindColumn('IntCol', $IntCol);
$stmt->bindColumn('CharCol', $CharCol);
$stmt->bindColumn('NCharCol', $NCharCol);
$stmt->bindColumn('DateTimeCol', $DateTimeCol);
$stmt->bindColumn('VarcharCol', $VarcharCol);
$stmt->bindColumn('NVarCharCol', $NVarCharCol);
$stmt->bindColumn('FloatCol', $FloatCol);
$stmt->bindColumn('XmlCol', $XmlCol);
$result = $stmt->fetch($style);
if (!$result) {
die("Error in FETCH_BOUND\n");
}
var_dump($IntCol);
var_dump($CharCol);
var_dump($NCharCol);
var_dump($DateTimeCol);
var_dump($VarcharCol);
var_dump($NVarCharCol);
var_dump($FloatCol);
var_dump($XmlCol);
unset($stmt);
break;
}
case PDO::FETCH_CLASS:
{
global $mainTypesClass;
$stmt->setFetchMode($style, $mainTypesClass);
$result = $stmt->fetch($style);
$result->dumpAll();
unset($stmt);
break;
}
case PDO::FETCH_INTO:
{
global $mainTypesClass;
$obj = new $mainTypesClass;
$stmt->setFetchMode($style, $obj);
$result = $stmt->fetch($style);
$obj->dumpAll();
unset($stmt);
break;
}
case "PDO::FETCH_INVALID":
{
try {
$result = $stmt->fetch(PDO::FETCH_UNKNOWN);
} catch (PDOException $err) {
print_r($err);
}
break;
}
}
var_dump($IntCol);
var_dump($CharCol);
var_dump($NCharCol);
var_dump($DateTimeCol);
var_dump($VarcharCol);
var_dump($NVarCharCol);
var_dump($FloatCol);
var_dump($XmlCol);
$stmt->closeCursor();
}
function fetch_class( $conn )
{
global $table1;
global $table1_class;
$stmt = $conn->query( "Select * from ". $table1 );
$stmt->setFetchMode(PDO::FETCH_CLASS, $table1_class);
$result = $stmt->fetch(PDO::FETCH_CLASS);
$result->dumpAll();
$stmt->closeCursor();
}
function fetch_into( $conn )
{
global $table1;
global $table1_class;
$stmt = $conn->query( "Select * from ". $table1 );
$obj = new $table1_class;
$stmt->setFetchMode(PDO::FETCH_INTO, $obj);
$result = $stmt->fetch(PDO::FETCH_INTO);
$obj->dumpAll();
$stmt->closeCursor();
}
function fetch_invalid( $conn )
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
try
{
$result = $stmt->fetch(PDO::FETCH_UNKNOWN);
}
catch(PDOException $err)
{
print_r($err);
}
}
try
{
try {
$db = connect();
create_and_insert_table1( $db );
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
echo "Test_1 : FETCH_BOTH :\n";
fetch_both($db);
fetchWithStyle($db, $tbname, PDO::FETCH_BOTH);
echo "Test_2 : FETCH_ASSOC :\n";
fetch_assoc($db);
fetchWithStyle($db, $tbname, PDO::FETCH_ASSOC);
echo "Test_3 : FETCH_LAZY :\n";
fetch_lazy($db);
fetchWithStyle($db, $tbname, PDO::FETCH_LAZY);
echo "Test_4 : FETCH_OBJ :\n";
fetch_obj($db);
fetchWithStyle($db, $tbname, PDO::FETCH_OBJ);
echo "Test_5 : FETCH_NUM :\n";
fetch_num($db);
fetchWithStyle($db, $tbname, PDO::FETCH_NUM);
echo "Test_6 : FETCH_BOUND :\n";
fetch_bound($db);
fetchWithStyle($db, $tbname, PDO::FETCH_BOUND);
echo "Test_7 : FETCH_CLASS :\n";
fetch_class($db);
fetchWithStyle($db, $tbname, PDO::FETCH_CLASS);
echo "Test_8 : FETCH_INTO :\n";
fetch_into($db);
fetchWithStyle($db, $tbname, PDO::FETCH_INTO);
echo "Test_9 : FETCH_INVALID :\n";
fetch_invalid($db);
}
catch( PDOException $e ) {
var_dump( $e );
fetchWithStyle($db, $tbname, "PDO::FETCH_INVALID");
dropTable($db, $tbname);
unset($db);
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECTF--
Test_1 : FETCH_BOTH :
@ -207,7 +170,7 @@ array(8) {
Test_3 : FETCH_LAZY :
object(PDORow)#%x (%x) {
["queryString"]=>
string(25) "Select * from PDO_Types_1"
string(27) "SELECT * FROM PDO_MainTypes"
["IntCol"]=>
string(1) "1"
["CharCol"]=>
@ -294,6 +257,6 @@ Test_9 : FETCH_INVALID :
Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x
Stack trace:
#0 %s: fetch_invalid(Object(PDO))
#0 %s: fetchWithStyle(Object(PDO), 'PDO_MainTypes', 'PDO::FETCH_INVA...')
#1 {main}
thrown in %s on line %x
thrown in %s on line %x

View file

@ -1,76 +1,78 @@
--TEST--
Test the PDOStatement::getColumnMeta() method (Note: there could be an issue about using a non-existent column index --- doesn't give any error/output/warning).
Test the PDOStatement::getColumnMeta() method
--DESCRIPTION--
there could be an issue about using a non-existent column index --- doesn't give any error/output/warning
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
function fetch_both( $conn )
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
function fetchBoth($conn, $tbname)
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$stmt = $conn->query("Select * from $tbname");
// 1
$meta = $stmt->getColumnMeta( 0 );
var_dump($meta);
$meta = $stmt->getColumnMeta(0);
var_dump($meta);
// 2
$meta = $stmt->getColumnMeta( 1 );
var_dump($meta);
$meta = $stmt->getColumnMeta(1);
var_dump($meta);
// 3
$meta = $stmt->getColumnMeta( 2 );
var_dump($meta);
$meta = $stmt->getColumnMeta(2);
var_dump($meta);
// 4
$meta = $stmt->getColumnMeta( 3 );
var_dump($meta);
$meta = $stmt->getColumnMeta(3);
var_dump($meta);
// 5
$meta = $stmt->getColumnMeta( 4 );
var_dump($meta);
$meta = $stmt->getColumnMeta(4);
var_dump($meta);
// 6
$meta = $stmt->getColumnMeta( 5 );
var_dump($meta);
$meta = $stmt->getColumnMeta(5);
var_dump($meta);
// 7
$meta = $stmt->getColumnMeta( 6 );
var_dump($meta);
$meta = $stmt->getColumnMeta(6);
var_dump($meta);
// 8
$meta = $stmt->getColumnMeta( 7 );
var_dump($meta);
$meta = $stmt->getColumnMeta(7);
if ($meta["sqlsrv:decl_type"] != "xml") {
echo "Wrong column metadata was retrieved for a xml column.\n";
}
unset($meta["sqlsrv:decl_type"]);
var_dump($meta);
// Test invalid arguments, set error mode to silent to reduce the amount of error messages generated
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
// Test negative column number, ignore the error messages
$meta = $stmt->getColumnMeta( -1 );
$meta = $stmt->getColumnMeta(-1);
var_dump($meta);
// Test non-existent column number
//$meta = $stmt->getColumnMeta( 10 );
//var_dump($meta);
$meta = $stmt->getColumnMeta(10);
var_dump($meta);
}
try
{
try {
$db = connect();
create_and_insert_table1( $db );
fetch_both($db);
}
catch( PDOException $e ) {
var_dump( $e );
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
fetchBoth($db, $tbname);
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECTF--
array(8) {
@ -199,11 +201,9 @@ array(8) {
["precision"]=>
int(0)
}
array(8) {
array(7) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(3) "xml"
["native_type"]=>
string(6) "string"
["table"]=>
@ -219,4 +219,6 @@ array(8) {
}
Warning: PDOStatement::getColumnMeta(): SQLSTATE[42P10]: Invalid column reference: column number must be non-negative in %s on line %x
bool(false)
bool(false)
Fatal error: pdo_sqlsrv_stmt_get_col_meta: invalid column number. in %s on line %x

View file

@ -1,124 +1,117 @@
--TEST--
Test the PDOStatement::getColumnMeta() method for Unicode column names (Note: there could be an issue about using a non-existent column index --- doesn't give any error/output/warning).
Test the PDOStatement::getColumnMeta() method for Unicode column names
--DESCRIPTION--
there could be an issue about using a non-existent column index --- doesn't give any error/output/warning
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
function fetch_both( $conn )
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
function fetchBoth($conn, $tbname)
{
global $table1;
$stmt = $conn->query( "Select * from ". $table1 );
$stmt = $conn->query("Select * from $tbname");
// 1
$meta = $stmt->getColumnMeta( 0 );
var_dump($meta);
$meta = $stmt->getColumnMeta(0);
var_dump($meta);
// 2
$meta = $stmt->getColumnMeta( 1 );
var_dump($meta);
$meta = $stmt->getColumnMeta(1);
var_dump($meta);
// 3
$meta = $stmt->getColumnMeta( 2 );
var_dump($meta);
$meta = $stmt->getColumnMeta(2);
var_dump($meta);
// 4
$meta = $stmt->getColumnMeta( 3 );
var_dump($meta);
$meta = $stmt->getColumnMeta(3);
var_dump($meta);
// 5
$meta = $stmt->getColumnMeta( 4 );
var_dump($meta);
$meta = $stmt->getColumnMeta(4);
var_dump($meta);
// 6
$meta = $stmt->getColumnMeta( 5 );
var_dump($meta);
$meta = $stmt->getColumnMeta(5);
var_dump($meta);
// 7
$meta = $stmt->getColumnMeta( 6 );
var_dump($meta);
$meta = $stmt->getColumnMeta(6);
var_dump($meta);
// 8
$meta = $stmt->getColumnMeta( 7 );
var_dump($meta);
$meta = $stmt->getColumnMeta(7);
if (isColEncrypted()) {
$xmlType = "nvarchar";
} else {
$xmlType = "xml";
}
if ($meta["sqlsrv:decl_type"] != $xmlType) {
echo "Wrong column metadata was retrieved for a $xmlType column.\n";
}
unset($meta["sqlsrv:decl_type"]);
var_dump($meta);
// Test invalid arguments, set error mode to silent to reduce the amount of error messages generated
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
// Test negative column number, ignore the error messages
$meta = $stmt->getColumnMeta( -1 );
$meta = $stmt->getColumnMeta(-1);
var_dump($meta);
// Test non-existent column number
//$meta = $stmt->getColumnMeta( 10 );
//var_dump($meta);
$meta = $stmt->getColumnMeta(10);
var_dump($meta);
}
function create_and_insert_table_unicode( $conn )
function createAndInsertTableUnicode($conn, $tbname)
{
global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1;
try
{
$create_query =
"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U'))
DROP TABLE " . $table1 .
" CREATE TABLE [dbo].[" . $table1 . "](
[此是後話] [int] NULL,
[Κοντάוְאַתָּה第] [char](10) NULL,
[NΚοντάוְאַתָּה第] [nchar](10) NULL,
[ნომინავიiałopioБун] [datetime] NULL,
[VarcharCol] [varchar](50) NULL,
[NVarΚοντάוְאַתָּה第] [nvarchar](50) NULL,
[FloatCol] [float] NULL,
[XmlCol] [xml] NULL
) ON [PRIMARY]
";
$conn->query( $create_query );
for ($i = 0 ; $i <= 1; ++ $i)
{
$insert_query =
"INSERT INTO PDO_Types_1 VALUES (".
$int_col[$i] . $comma .
$string_col[$i] . $comma .
$string_col[$i] . $comma .
"Convert(datetime, ". $date_col[$i] . ")" . $comma .
$string_col[$i] . $comma .
$string_col[$i] . $comma .
$decimal_col[$i] . $comma .
$xml_col[$i] .
")";
$conn->query ( $insert_query );
try {
global $string_col, $xml_col, $int_col, $decimal_col, $datetime_col;
if (isColEncrypted()) {
$xmlType = "nvarchar(max)";
} else {
$xmlType = "xml";
}
}
catch(Exception $e)
{
var_dump( $e);
$columnMetaArr = array("此是後話" => "int",
"Κοντάוְאַתָּה第" => "char(10)",
"NΚοντάוְאַתָּה第" => "nchar(10)",
"ნომინავიiałopioБун" => "datetime",
"VarcharCol" => "varchar(50)",
"NVarΚοντάוְאַתָּה第" => "nvarchar(50)",
"FloatCol" => "float",
"XmlCol" => $xmlType);
createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY]");
for ($i = 0 ; $i <= 1; ++ $i) {
$inputs = array("此是後話" => $int_col[$i],
"Κοντάוְאַתָּה第" => $string_col[$i],
"NΚοντάוְאַתָּה第" => $string_col[$i],
"ნომინავიiałopioБун" => $datetime_col[$i],
"VarcharCol" => $string_col[$i],
"NVarΚοντάוְאַתָּה第" => $string_col[$i],
"FloatCol" => $decimal_col[$i],
"XmlCol" => $xml_col[$i]);
$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam");
}
} catch (Exception $e) {
var_dump($e);
exit;
}
}
try
{
$db = connect();
create_and_insert_table_unicode( $db );
fetch_both($db);
}
catch( PDOException $e ) {
var_dump( $e );
try {
$db = connect();
$tbname = "PDO_MainTypes";
createAndInsertTableUnicode($db, $tbname);
fetchBoth($db, $tbname);
} catch (PDOException $e) {
var_dump($e);
exit;
}
?>
?>
--EXPECTF--
array(8) {
@ -247,11 +240,9 @@ array(8) {
["precision"]=>
int(0)
}
array(8) {
array(7) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(3) "xml"
["native_type"]=>
string(6) "string"
["table"]=>
@ -267,4 +258,6 @@ array(8) {
}
Warning: PDOStatement::getColumnMeta(): SQLSTATE[42P10]: Invalid column reference: column number must be non-negative in %s on line %x
bool(false)
bool(false)
Fatal error: pdo_sqlsrv_stmt_get_col_meta: invalid column number. in %s on line %x

View file

@ -1,48 +1,32 @@
--TEST--
Test setFetchMode method.
--SKIPIF--
<?php require 'skipif.inc'; ?>
<?php require 'skipif_mid-refactor.inc'; ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
require_once 'MsCommon.inc';
try{
try {
$db = connect();
$stmt = $db->query("SELECT * FROM " . $table1 );
echo "Set Fetch Mode for PDO::FETCH_ASSOC \n";
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetch();
var_dump($result);
$stmt = $db->query("SELECT * FROM " . $table1 );
echo "Set Fetch Mode for PDO::FETCH_NUM \n";
$stmt->setFetchMode(PDO::FETCH_NUM);
$result = $stmt->fetch();
var_dump($result);
$stmt = $db->query("SELECT * FROM " . $table1 );
echo "Set Fetch Mode for PDO::FETCH_BOTH \n";
$stmt->setFetchMode(PDO::FETCH_BOTH);
$result = $stmt->fetch();
var_dump($result);
$stmt = $db->query("SELECT * FROM " . $table1 );
echo "Set Fetch Mode for PDO::FETCH_LAZY \n";
$stmt->setFetchMode(PDO::FETCH_LAZY);
$result = $stmt->fetch();
var_dump($result);
$stmt = $db->query("SELECT * FROM " . $table1 );
echo "Set Fetch Mode for PDO::FETCH_OBJ \n";
$stmt->setFetchMode(PDO::FETCH_OBJ);
$result = $stmt->fetch();
var_dump($result);
}
catch ( PDOException $e)
{
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
$fetchModes = array("PDO::FETCH_ASSOC", "PDO::FETCH_NUM", "PDO::FETCH_BOTH", "PDO::FETCH_LAZY", "PDO::FETCH_OBJ");
foreach ($fetchModes as $mode) {
$stmt = $db->query("SELECT * FROM $tbname");
echo "Set Fetch Mode for $mode\n";
$stmt->setFetchMode(constant($mode));
$result = $stmt->fetch();
var_dump($result);
}
} catch (PDOException $e) {
var_dump($e);
}
?>
--EXPECT--
Set Fetch Mode for PDO::FETCH_ASSOC
Set Fetch Mode for PDO::FETCH_ASSOC
array(8) {
["IntCol"]=>
string(1) "1"
@ -61,7 +45,7 @@ array(8) {
["XmlCol"]=>
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
}
Set Fetch Mode for PDO::FETCH_NUM
Set Fetch Mode for PDO::FETCH_NUM
array(8) {
[0]=>
string(1) "1"
@ -80,7 +64,7 @@ array(8) {
[7]=>
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
}
Set Fetch Mode for PDO::FETCH_BOTH
Set Fetch Mode for PDO::FETCH_BOTH
array(16) {
["IntCol"]=>
string(1) "1"
@ -115,10 +99,10 @@ array(16) {
[7]=>
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
}
Set Fetch Mode for PDO::FETCH_LAZY
Set Fetch Mode for PDO::FETCH_LAZY
object(PDORow)#3 (9) {
["queryString"]=>
string(25) "SELECT * FROM PDO_Types_1"
string(27) "SELECT * FROM PDO_MainTypes"
["IntCol"]=>
string(1) "1"
["CharCol"]=>
@ -136,7 +120,7 @@ object(PDORow)#3 (9) {
["XmlCol"]=>
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
}
Set Fetch Mode for PDO::FETCH_OBJ
Set Fetch Mode for PDO::FETCH_OBJ
object(stdClass)#5 (8) {
["IntCol"]=>
string(1) "1"

View file

@ -1,7 +1,9 @@
--TEST--
scrollable results with no rows.
--DESCRIPTION--
this test is very similar to test_scrollable.phpt... might consider removing this test as a duplicate
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -9,23 +11,42 @@ scrollable results with no rows.
require_once('MsCommon.inc');
$conn = connect();
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
$conn = AE\connect();
$tableName = 'ScrollTest';
$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));
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('char(10)', 'value'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table for the test]n");
}
sqlsrv_free_stmt($stmt);
// Always Encrypted feature only supports SQLSRV_CURSOR_FORWARD or
// SQLSRV_CURSOR_CLIENT_BUFFERED
$query = "SELECT * FROM $tableName";
if (AE\isColEncrypted()) {
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
} else {
$options = array('Scrollable' => 'static');
}
$stmt = sqlsrv_query($conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'static' ));
$stmt = sqlsrv_query($conn, $query, array(), $options);
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");
};
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt);
print_r($row);
if ($row === false) {
print_r(sqlsrv_errors(), true);
}
$stmt = sqlsrv_query($conn, $query);
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");
@ -40,23 +61,7 @@ scrollable results with no rows.
print_r(sqlsrv_errors(), true);
}
$stmt = sqlsrv_query($conn, "SELECT * FROM ScrollTest");
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");
};
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt);
print_r($row);
if ($row === false) {
print_r(sqlsrv_errors(), true);
}
$stmt = sqlsrv_query($conn, "DROP TABLE ScrollTest");
dropTable($conn, $tableName);
echo "Test succeeded.\n";
?>

View file

@ -1,25 +0,0 @@
<?php
function getKSPpath()
{
$name = 'myKSP';
$dir_name = realpath(dirname(__FILE__));
$ksp = $dir_name . DIRECTORY_SEPARATOR . $name;
if ( strtoupper( substr( php_uname( 's' ), 0, 3 ) ) == 'WIN' ) {
$arch = 'x64';
if ( PHP_INT_SIZE == 4 ) // running 32 bit
$arch = '';
$ksp .= $arch . '.dll';
}
else
$ksp .= '.so';
return $ksp;
}
$ksp_name = 'MyCustomKSPName';
$encrypt_key = 'LPKCWVD07N3RG98J0MBLG4H2';
$ksp_test_table = 'CustomKSPTestTable';
?>

Some files were not shown because too many files have changed in this diff Show more