Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More locale cases #1115

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile-msphpsql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/shared/localization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ inline UINT SystemLocale::MaxCharCchSize( UINT codepage )
switch ( codepage )
{
case CP_UTF8:
case 54936:
return 4;
case 932:
case 936:
Expand Down
6 changes: 6 additions & 0 deletions source/shared/localizationimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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),
Expand Down
79 changes: 79 additions & 0 deletions test/functional/pdo_sqlsrv/pdo_ansi_locale_fr.phpt
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions test/functional/pdo_sqlsrv/skipif_unix_ansitests.inc
Original file line number Diff line number Diff line change
@@ -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");
}

?>
16 changes: 16 additions & 0 deletions test/functional/sqlsrv/skipif_unix_ansitests.inc
Original file line number Diff line number Diff line change
@@ -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");
}

?>
93 changes: 93 additions & 0 deletions test/functional/sqlsrv/sqlsrv_ansi_locale_fr.phpt
Original file line number Diff line number Diff line change
@@ -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