More locale cases (#1115)

This commit is contained in:
Jenny Tam 2020-04-16 15:29:37 -07:00 committed by GitHub
parent d4c112e9af
commit 92f9810edd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 213 additions and 0 deletions

View file

@ -42,6 +42,7 @@ ENV PATH="/opt/mssql-tools/bin:${PATH}"
# add locales for testing
RUN sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
RUN sed -i 's/# fr_FR@euro ISO-8859-15/fr_FR@euro ISO-8859-15/g' /etc/locale.gen
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

View file

@ -111,6 +111,7 @@ jobs:
- script: |
sudo sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
sudo sed -i 's/# fr_FR@euro ISO-8859-15/fr_FR@euro ISO-8859-15/g' /etc/locale.gen
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

View file

@ -247,6 +247,7 @@ inline UINT SystemLocale::MaxCharCchSize( UINT codepage )
switch ( codepage )
{
case CP_UTF8:
case 54936:
return 4;
case 932:
case 936:

View file

@ -77,6 +77,7 @@ const cp_iconv cp_iconv::g_cp_iconv[] = {
{ 1256, "CP1256" TRANSLIT },
{ 1257, "CP1257" TRANSLIT },
{ 1258, "CP1258" TRANSLIT },
{ 54936, "GB18030" TRANSLIT},
{ CP_ISO8859_1, "ISO8859-1" TRANSLIT },
{ CP_ISO8859_2, "ISO8859-2" TRANSLIT },
{ CP_ISO8859_3, "ISO8859-3" TRANSLIT },
@ -342,6 +343,11 @@ SystemLocale::SystemLocale( const char * localeName )
const LocaleCP lcpTable[] = {
{ "utf8", CP_UTF8 },
{ "UTF-8", CP_UTF8 },
{ "BIG5", 950 },
{ "BIG5-HKSCS", 950 },
{ "gb18030", 54936 },
{ "gb2312", 936 },
{ "gbk", 936 },
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),

View file

@ -0,0 +1,79 @@
--TEST--
Test another ANSI encoding fr_FR euro locale outside Windows
--DESCRIPTION--
This file must be saved in ANSI encoding and the required locale must be present
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_unix_ansitests.inc'); ?>
--FILE--
<?php
function insertData($conn, $tableName, $inputs)
{
try {
$tsql = "INSERT INTO $tableName (id, phrase) VALUES (?, ?)";
$stmt = $conn->prepare($tsql);
for ($i = 0; $i < count($inputs); $i++) {
$stmt->execute(array($i, $inputs[$i]));
}
} catch( PDOException $e ) {
echo "Failed to insert data\n";
print_r( $e->getMessage() );
}
}
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);
}
require_once('MsSetup.inc');
try {
$locale = 'fr_FR@euro';
setlocale(LC_ALL, $locale);
$conn = new PDO("sqlsrv:server = $server; database=$databaseName; driver=$driver", $uid, $pwd);
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
$tableName = "pdo_ansitest_FR";
dropTable($conn, $tableName);
$tsql = "CREATE TABLE $tableName([id] [int] NOT NULL, [phrase] [varchar](50) NULL)";
$conn->exec($tsql);
$inputs = array("À tout à l'heure!",
"Je suis désolé.",
"À plus!",
" Je dois aller à l'école.");
// Next, insert the strings
insertData($conn, $tableName, $inputs);
// Next, fetch the strings
$tsql = "SELECT phrase FROM $tableName ORDER by id";
$stmt = $conn->query($tsql);
$results = $stmt->fetchAll(PDO::FETCH_NUM);
for ($i = 0; $i < count($inputs); $i++) {
if ($results[$i][0] !== $inputs[$i]) {
echo "Unexpected phrase retrieved:\n";
var_dump($results[$i][0]);
}
}
dropTable($conn, $tableName);
unset($stmt);
unset($conn);
} catch (PDOException $e) {
print_r($e->getMessage());
}
echo "Done" . PHP_EOL;
?>
--EXPECT--
Done

View file

@ -0,0 +1,16 @@
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
die("skip Test for Linux and macOS");
}
if (!extension_loaded("pdo_sqlsrv")) {
die("skip Extension not loaded");
}
$loc = setlocale(LC_ALL, 'fr_FR@euro');
if (empty($loc)) {
die("skip required French locale not available");
}
?>

View file

@ -0,0 +1,16 @@
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
die("skip: Test for Linux and macOS");
}
if (!extension_loaded("sqlsrv")) {
die("skip extension not loaded");
}
$loc = setlocale(LC_ALL, 'fr_FR@euro');
if (empty($loc)) {
die("skip required French locale not available");
}
?>

View file

@ -0,0 +1,93 @@
--TEST--
Test another ansi encoding fr_FR euro locale outside Windows
--DESCRIPTION--
This file must be saved in ANSI encoding and the required locale must be present
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_unix_ansitests.inc'); ?>
--FILE--
<?php
function insertData($conn, $tableName, $inputs)
{
$tsql = "INSERT INTO $tableName (id, phrase) VALUES (?, ?)";
$param1 = null;
$param2 = null;
$params = array(&$param1, &$param2);
$stmt = sqlsrv_prepare($conn, $tsql, $params);
if ($stmt === false) {
echo "Failed to prepare the insert statement\n";
die(print_r(sqlsrv_errors(), true));
}
for ($i = 0; $i < count($inputs); $i++) {
$param1 = $i;
$param2 = $inputs[$i];
if (!sqlsrv_execute($stmt)) {
echo "Statement could not be executed.\n";
die(print_r(sqlsrv_errors(), true));
}
}
}
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);
}
require_once('MsSetup.inc');
$tableName = "srv_ansitest_FR";
$locale = 'fr_FR@euro';
setlocale(LC_ALL, $locale);
$conn = sqlsrv_connect($server, $connectionOptions);
if( $conn === false ) {
echo "Failed to connect\n";
die(print_r(sqlsrv_errors(), true));
}
dropTable($conn, $tableName);
$tsql = "CREATE TABLE $tableName([id] [int] NOT NULL, [phrase] [varchar](50) NULL)";
$stmt = sqlsrv_query($conn, $tsql);
$inputs = array("À tout à l'heure!",
"Je suis désolé.",
"À plus!",
" Je dois aller à l'école.");
// Next, insert the strings
insertData($conn, $tableName, $inputs);
// Next, fetch the strings
$tsql = "SELECT phrase FROM $tableName ORDER by id";
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
echo "Failed to run select query\n";
die(print_r(sqlsrv_errors(), true));
}
$i = 0;
while (sqlsrv_fetch($stmt)) {
$phrase = sqlsrv_get_field($stmt, 0);
if ($phrase != $inputs[$i++]) {
echo "Unexpected phrase retrieved:\n";
var_dump($phrase);
}
}
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Done" . PHP_EOL;
?>
--EXPECT--
Done