Skip to content

Commit

Permalink
updated mssql-proxy to automatically find odbc driver
Browse files Browse the repository at this point in the history
enabled mac download button
cleaned up CIs
  • Loading branch information
IPdotSetAF committed Nov 21, 2024
1 parent 5e46f7a commit 22ea5f4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: 3.11.4
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
- run: ./Tools/mssql-proxy/odbc-driver-installer.sh
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
- run: pyinstaller mssql-proxy.linux.spec
working-directory: Tools/mssql-proxy
- id: name
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ jobs:
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
HOMEBREW_SANDBOX=1 HOMEBREW_ACCEPT_EULA=Y brew install unixodbc msodbcsql18 tree
tree /opt/homebrew/Cellar/msodbcsql18/
cat /opt/homebrew/Cellar/msodbcsql18/18.4.1.1/odbcinst.ini
HOMEBREW_SANDBOX=1 HOMEBREW_ACCEPT_EULA=Y brew install unixodbc msodbcsql18
- run: pip install -r Tools/mssql-proxy/requirements.txt pyinstaller
- run: pyinstaller mssql-proxy.mac.spec
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ jobs:
uses: ./.github/workflows/publish.yml
if: github.ref_type == 'tag'

# build-linux:
# uses: ./.github/workflows/build-linux.yml
build-linux:
uses: ./.github/workflows/build-linux.yml

# build-windows:
# uses: ./.github/workflows/build-windows.yml
build-windows:
uses: ./.github/workflows/build-windows.yml

build-macos:
uses: ./.github/workflows/build-macos.yml

# build-publish-docker:
# uses: ./.github/workflows/build-publish-docker.yml
# needs: [publish, build-linux, build-windows, build-macos]
build-publish-docker:
uses: ./.github/workflows/build-publish-docker.yml
needs: [publish, build-linux, build-windows, build-macos]

release:
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
# needs: [build-publish-docker]
needs: [build-publish-docker]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Frontend/src/app/downloads/downloads.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2 class="bi bi-database"> MSSQl proxy server</h2>
<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>
<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>
<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>
<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>
<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>
<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>
</div>
</div>
Expand Down
33 changes: 24 additions & 9 deletions Tools/mssql-proxy/mssql-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import BaseModel
import uvicorn
from colorama import Fore, Style, init
import sys
import sys, os

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

def find_file_path(file_name):
base_path = sys._MEIPASS
for root, _, files in os.walk(f"{base_path}/drivers"):
if file_name in files:
return os.path.join(root, file_name)
raise f"{file_name} NotFound."

def find_odbc_driver_path():
try:
with open(find_file_path("odbcinst.ini"), 'r') as file:
for line in file:
line = line.strip()
if line.startswith("Driver="):
driver_name = line.split("/")[-1].strip()
break

return find_file_path(driver_name)
except:
print("Could not fild odbc driver internally...")
return "{SQL Server}"

# Establish a database connection and return a unique connection ID
@app.post("/connect")
async def connect(request: ConnectRequest):
global connection_index_counter
try:
# Attempt to connect to the database
try:
connection = pyodbc.connect(f"Driver={{SQL Server}};Server={request.server};UID={request.username};PWD={request.password};", timeout=5)
except:
try:
base_path = sys._MEIPASS
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)
except:
raise
driver_path = find_odbc_driver_path()
connection = pyodbc.connect(f"Driver={driver_path};Server={request.server};UID={request.username};PWD={request.password};", timeout=5)

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

0 comments on commit 22ea5f4

Please sign in to comment.