parent
eeec2f838d
commit
23f92effab
|
@ -39,12 +39,14 @@ ENV TEST_PHP_SQL_PWD Password123
|
|||
# update PATH after ODBC driver and tools are installed
|
||||
ENV PATH="/opt/mssql-tools/bin:${PATH}"
|
||||
|
||||
# add locale iso-8859-1
|
||||
# add locales for testing
|
||||
RUN sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
|
||||
RUN locale-gen en_US
|
||||
RUN sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
RUN sed -i 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
RUN locale-gen
|
||||
|
||||
# set locale to utf-8
|
||||
RUN locale-gen en_US.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 coveralls (upgrade both pip and requests first)
|
||||
|
@ -65,6 +67,10 @@ RUN /bin/bash -c "./packagize.sh"
|
|||
RUN echo "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.3/mods-available/sqlsrv.ini
|
||||
RUN echo "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.3/mods-available/pdo_sqlsrv.ini
|
||||
|
||||
# create a writable ini file for testing locales
|
||||
RUN echo '' > `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/99-overrides.ini
|
||||
RUN chmod 666 `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/99-overrides.ini
|
||||
|
||||
WORKDIR $PHPSQLDIR/source/sqlsrv
|
||||
RUN /usr/bin/phpize && ./configure LDFLAGS="-lgcov" CXXFLAGS="-O0 --coverage" && make && make install
|
||||
|
||||
|
|
|
@ -107,8 +107,9 @@ jobs:
|
|||
|
||||
- script: |
|
||||
sudo sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
|
||||
sudo locale-gen en_US
|
||||
sudo locale-gen en_US.UTF-8
|
||||
sudo sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
sudo sed -i 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
sudo locale-gen
|
||||
export LANG='en_US.UTF-8'
|
||||
export LANGUAGE='en_US:en'
|
||||
export LC_ALL='en_US.UTF-8'
|
||||
|
@ -151,6 +152,9 @@ jobs:
|
|||
echo copying pdo_sqlsrv to $dest
|
||||
sudo cp 30-pdo_sqlsrv.ini $dest
|
||||
|
||||
sudo touch $dest/99-overrides.ini
|
||||
sudo chmod 666 $dest/99-overrides.ini
|
||||
|
||||
php --ri sqlsrv
|
||||
php --ri pdo_sqlsrv
|
||||
displayName: 'Build and install drivers'
|
||||
|
@ -162,6 +166,7 @@ jobs:
|
|||
sed -i -e 's/TARGET_USERNAME/'"$(uid)"'/g' MsSetup.inc
|
||||
sed -i -e 's/TARGET_PASSWORD/'"$(pwd)"'/g' MsSetup.inc
|
||||
|
||||
export LC_ALL='en_US.UTF-8'
|
||||
php run-tests.php -P ./*.phpt 2>&1 | tee ../sqlsrv.log
|
||||
displayName: 'Run sqlsrv functional tests'
|
||||
|
||||
|
@ -172,6 +177,7 @@ jobs:
|
|||
sed -i -e 's/TARGET_USERNAME/'"$(uid)"'/g' MsSetup.inc
|
||||
sed -i -e 's/TARGET_PASSWORD/'"$(pwd)"'/g' MsSetup.inc
|
||||
|
||||
export LC_ALL='en_US.UTF-8'
|
||||
php run-tests.php -P ./*.phpt 2>&1 | tee ../pdo_sqlsrv.log
|
||||
displayName: 'Run pdo_sqlsrv functional tests'
|
||||
|
||||
|
|
|
@ -220,6 +220,22 @@ PHP_RINIT_FUNCTION(pdo_sqlsrv)
|
|||
ZEND_TSRMLS_CACHE_UPDATE();
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
// if necessary, set locale from the environment for ODBC, which MUST be done before any connection
|
||||
int set_locale = PDO_SQLSRV_G(set_locale_info);
|
||||
if (set_locale == 2) {
|
||||
setlocale(LC_ALL, "");
|
||||
LOG(SEV_NOTICE, "pdo_sqlsrv: setlocale LC_ALL");
|
||||
}
|
||||
else if (set_locale == 1) {
|
||||
setlocale(LC_CTYPE, "");
|
||||
LOG(SEV_NOTICE, "pdo_sqlsrv: setlocale LC_CTYPE");
|
||||
}
|
||||
else {
|
||||
LOG(SEV_NOTICE, "pdo_sqlsrv: setlocale NONE");
|
||||
}
|
||||
#endif
|
||||
|
||||
LOG( SEV_NOTICE, "pdo_sqlsrv: entering rinit" );
|
||||
|
||||
return SUCCESS;
|
||||
|
|
|
@ -32,6 +32,10 @@ ZEND_BEGIN_MODULE_GLOBALS(pdo_sqlsrv)
|
|||
unsigned int log_severity;
|
||||
zend_long client_buffer_max_size;
|
||||
|
||||
#ifndef _WIN32
|
||||
zend_long set_locale_info;
|
||||
#endif
|
||||
|
||||
ZEND_END_MODULE_GLOBALS(pdo_sqlsrv)
|
||||
|
||||
ZEND_EXTERN_MODULE_GLOBALS(pdo_sqlsrv);
|
||||
|
|
|
@ -55,11 +55,19 @@ extern HMODULE g_sqlsrv_hmodule;
|
|||
#define INI_PDO_SQLSRV_LOG "log_severity"
|
||||
#define INI_PREFIX "pdo_sqlsrv."
|
||||
|
||||
#ifndef _WIN32
|
||||
#define INI_PDO_SET_LOCALE_INFO "set_locale_info"
|
||||
#endif
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
STD_PHP_INI_ENTRY( INI_PREFIX INI_PDO_SQLSRV_LOG , "0", PHP_INI_ALL, OnUpdateLong, log_severity,
|
||||
zend_pdo_sqlsrv_globals, pdo_sqlsrv_globals )
|
||||
STD_PHP_INI_ENTRY( INI_PREFIX INI_PDO_SQLSRV_CLIENT_BUFFER_MAX_SIZE , INI_BUFFERED_QUERY_LIMIT_DEFAULT, PHP_INI_ALL, OnUpdateLong,
|
||||
client_buffer_max_size, zend_pdo_sqlsrv_globals, pdo_sqlsrv_globals )
|
||||
#ifndef _WIN32
|
||||
STD_PHP_INI_ENTRY(INI_PREFIX INI_PDO_SET_LOCALE_INFO, "2", PHP_INI_ALL, OnUpdateLong, set_locale_info,
|
||||
zend_pdo_sqlsrv_globals, pdo_sqlsrv_globals)
|
||||
#endif
|
||||
PHP_INI_END()
|
||||
|
||||
|
||||
|
|
|
@ -39,12 +39,6 @@ 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 {
|
||||
|
|
|
@ -654,6 +654,25 @@ PHP_RINIT_FUNCTION(sqlsrv)
|
|||
SQLSRV_G( log_subsystems ) = INI_INT( subsystems );
|
||||
SQLSRV_G( buffered_query_limit ) = INI_INT( buffered_limit );
|
||||
|
||||
#ifndef _WIN32
|
||||
char set_locale_info[] = INI_PREFIX INI_SET_LOCALE_INFO;
|
||||
SQLSRV_G(set_locale_info) = INI_INT(set_locale_info);
|
||||
|
||||
// if necessary, set locale from the environment for ODBC, which MUST be done before any connection
|
||||
int set_locale = SQLSRV_G(set_locale_info);
|
||||
if (set_locale == 2) {
|
||||
setlocale(LC_ALL, "");
|
||||
}
|
||||
else if (set_locale == 1) {
|
||||
setlocale(LC_CTYPE, "");
|
||||
}
|
||||
else {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
LOG(SEV_NOTICE, INI_PREFIX INI_SET_LOCALE_INFO " = %1!d!", set_locale);
|
||||
#endif
|
||||
|
||||
LOG( SEV_NOTICE, INI_PREFIX INI_WARNINGS_RETURN_AS_ERRORS " = %1!s!", SQLSRV_G( warnings_return_as_errors ) ? "On" : "Off");
|
||||
LOG( SEV_NOTICE, INI_PREFIX INI_LOG_SEVERITY " = %1!d!", SQLSRV_G( log_severity ));
|
||||
LOG( SEV_NOTICE, INI_PREFIX INI_LOG_SUBSYSTEMS " = %1!d!", SQLSRV_G( log_subsystems ));
|
||||
|
|
|
@ -42,6 +42,10 @@ zend_long current_subsystem;
|
|||
zend_bool warnings_return_as_errors;
|
||||
zend_long buffered_query_limit;
|
||||
|
||||
#ifndef _WIN32
|
||||
zend_long set_locale_info;
|
||||
#endif
|
||||
|
||||
ZEND_END_MODULE_GLOBALS(sqlsrv)
|
||||
|
||||
ZEND_EXTERN_MODULE_GLOBALS(sqlsrv);
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
#define INI_BUFFERED_QUERY_LIMIT "ClientBufferMaxKBSize"
|
||||
#define INI_PREFIX "sqlsrv."
|
||||
|
||||
#ifndef _WIN32
|
||||
#define INI_SET_LOCALE_INFO "SetLocaleInfo"
|
||||
#endif
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
STD_PHP_INI_BOOLEAN( INI_PREFIX INI_WARNINGS_RETURN_AS_ERRORS , "1", PHP_INI_ALL, OnUpdateBool, warnings_return_as_errors,
|
||||
zend_sqlsrv_globals, sqlsrv_globals )
|
||||
|
@ -46,6 +50,11 @@ PHP_INI_BEGIN()
|
|||
sqlsrv_globals )
|
||||
STD_PHP_INI_ENTRY( INI_PREFIX INI_BUFFERED_QUERY_LIMIT, INI_BUFFERED_QUERY_LIMIT_DEFAULT, PHP_INI_ALL, OnUpdateLong, buffered_query_limit,
|
||||
zend_sqlsrv_globals, sqlsrv_globals )
|
||||
#ifndef _WIN32
|
||||
STD_PHP_INI_ENTRY(INI_PREFIX INI_SET_LOCALE_INFO, "2", PHP_INI_ALL, OnUpdateLong, set_locale_info,
|
||||
zend_sqlsrv_globals, sqlsrv_globals)
|
||||
#endif
|
||||
|
||||
PHP_INI_END()
|
||||
|
||||
|
||||
|
|
103
test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt
Normal file
103
test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt
Normal file
|
@ -0,0 +1,103 @@
|
|||
--TEST--
|
||||
GitHub issue 1063 - make setting locale info configurable
|
||||
--DESCRIPTION--
|
||||
This test verifies that the users can configure using ini file to set application locale using the system locale or not. This test is valid for Linux and macOS systems only.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix_locales.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
function runTest($val, $file, $locale)
|
||||
{
|
||||
print("\n***sqlsrv.SetLocaleInfo = $val\npdo_sqlsrv.set_locale_info = $val***\n\n");
|
||||
shell_exec("echo 'sqlsrv.SetLocaleInfo = $val\npdo_sqlsrv.set_locale_info = $val' > $file");
|
||||
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/pdo_1063_test_locale.php "));
|
||||
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/pdo_1063_test_locale.php $locale"));
|
||||
}
|
||||
|
||||
$inifile = PHP_CONFIG_FILE_SCAN_DIR."/99-overrides.ini";
|
||||
|
||||
$locale1 = strtoupper(PHP_OS) === 'LINUX' ? "en_US.ISO-8859-1" : "en_US.ISO8859-1";
|
||||
$locale2 = 'de_DE.UTF-8';
|
||||
|
||||
runTest(0, $inifile, $locale1);
|
||||
runTest(1, $inifile, $locale2);
|
||||
runTest(2, $inifile, $locale2);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
***sqlsrv.SetLocaleInfo = 0
|
||||
pdo_sqlsrv.set_locale_info = 0***
|
||||
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Currency symbol:
|
||||
Thousands_sep:
|
||||
Amount formatted: 10000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Setting LC_ALL: en_US.ISO-8859-1
|
||||
Currency symbol: $
|
||||
Thousands_sep: ,
|
||||
Amount formatted: USD 10,000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
|
||||
***sqlsrv.SetLocaleInfo = 1
|
||||
pdo_sqlsrv.set_locale_info = 1***
|
||||
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Currency symbol:
|
||||
Thousands_sep:
|
||||
Amount formatted: 10000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Setting LC_ALL: de_DE.UTF-8
|
||||
Currency symbol: €
|
||||
Thousands_sep: .
|
||||
Amount formatted: 10.000,99 EUR
|
||||
Freitag
|
||||
Dezember
|
||||
3,14159
|
||||
**End**
|
||||
|
||||
***sqlsrv.SetLocaleInfo = 2
|
||||
pdo_sqlsrv.set_locale_info = 2***
|
||||
|
||||
**Begin**
|
||||
Current LC_MONETARY: en_US.UTF-8
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Currency symbol: $
|
||||
Thousands_sep: ,
|
||||
Amount formatted: USD 10,000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
**Begin**
|
||||
Current LC_MONETARY: en_US.UTF-8
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Setting LC_ALL: de_DE.UTF-8
|
||||
Currency symbol: €
|
||||
Thousands_sep: .
|
||||
Amount formatted: 10.000,99 EUR
|
||||
Freitag
|
||||
Dezember
|
||||
3,14159
|
||||
**End**
|
61
test/functional/pdo_sqlsrv/pdo_1063_test_locale.php
Normal file
61
test/functional/pdo_sqlsrv/pdo_1063_test_locale.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
function dropTable($conn, $tableName)
|
||||
{
|
||||
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName";
|
||||
$conn->exec($tsql);
|
||||
}
|
||||
|
||||
|
||||
// This test is invoked by pdo_1063_locale_configs.phpt
|
||||
require_once('MsSetup.inc');
|
||||
|
||||
$locale = ($_SERVER['argv'][1] ?? '');
|
||||
|
||||
echo "**Begin**" . PHP_EOL;
|
||||
echo "Current LC_MONETARY: " . setlocale(LC_MONETARY, 0) . PHP_EOL;
|
||||
echo "Current LC_CTYPE: " . setlocale(LC_CTYPE, 0) . PHP_EOL;
|
||||
|
||||
if (!empty($locale)) {
|
||||
$loc = setlocale(LC_ALL, $locale);
|
||||
echo "Setting LC_ALL: " . $loc . PHP_EOL;
|
||||
}
|
||||
|
||||
$info = localeconv();
|
||||
echo "Currency symbol: " . $info['currency_symbol'] . PHP_EOL;
|
||||
echo "Thousands_sep: " . $info['thousands_sep'] . PHP_EOL;
|
||||
|
||||
$n1 = 10000.98765;
|
||||
echo "Amount formatted: " . money_format("%i", $n1) . PHP_EOL;
|
||||
echo strftime("%A", strtotime("12/25/2020")) . PHP_EOL;
|
||||
echo strftime("%B", strtotime("12/25/2020")) . PHP_EOL;
|
||||
|
||||
try {
|
||||
$conn = new PDO("sqlsrv:server = $server; database=$databaseName; driver=$driver", $uid, $pwd );
|
||||
|
||||
$tableName = "[" . "pdo1063" . $locale . "]";
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
$pi = "3.14159";
|
||||
|
||||
$stmt = $conn->query("CREATE TABLE $tableName (c1 FLOAT)");
|
||||
$stmt = $conn->query("INSERT INTO $tableName (c1) VALUES ($pi)");
|
||||
|
||||
$sql = "SELECT c1 FROM $tableName";
|
||||
$stmt = $conn->prepare($sql, array(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true));
|
||||
$stmt->execute();
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_NUM);
|
||||
echo ($row[0]) . PHP_EOL;
|
||||
unset($stmt);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
unset($conn);
|
||||
} catch( PDOException $e ) {
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
echo "**End**" . PHP_EOL;
|
||||
?>
|
29
test/functional/pdo_sqlsrv/skipif_unix_locales.inc
Normal file
29
test/functional/pdo_sqlsrv/skipif_unix_locales.inc
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
die("Skipped: Test for Linux and macOS");
|
||||
}
|
||||
|
||||
if (!extension_loaded("sqlsrv")) {
|
||||
die("skip extension not loaded");
|
||||
}
|
||||
|
||||
// check if the required ini file exists
|
||||
$inifile = PHP_CONFIG_FILE_SCAN_DIR."/99-overrides.ini";
|
||||
if (!file_exists($inifile)) {
|
||||
die("required ini file not exists");
|
||||
}
|
||||
|
||||
// if the file exists, is it writable? '@' sign is used to suppress warnings
|
||||
$file = @fopen($inifile, "w");
|
||||
if (!$file) {
|
||||
die("required ini file not writable");
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
|
||||
$loc = setlocale(LC_TIME, 'de_DE.UTF-8');
|
||||
if (empty($loc)) {
|
||||
die("required locale not available");
|
||||
}
|
||||
?>
|
|
@ -7,9 +7,6 @@ Validates that a prepared statement can be successfully executed more than once.
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -7,9 +7,6 @@ retrieving fields from a table including rows with all supported SQL types (28 t
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -4,9 +4,6 @@ Fetch Field Data Test verifies the data retrieved via sqlsrv_get_field
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -7,9 +7,6 @@ by checking all fetch type modes.
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -6,9 +6,6 @@ Verifies data retrieval via "sqlsrv_fetch_object".
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -6,9 +6,6 @@ Verifies the functionality of "sqlsrv_next_result"
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -6,9 +6,6 @@ Verifies data retrieval with scrollable result sets.
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -7,9 +7,6 @@ can be successfully retrieved as streams.
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
|
@ -6,9 +6,6 @@ Verifies the streaming behavior with scrollable resultsets.
|
|||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif_versions_old.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
29
test/functional/sqlsrv/skipif_unix_locales.inc
Normal file
29
test/functional/sqlsrv/skipif_unix_locales.inc
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
die("Skipped: Test for Linux and macOS");
|
||||
}
|
||||
|
||||
if (!extension_loaded("sqlsrv")) {
|
||||
die("skip extension not loaded");
|
||||
}
|
||||
|
||||
// check if the required ini file exists
|
||||
$inifile = PHP_CONFIG_FILE_SCAN_DIR."/99-overrides.ini";
|
||||
if (!file_exists($inifile)) {
|
||||
die("required ini file not exists");
|
||||
}
|
||||
|
||||
// if the file exists, is it writable? '@' sign is used to suppress warnings
|
||||
$file = @fopen($inifile, "w");
|
||||
if (!$file) {
|
||||
die("required ini file not writable");
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
|
||||
$loc = setlocale(LC_TIME, 'de_DE.UTF-8');
|
||||
if (empty($loc)) {
|
||||
die("required locale not available");
|
||||
}
|
||||
?>
|
103
test/functional/sqlsrv/srv_1063_locale_configs.phpt
Normal file
103
test/functional/sqlsrv/srv_1063_locale_configs.phpt
Normal file
|
@ -0,0 +1,103 @@
|
|||
--TEST--
|
||||
GitHub issue 1063 - make setting locale info configurable
|
||||
--DESCRIPTION--
|
||||
This test verifies that the users can configure using ini file to set application locale using the system locale or not. This test is valid for Linux and macOS systems only.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix_locales.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
function runTest($val, $file, $locale)
|
||||
{
|
||||
print("\n***sqlsrv.SetLocaleInfo = $val\npdo_sqlsrv.set_locale_info = $val***\n\n");
|
||||
shell_exec("echo 'sqlsrv.SetLocaleInfo = $val\npdo_sqlsrv.set_locale_info = $val' > $file");
|
||||
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/srv_1063_test_locale.php "));
|
||||
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/srv_1063_test_locale.php $locale"));
|
||||
}
|
||||
|
||||
$inifile = PHP_CONFIG_FILE_SCAN_DIR."/99-overrides.ini";
|
||||
|
||||
$locale1 = strtoupper(PHP_OS) === 'LINUX' ? "en_US.ISO-8859-1" : "en_US.ISO8859-1";
|
||||
$locale2 = 'de_DE.UTF-8';
|
||||
|
||||
runTest(0, $inifile, $locale1);
|
||||
runTest(1, $inifile, $locale2);
|
||||
runTest(2, $inifile, $locale2);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
***sqlsrv.SetLocaleInfo = 0
|
||||
pdo_sqlsrv.set_locale_info = 0***
|
||||
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Currency symbol:
|
||||
Thousands_sep:
|
||||
Amount formatted: 10000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Setting LC_ALL: en_US.ISO-8859-1
|
||||
Currency symbol: $
|
||||
Thousands_sep: ,
|
||||
Amount formatted: USD 10,000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
|
||||
***sqlsrv.SetLocaleInfo = 1
|
||||
pdo_sqlsrv.set_locale_info = 1***
|
||||
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Currency symbol:
|
||||
Thousands_sep:
|
||||
Amount formatted: 10000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
**Begin**
|
||||
Current LC_MONETARY: C
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Setting LC_ALL: de_DE.UTF-8
|
||||
Currency symbol: €
|
||||
Thousands_sep: .
|
||||
Amount formatted: 10.000,99 EUR
|
||||
Freitag
|
||||
Dezember
|
||||
3,14159
|
||||
**End**
|
||||
|
||||
***sqlsrv.SetLocaleInfo = 2
|
||||
pdo_sqlsrv.set_locale_info = 2***
|
||||
|
||||
**Begin**
|
||||
Current LC_MONETARY: en_US.UTF-8
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Currency symbol: $
|
||||
Thousands_sep: ,
|
||||
Amount formatted: USD 10,000.99
|
||||
Friday
|
||||
December
|
||||
3.14159
|
||||
**End**
|
||||
**Begin**
|
||||
Current LC_MONETARY: en_US.UTF-8
|
||||
Current LC_CTYPE: en_US.UTF-8
|
||||
Setting LC_ALL: de_DE.UTF-8
|
||||
Currency symbol: €
|
||||
Thousands_sep: .
|
||||
Amount formatted: 10.000,99 EUR
|
||||
Freitag
|
||||
Dezember
|
||||
3,14159
|
||||
**End**
|
75
test/functional/sqlsrv/srv_1063_test_locale.php
Normal file
75
test/functional/sqlsrv/srv_1063_test_locale.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
function dropTable($conn, $tableName)
|
||||
{
|
||||
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName";
|
||||
sqlsrv_query($conn, $tsql);
|
||||
}
|
||||
|
||||
function fatalError($message)
|
||||
{
|
||||
var_dump(sqlsrv_errors(SQLSRV_ERR_ALL));
|
||||
die($message);
|
||||
}
|
||||
|
||||
// This test is invoked by srv_1063_locale_configs.phpt
|
||||
require_once('MsSetup.inc');
|
||||
|
||||
$locale = ($_SERVER['argv'][1] ?? '');
|
||||
|
||||
echo "**Begin**" . PHP_EOL;
|
||||
echo "Current LC_MONETARY: " . setlocale(LC_MONETARY, 0) . PHP_EOL;
|
||||
echo "Current LC_CTYPE: " . setlocale(LC_CTYPE, 0) . PHP_EOL;
|
||||
|
||||
if (!empty($locale)) {
|
||||
$loc = setlocale(LC_ALL, $locale);
|
||||
echo "Setting LC_ALL: " . $loc . PHP_EOL;
|
||||
}
|
||||
|
||||
$info = localeconv();
|
||||
echo "Currency symbol: " . $info['currency_symbol'] . PHP_EOL;
|
||||
echo "Thousands_sep: " . $info['thousands_sep'] . PHP_EOL;
|
||||
|
||||
$n1 = 10000.98765;
|
||||
echo "Amount formatted: " . money_format("%i", $n1) . PHP_EOL;
|
||||
echo strftime("%A", strtotime("12/25/2020")) . PHP_EOL;
|
||||
echo strftime("%B", strtotime("12/25/2020")) . PHP_EOL;
|
||||
|
||||
$conn = sqlsrv_connect($server, $connectionOptions);
|
||||
if (!$conn) {
|
||||
fatalError("Failed to connect to $server.");
|
||||
}
|
||||
|
||||
$tableName = "[" . "srv1063" . $locale . "]";
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
$pi = "3.14159";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName (c1 FLOAT)");
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to create test table $tableName");
|
||||
}
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1) VALUES ($pi)");
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to insert into test table $tableName");
|
||||
}
|
||||
|
||||
$sql = "SELECT c1 FROM $tableName";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
if (!$stmt) {
|
||||
fatalError("Failed in running query $sql");
|
||||
}
|
||||
|
||||
while (sqlsrv_fetch($stmt)) {
|
||||
$value = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_FLOAT);
|
||||
echo $value . PHP_EOL;
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
|
||||
echo "**End**" . PHP_EOL;
|
||||
?>
|
|
@ -2,9 +2,6 @@
|
|||
streaming large amounts of data into a database and getting it out as a string exactly the same.
|
||||
--SKIPIF--
|
||||
<?
|
||||
require_once('MsCommon.inc');
|
||||
// locale must be set before 1st connection
|
||||
setUSAnsiLocale();
|
||||
require('skipif.inc');
|
||||
?>
|
||||
--FILE--
|
||||
|
|
Loading…
Reference in a new issue