Enable ODBC and MS SQL ODBC support (#4676)

Closes #4356.
This commit is contained in:
Arik Fraimovich
2020-02-23 11:57:39 +02:00
committed by GitHub
parent dd8e23040a
commit f1a2f8cb88
5 changed files with 34 additions and 12 deletions

View File

@@ -30,6 +30,8 @@ RUN apt-get update && \
wget \
# Postgres client
libpq-dev \
# ODBC support:
g++ unixodbc-dev \
# for SAML
xmlsec1 \
# Additional packages required for data sources:
@@ -37,6 +39,11 @@ RUN apt-get update && \
default-libmysqlclient-dev \
freetds-dev \
libsasl2-dev && \
# MSSQL ODBC Driver:
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install -y msodbcsql17 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -25,24 +25,31 @@ class SQLServerODBC(BaseSQLQueryRunner):
return {
"type": "object",
"properties": {
"server": {"type": "string"},
"port": {"type": "number", "default": 1433},
"user": {"type": "string"},
"password": {"type": "string"},
"server": {"type": "string", "default": "127.0.0.1"},
"port": {"type": "number", "default": 1433},
"db": {"type": "string", "title": "Database Name"},
"charset": {
"type": "string",
"default": "UTF-8",
"title": "Character Set",
},
"db": {"type": "string", "title": "Database Name"},
"driver": {
"type": "string",
"title": "Driver Identifier",
"default": "{ODBC Driver 13 for SQL Server}",
"use_ssl": {
"type": "boolean",
"title": "Use SSL",
"default": False,
},
"verify_ssl": {
"type": "boolean",
"title": "Verify SSL certificate",
"default": True,
},
},
"required": ["db"],
"order": ["server", "port", "user", "password", "db", "charset", "use_ssl", "verify_ssl"],
"required": ["host", "user", "password", "db"],
"secret": ["password"],
"extra_options": ["verify_ssl", "use_ssl"],
}
@classmethod
@@ -91,20 +98,26 @@ class SQLServerODBC(BaseSQLQueryRunner):
connection = None
try:
server = self.configuration.get("server", "")
server = self.configuration.get("server")
user = self.configuration.get("user", "")
password = self.configuration.get("password", "")
db = self.configuration["db"]
port = self.configuration.get("port", 1433)
charset = self.configuration.get("charset", "UTF-8")
driver = self.configuration.get("driver", "{ODBC Driver 13 for SQL Server}")
connection_string_fmt = (
"DRIVER={};PORT={};SERVER={};DATABASE={};UID={};PWD={}"
"DRIVER={{ODBC Driver 17 for SQL Server}};PORT={};SERVER={};DATABASE={};UID={};PWD={}"
)
connection_string = connection_string_fmt.format(
driver, port, server, db, user, password
port, server, db, user, password
)
if self.configuration.get('use_ssl', False):
connection_string += ";Encrypt=YES"
if not self.configuration.get('verify_ssl'):
connection_string += ";TrustServerCertificate=YES"
connection = pyodbc.connect(connection_string)
cursor = connection.cursor()
logger.debug("SQLServerODBC running query: %s", query)

View File

@@ -332,6 +332,7 @@ default_query_runners = [
"redash.query_runner.sqlite",
"redash.query_runner.dynamodb_sql",
"redash.query_runner.mssql",
"redash.query_runner.mssql_odbc",
"redash.query_runner.memsql_ds",
"redash.query_runner.mapd",
"redash.query_runner.jql",

View File

@@ -34,3 +34,4 @@ pydgraph==2.0.2
azure-kusto-data==0.0.35
pyexasol==0.9.1
python-rapidjson==0.8.0
pyodbc==4.0.28