Skip to content

feat(bq_driver): implement cross-platform File DSN connection support - #1701

Draft
KanchanShu wants to merge 1 commit into
googleapis:mainfrom
KanchanShu:imple_file_dsn
Draft

KanchanShu wants to merge 1 commit into
googleapis:mainfrom
KanchanShu:imple_file_dsn

Conversation

@KanchanShu

@KanchanShu KanchanShu commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for File DSN connections (FILEDSN=<path>) in the BigQuery ODBC Driver across all supported platforms (Linux, macOS, and Windows) for both SQLDriverConnect and SQLBrowseConnect.

It also adds comprehensive unit and integration test coverage for File DSN connection flows, invalid credentials, empty paths, and non-existent files without introducing any static or hardcoded local file paths.


Changes

1. Driver Core & Parsing Logic

  • ProcessFileDSN extraction: Centralized File DSN parsing logic into a shared helper function in google/cloud/odbc/bq_driver/odbc_connection.cc used by both SQLDriverConnectInternal and SQLBrowseConnectInternal.
  • Cross-platform path resolution:
    • On Windows: Looks up DefaultDSNDir from HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC File DSN if a relative filename is provided.
    • On Linux/macOS: Resolves relative paths against the current working directory.
  • Bounds Checking & Undefined Behavior Prevention:
    • Added explicit .size() >= 2 bounds checking prior to string slicing to eliminate potential unsigned underflow/overflow risks.
    • Guarded std::tolower with static_cast<unsigned char> to prevent undefined behavior with signed characters under Clang / AddressSanitizer (ASAN).
  • Diagnostics: Added proper SQLSTATE reporting (SQLSTATE 08001 / HY000) when a File DSN path cannot be read or opened.

2. Testing

  • Unit Tests (google/cloud/odbc/bq_driver/internal/utils_test.cc):
    • Added unit test cases for empty File DSN paths, non-existent files, and valid .dsn files with key-value parsing and quote stripping.
    • Implemented an RAII Cleaner struct for deterministic cleanup of temporary test files.
  • Integration Tests (google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc):
    • Added ConnectionTest.FileDSN_Success: Generates a dynamic, self-cleaning temporary .dsn file with absolute path resolution via std::filesystem::absolute to support both Google Driver and Simba Driver seamlessly across platforms.
    • Added negative test cases: FileDSN_NonExistentFile_Fails, FileDSN_EmptyPath_Fails, and FileDSN_InvalidCredentials_Fails.
    • Added GTEST_SKIP() guard when CPP_BIGQUERY_ODBC_TEST_SERVICE_ACCOUNT_AUTH_KEY is not present, allowing test suites to pass gracefully on local developer machines without active GCP credentials.

Bug: Buganizer Issue 576846795

// Strip UTF-8 BOM if present
if (is_first_line) {
is_first_line = false;
if (line.size() >= 3 && static_cast<unsigned char>(line[0]) == 0xEF &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we doing this handling? will this work for cross platform , ascii/ non-ascii encodings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, editors like Notepad often prepend a 3-byte UTF-8 BOM (0xEF, 0xBB, 0xBF). Without stripping it, [ODBC] is read as \xEF\xBB\xBF[ODBC], causing line.front() == '[' to fail and the section to be missed.

It is safe across platforms and encodings:

  • ASCII: Characters are 0x00–0x7F, so they will never match 0xEF (safe no-op).
  • Cross-platform / Non-ASCII (UTF-8): The BOM sequence is endian-neutral and identical across Linux, macOS, and Windows. Only the leading 3 bytes on the first line are stripped; all non-ASCII payloads remain intact.

If you'd prefer to omit BOM handling to stay consistent with ParseConfig, I'm happy to remove it—let me know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants