Skip to content

Commit 22ea5f4

Browse files
committed
updated mssql-proxy to automatically find odbc driver
enabled mac download button cleaned up CIs
1 parent 5e46f7a commit 22ea5f4

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

.github/workflows/build-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
- uses: actions/setup-python@v5
1818
with:
1919
python-version: 3.11.4
20-
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
2120
- run: ./Tools/mssql-proxy/odbc-driver-installer.sh
21+
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
2222
- run: pyinstaller mssql-proxy.linux.spec
2323
working-directory: Tools/mssql-proxy
2424
- id: name

.github/workflows/build-macos.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ jobs:
1717
run: |
1818
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
1919
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
20-
HOMEBREW_SANDBOX=1 HOMEBREW_ACCEPT_EULA=Y brew install unixodbc msodbcsql18 tree
21-
tree /opt/homebrew/Cellar/msodbcsql18/
22-
cat /opt/homebrew/Cellar/msodbcsql18/18.4.1.1/odbcinst.ini
20+
HOMEBREW_SANDBOX=1 HOMEBREW_ACCEPT_EULA=Y brew install unixodbc msodbcsql18
2321
2422
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
2523
- run: pyinstaller mssql-proxy.mac.spec

.github/workflows/build-release.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ jobs:
1717
uses: ./.github/workflows/publish.yml
1818
if: github.ref_type == 'tag'
1919

20-
# build-linux:
21-
# uses: ./.github/workflows/build-linux.yml
20+
build-linux:
21+
uses: ./.github/workflows/build-linux.yml
2222

23-
# build-windows:
24-
# uses: ./.github/workflows/build-windows.yml
23+
build-windows:
24+
uses: ./.github/workflows/build-windows.yml
2525

2626
build-macos:
2727
uses: ./.github/workflows/build-macos.yml
2828

29-
# build-publish-docker:
30-
# uses: ./.github/workflows/build-publish-docker.yml
31-
# needs: [publish, build-linux, build-windows, build-macos]
29+
build-publish-docker:
30+
uses: ./.github/workflows/build-publish-docker.yml
31+
needs: [publish, build-linux, build-windows, build-macos]
3232

3333
release:
3434
runs-on: ubuntu-latest
3535
if: github.ref_type == 'tag'
36-
# needs: [build-publish-docker]
36+
needs: [build-publish-docker]
3737
steps:
3838
- name: Checkout
3939
uses: actions/checkout@v4

Frontend/src/app/downloads/downloads.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h2 class="bi bi-database"> MSSQl proxy server</h2>
1414
<a role="button" class="bi bi-windows btn btn-success text-no-wrap" href="https://github.com/IPdotSetAF/CodeChef/releases/download/{{version}}/mssql-proxy-{{version}}-windows.zip"> Windows</a>
1515
<a role="button" class="bi bi-ubuntu btn btn-success text-no-wrap" href="https://github.com/IPdotSetAF/CodeChef/releases/download/{{version}}/mssql-proxy-{{version}}-linux-amd64.tar.gz"> Linux - AMD64</a>
1616
<a role="button" class="bi bi-ubuntu btn btn-success text-no-wrap" href="https://github.com/IPdotSetAF/CodeChef/releases/download/{{version}}/mssql-proxy-{{version}}-linux-arm64.tar.gz"> Linux - ARM64</a>
17-
<a role="button" class="bi bi-apple btn btn-success text-no-wrap disabled" href="https://github.com/IPdotSetAF/CodeChef/releases/download/{{version}}/mssql-proxy-{{version}}-macos.tar.gz"> Mac OS</a>
17+
<a role="button" class="bi bi-apple btn btn-success text-no-wrap" href="https://github.com/IPdotSetAF/CodeChef/releases/download/{{version}}/mssql-proxy-{{version}}-macos.tar.gz"> Mac OS</a>
1818
<a role="button" class="bi bi-filetype-py btn btn-success text-no-wrap" href="https://github.com/IPdotSetAF/CodeChef/releases/download/{{version}}/mssql-proxy-{{version}}-source.tar.gz"> Python Source Code</a>
1919
</div>
2020
</div>

Tools/mssql-proxy/mssql-proxy.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic import BaseModel
77
import uvicorn
88
from colorama import Fore, Style, init
9-
import sys
9+
import sys, os
1010

1111
# Initialize colorama
1212
init(autoreset=True)
@@ -73,20 +73,35 @@ def log_query(index, query):
7373
endpoint_text = f"{Fore.GREEN}execute-query{Style.RESET_ALL}"
7474
print(f"{index_text} {endpoint_text}: Executed query: {query}")
7575

76+
def find_file_path(file_name):
77+
base_path = sys._MEIPASS
78+
for root, _, files in os.walk(f"{base_path}/drivers"):
79+
if file_name in files:
80+
return os.path.join(root, file_name)
81+
raise f"{file_name} NotFound."
82+
83+
def find_odbc_driver_path():
84+
try:
85+
with open(find_file_path("odbcinst.ini"), 'r') as file:
86+
for line in file:
87+
line = line.strip()
88+
if line.startswith("Driver="):
89+
driver_name = line.split("/")[-1].strip()
90+
break
91+
92+
return find_file_path(driver_name)
93+
except:
94+
print("Could not fild odbc driver internally...")
95+
return "{SQL Server}"
96+
7697
# Establish a database connection and return a unique connection ID
7798
@app.post("/connect")
7899
async def connect(request: ConnectRequest):
79100
global connection_index_counter
80101
try:
81102
# Attempt to connect to the database
82-
try:
83-
connection = pyodbc.connect(f"Driver={{SQL Server}};Server={request.server};UID={request.username};PWD={request.password};", timeout=5)
84-
except:
85-
try:
86-
base_path = sys._MEIPASS
87-
connection = pyodbc.connect(f"Driver={base_path}/drivers/msodbcsql18/lib64/libmsodbcsql-18.4.so.1.1;Server={request.server};UID={request.username};PWD={request.password};", timeout=5)
88-
except:
89-
raise
103+
driver_path = find_odbc_driver_path()
104+
connection = pyodbc.connect(f"Driver={driver_path};Server={request.server};UID={request.username};PWD={request.password};", timeout=5)
90105

91106
# Generate a unique ID and index for the connection
92107
connection_id = str(uuid.uuid4())

0 commit comments

Comments
 (0)