From 2794059bbbf7465571c684093345828efa7d11e3 Mon Sep 17 00:00:00 2001 From: Richard Wheeler Date: Thu, 9 Apr 2026 14:27:49 -0400 Subject: [PATCH] mssql, ci: fix Database CI mssql-driver-tests job (#26850) * mssql: add tcc linux include path flag for unixODBC headers (fixes #26816) tcc does not search /usr/include by default, causing compilation failures when building the mssql module on Linux with the bundled tcc after unixodbc-dev is installed. Add `#flag linux -I/usr/include` under a `$if tinyc` guard so tcc can locate sql.h and sqlext.h. Co-Authored-By: Claude Sonnet 4.6 * mssql: avoid DROP TABLE IF EXISTS to prevent FreeTDS protocol state pollution DROP TABLE IF EXISTS on a non-existent table causes SQL Server to send an informational TDS token. FreeTDS may not drain this token before the statement handle is freed, leaving the connection in a state where the next SQLAllocHandle(STMT) returns a handle that immediately gives SQL_INVALID_HANDLE on SQLExecDirect (no ODBC diagnostics). Replace with IF OBJECT_ID() IS NOT NULL DROP TABLE, which only sends a done token and avoids the spurious info message. Co-Authored-By: Claude Sonnet 4.6 * ci: skip GPG dearmor if microsoft-prod.gpg already exists on runner Ubuntu 24.04 GitHub Actions runners ship with /usr/share/keyrings/microsoft-prod.gpg pre-installed. The unconditional `gpg --dearmor -o ...` fails with "File exists" because the file is already present. Guard the step so it only runs when the file is absent. Co-Authored-By: Claude Sonnet 4.6 --------- Co-authored-by: Richard Wheeler <18647491+PythonWillRule@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- .github/workflows/db_ci.yml | 2 +- vlib/db/mssql/_cdef_nix.c.v | 6 ++++++ vlib/db/mssql/mssql_test.v | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/db_ci.yml b/.github/workflows/db_ci.yml index 7864a6dea..48c8adf98 100644 --- a/.github/workflows/db_ci.yml +++ b/.github/workflows/db_ci.yml @@ -96,7 +96,7 @@ jobs: - name: Install ODBC dependencies run: | .github/workflows/disable_azure_mirror.sh - curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --batch --no-tty --dearmor -o /usr/share/keyrings/microsoft-prod.gpg + [ -f /usr/share/keyrings/microsoft-prod.gpg ] || curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --batch --no-tty --dearmor -o /usr/share/keyrings/microsoft-prod.gpg curl -fsSL https://packages.microsoft.com/config/ubuntu/24.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list ./v retry -- sudo apt update sudo ACCEPT_EULA=Y apt install --quiet -y msodbcsql18 unixodbc-dev diff --git a/vlib/db/mssql/_cdef_nix.c.v b/vlib/db/mssql/_cdef_nix.c.v index 7591c9af7..7838c85c9 100644 --- a/vlib/db/mssql/_cdef_nix.c.v +++ b/vlib/db/mssql/_cdef_nix.c.v @@ -13,5 +13,11 @@ $if $pkgconfig('odbc') { #flag darwin -L/opt/local/lib } +$if tinyc { + // tcc does not search system include paths by default; add /usr/include so + // that it can find the unixODBC headers (sql.h, sqlext.h) on Linux. + #flag linux -I/usr/include +} + #include #include diff --git a/vlib/db/mssql/mssql_test.v b/vlib/db/mssql/mssql_test.v index 4ace13bf0..41f0c113e 100644 --- a/vlib/db/mssql/mssql_test.v +++ b/vlib/db/mssql/mssql_test.v @@ -35,9 +35,9 @@ fn test_connection_and_query() { conn.close() } - conn.query('drop table if exists vlang_mssql_test') or {} + conn.query("if object_id('vlang_mssql_test', 'U') is not null drop table vlang_mssql_test") or {} defer { - conn.query('drop table if exists vlang_mssql_test') or {} + conn.query("if object_id('vlang_mssql_test', 'U') is not null drop table vlang_mssql_test") or {} } create_result := conn.query('create table vlang_mssql_test ( -- 2.39.5