Skip to content

Commit

Permalink
mssql-odbc-arm64 (getredash#6924)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Lee <[email protected]>
  • Loading branch information
2 people authored and harveyrendell committed Jan 8, 2025
1 parent d6afd80 commit 860b843
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN \
curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \
apt update && \
ACCEPT_EULA=Y apt install -y --no-install-recommends msodbcsql18 && \
apt clean && \
rm -rf /var/lib/apt/lists/*

ARG TARGETPLATFORM
ARG databricks_odbc_driver_url=https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/odbc/2.6.26/SimbaSparkODBC-2.6.26.1045-Debian-64bit.zip
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \
&& curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y --no-install-recommends msodbcsql17 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& curl "$databricks_odbc_driver_url" --location --output /tmp/simba_odbc.zip \
curl "$databricks_odbc_driver_url" --location --output /tmp/simba_odbc.zip \
&& chmod 600 /tmp/simba_odbc.zip \
&& unzip /tmp/simba_odbc.zip -d /tmp/simba \
&& dpkg -i /tmp/simba/*.deb \
Expand Down
25 changes: 20 additions & 5 deletions redash/query_runner/mssql_odbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def configuration_schema(cls):
"verify_ssl": {
"type": "boolean",
"title": "Verify SSL certificate",
"default": True,
"default": False,
},
},
"order": [
Expand Down Expand Up @@ -123,14 +123,29 @@ def run_query(self, query, user):
db = self.configuration["db"]
port = self.configuration.get("port", 1433)

connection_string_fmt = "DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={},{};DATABASE={};UID={};PWD={}"
connection_string = connection_string_fmt.format(server, port, db, user, password)
connection_params = {
"Driver": "{ODBC Driver 18 for SQL Server}",
"Server": server,
"Port": port,
"Database": db,
"Uid": user,
"Pwd": password,
}

if self.configuration.get("use_ssl", False):
connection_string += ";Encrypt=YES"
connection_params["Encrypt"] = "YES"

if not self.configuration.get("verify_ssl"):
connection_string += ";TrustServerCertificate=YES"
connection_params["TrustServerCertificate"] = "YES"
else:
connection_params["TrustServerCertificate"] = "NO"
else:
connection_params["Encrypt"] = "NO"

def fn(k):
return "{}={}".format(k, connection_params[k])

connection_string = ";".join(list(map(fn, connection_params)))

connection = pyodbc.connect(connection_string)
cursor = connection.cursor()
Expand Down

0 comments on commit 860b843

Please sign in to comment.