Merge pull request #265 from mlocati/sqlsrv

Install Microsoft ODBC Drivers when using sqlsrv / pdo_sqlsrv
pull/268/head
Michele Locati 2021-01-20 14:48:50 +01:00 committed by GitHub
commit 3ab860ad2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 10 deletions

View File

@ -1,4 +1,6 @@
enchant !7.2-alpine3.12 !7.3-alpine3.12 !7.4-alpine3.12
parallel zts
pdo_sqlsrv !7.0-alpine3.7 !7.1-alpine3.7 !7.1-alpine3.8 !7.2-alpine3.7 !7.2-alpine3.8 !7.3-alpine3.8
pthreads zts
sqlsrv !7.0-alpine3.7 !7.1-alpine3.7 !7.1-alpine3.8 !7.1-alpine3.9 !7.1-alpine3.10 !7.2-alpine3.7 !7.2-alpine3.8 !7.3-alpine3.8
tdlib !alpine3.7 !jessie

View File

@ -667,14 +667,6 @@ buildRequiredPackageLists() {
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libpq5"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libpq-dev"
;;
pdo_sqlsrv@alpine)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libstdc++ unixodbc"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev"
;;
pdo_sqlsrv@debian)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libodbc1 odbcinst"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev"
;;
pgsql@alpine)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent postgresql-libs"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile postgresql-dev"
@ -772,13 +764,16 @@ buildRequiredPackageLists() {
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libcurl3-gnutls"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile libcurl4-gnutls-dev libxml2-dev"
;;
sqlsrv@alpine)
sqlsrv@alpine | pdo_sqlsrv@alpine)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libstdc++ unixodbc"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev"
;;
sqlsrv@debian)
sqlsrv@debian | pdo_sqlsrv@debian)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent unixodbc"
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile unixodbc-dev"
if ! isMicrosoftSqlServerODBCInstalled; then
buildRequiredPackageLists_volatile="$buildRequiredPackageLists_volatile gnupg apt-transport-https"
fi
;;
ssh2@alpine)
buildRequiredPackageLists_persistent="$buildRequiredPackageLists_persistent libssh2"
@ -1170,6 +1165,41 @@ installOracleInstantClient() {
esac
}
# Check if the Microsoft SQL Server ODBC Driver is installed
#
# Return:
# 0 (true): if the string is in the list
# 1 (false): if the string is not in the list
isMicrosoftSqlServerODBCInstalled() {
test -d /opt/microsoft/msodbcsql*/
}
# Install the Microsoft SQL Server ODBC Driver
installMicrosoftSqlServerODBC() {
printf 'Installing the Microsoft SQL Server ODBC Driver\n'
case "$DISTRO" in
alpine)
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#alpine17
rm -rf /tmp/src/msodbcsql.apk
curl -sSLf -o /tmp/src/msodbcsql.apk https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_17.6.1.1-1_amd64.apk
printf '\n' | apk add --allow-untrusted /tmp/src/msodbcsql.apk
rm -rf /tmp/src/msodbcsql.apk
;;
debian)
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server#debian17
printf -- '- installing the Microsoft APT key\n'
curl -sSLf https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
if ! test -f /etc/apt/sources.list.d/mssql-release.list; then
printf -- '- adding the Microsoft APT source list\n'
curl -sSLf https://packages.microsoft.com/config/debian/$DISTRO_VERSION_NUMBER/prod.list >/etc/apt/sources.list.d/mssql-release.list
DEBIAN_FRONTEND=noninteractive apt-get -q update
fi
printf -- '- installing the APT package\n'
DEBIAN_FRONTEND=noninteractive ACCEPT_EULA=Y apt-get -qy install '^msodbcsql[0-9]+$'
;;
esac
}
# Install Composer
installComposer() {
installComposer_version="$(getWantedPHPModuleVersion @composer)"
@ -1681,6 +1711,9 @@ installRemoteModule() {
installRemoteModule_version=5.8.1
fi
fi
if ! isMicrosoftSqlServerODBCInstalled; then
installMicrosoftSqlServerODBC
fi
;;
propro)
if test -z "$installRemoteModule_version"; then

28
scripts/tests/pdo_sqlsrv Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env php
<?php
error_reporting(-1);
set_error_handler(
static function ($errno, $errstr, $errfile, $errline) {
$msg = "Error {$errno}: {$errstr}\n";
if ($errfile) {
$msg .= "File: {$errfile}\n";
if ($errline) {
$msg .= "Line: {$errline}\n";
}
}
fwrite(STDERR, $msg);
exit(1);
},
-1
);
try {
new PDO('sqlsrv:server=localhost; Authentication=SqlPassword; ConnectRetryCount=0; Database=example; LoginTimeout=1', 'userName', 'password');
} catch (PDOException $x) {
if (stripos($x->getMessage(), 'This extension requires the Microsoft ODBC Driver for SQL Server') !== false) {
fwrite(STDERR, trim($x->getMessage() . "\n"));
exit(1);
}
}

39
scripts/tests/sqlsrv Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php
error_reporting(-1);
set_error_handler(
static function ($errno, $errstr, $errfile, $errline) {
$msg = "Error {$errno}: {$errstr}\n";
if ($errfile) {
$msg .= "File: {$errfile}\n";
if ($errline) {
$msg .= "Line: {$errline}\n";
}
}
fwrite(STDERR, $msg);
exit(1);
},
-1
);
sqlsrv_connect(
'localhost, 50000',
[
'Authentication' => 'SqlPassword',
'ConnectRetryCount' => 0,
'Database' => 'example',
'LoginTimeout' => 1, // string for PDO_SQLSRV
'UID' => 'userName', // not for PDO_SQLSRV
'PWD' => 'password',
]
);
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
if (is_array($errors)) {
foreach ($errors as $error) {
if (isset($error['message']) && stripos($error['message'], 'This extension requires the Microsoft ODBC Driver for SQL Server') !== false) {
fwrite(STDERR, trim($error['message']) . "\n");
}
}
}