Metadata-Version: 2.5
Name: harlequin-odbc-vertica
Version: 0.1.2
Summary: A Harlequin adapter for Vertica via ODBC, fixing catalog and column metadata issues.
Project-URL: Repository, https://github.com/clang-engineer/harlequin-odbc-vertica
Project-URL: Issues, https://github.com/clang-engineer/harlequin-odbc-vertica/issues
Author: clang-engineer
License-Expression: MIT
License-File: LICENSE
Keywords: database,harlequin,odbc,sql,vertica
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Topic :: Database :: Front-Ends
Requires-Python: >=3.10
Requires-Dist: harlequin-odbc>=0.4.0
Requires-Dist: harlequin<3,>=1.25
Description-Content-Type: text/markdown

# harlequin-odbc-vertica

[![PyPI](https://img.shields.io/pypi/v/harlequin-odbc-vertica)](https://pypi.org/project/harlequin-odbc-vertica/)
[![CI](https://github.com/clang-engineer/harlequin-odbc-vertica/actions/workflows/ci.yml/badge.svg)](https://github.com/clang-engineer/harlequin-odbc-vertica/actions/workflows/ci.yml)

A [Harlequin](https://harlequin.sh) adapter for [Vertica](https://www.vertica.com/) via ODBC.

This adapter extends `harlequin-odbc` to fix Vertica-specific issues with catalog and column metadata retrieval.

## Problem

The standard `harlequin-odbc` adapter has two issues when used with Vertica:

1. **Empty Data Catalog**: Vertica's ODBC driver returns `None` for catalog names, causing all tables to be filtered out.
2. **Column listing error**: Vertica's ODBC driver does not support the `catalog` parameter in `SQLColumns`, resulting in `HYC00` errors.

## Solution

`harlequin-odbc-vertica` overrides two methods in the ODBC adapter:

- `_list_tables`: Resolves `SELECT current_database()` before streaming `SQLTables` metadata, then uses it when the catalog name is `None`. Vertica cannot execute another query on the same connection while that metadata result is active.
- `_list_columns_in_relation`: Omits the `catalog` parameter when calling `pyodbc.Cursor.columns()`.

## Installation

Three separate components are required:

1. **Harlequin and this Python plug-in**: `odbc-vertica` is the Harlequin
   adapter name. Installing the plug-in also installs its `harlequin-odbc` and
   `pyodbc` dependencies; it does **not** install a Vertica database driver.
2. **An ODBC driver manager**: unixODBC locates and loads registered native
   drivers. `odbcinst` is its configuration/query utility, not a driver.
3. **The native Vertica ODBC driver**: a separate library supplied by Vertica.
   It must be loadable by the driver manager and registered under the name
   `Vertica`, which matches `DRIVER={Vertica}` in the connection string.

### 1. Install Harlequin, unixODBC, and the plug-in

On macOS with Homebrew:

```sh
brew install harlequin unixodbc
```

On Debian/Ubuntu, install the driver manager with `sudo apt install unixodbc`;
install Harlequin using its [installation instructions](https://harlequin.sh/docs/getting-started).
Neither package manager command above installs the **native Vertica driver**.

Install this plug-in **in the same Python environment as Harlequin**. For a
virtual environment containing Harlequin:

```sh
python -m pip install harlequin-odbc-vertica
```

For a Homebrew-installed Harlequin, `pip` on your shell's `PATH` may point to
a different Python. Use the interpreter from Harlequin's entry-point script:

```sh
HARLEQUIN_PYTHON="$(head -n 1 "$(command -v harlequin)" | sed 's/^#!//')"
"$HARLEQUIN_PYTHON" -m pip install harlequin-odbc-vertica
```

If installing Harlequin as a `uv` tool instead:

```sh
uv tool install harlequin --with harlequin-odbc-vertica
```

After a Homebrew upgrade replaces Harlequin's environment, reinstall the
plug-in into the new environment. `harlequin --version` should list
`odbc-vertica` under installed adapters.

### 2. Install and register the native Vertica driver

Obtain the ODBC driver for your operating system from the
[Vertica client-driver installation documentation](https://docs.vertica.com/26.3.x/en/connecting-to/client-libraries/client-drivers/install-config/odbc/installing-odbc/).
Follow the vendor's installer instructions. On macOS, ensure the driver
library supports the architecture of the Python process running Harlequin:
an x86_64-only library cannot be loaded into an arm64 process.

```sh
odbcinst -j       # locations used by this unixODBC installation
odbcinst -q -d    # registered driver names; look for Vertica
```

If the vendor installer did not register `Vertica` with **this** unixODBC
installation, add an entry to the `odbcinst.ini` shown as `DRIVERS` by
`odbcinst -j`. Use the actual absolute path to the installed library (often
`.dylib` on macOS or `.so` on Linux), not the example below:

```ini
[Vertica]
Description = Vertica ODBC driver
Driver = /absolute/path/to/installed/vertica-odbc-library
FileUsage = 1
```

The `[Vertica]` section is the name referenced by `DRIVER={Vertica}`; the
`Driver` value is a filesystem path, **not** `harlequin-odbc-vertica`. A DSN
in `odbc.ini` is not required when passing a full connection string. After
registration, rerun `odbcinst -q -d` and check that the library path exists.
Listing a driver confirms its registration, not that it can load or connect.

### macOS with Homebrew unixODBC

The macOS Vertica `.pkg` may register its driver in `/etc/odbcinst.ini`,
while Homebrew unixODBC reads `/opt/homebrew/etc/odbcinst.ini` on Apple
Silicon. If `odbcinst -j` points there and `odbcinst -q -d` does not show
`[Vertica]`, register the installed
`/Library/Vertica/ODBC/lib/libverticaodbc.dylib` in Homebrew's
`odbcinst.ini` using the `[Vertica]` section above.

Registration alone may still leave `SQLDriverConnect` failing with
`('H000', '[H000] [ (50404) (SQLDriverConnect)')`: the vendor's default
`vertica.ini` uses iODBC (`UTF-32`), whereas Homebrew `pyodbc` uses
unixODBC. Run `mkdir -p ~/.config/vertica` and create
`~/.config/vertica/vertica.ini` with:

```ini
[Driver]
ErrorMessagesPath=/Library/Vertica/ODBC/messages/
ODBCInstLib=/opt/homebrew/lib/libodbcinst.2.dylib
DriverManagerEncoding=UTF-16
```

Launch Harlequin with the example profile below and the new file:

```sh
export VERTICAINI="$HOME/.config/vertica/vertica.ini"
harlequin -P vertica
```

This avoids editing the root-owned vendor file. Check that the configured
path exists. On other architectures or Homebrew prefixes, use the actual
path to the installed unixODBC library. Check the
fix by launching Harlequin with a valid profile: a listed driver or a
successful `isql` test alone does not prove Python's Unicode ODBC path
works.

## Usage

With a reachable Vertica server and valid credentials:

```sh
harlequin -a odbc-vertica 'DRIVER={Vertica};SERVER=your-server;PORT=5433;DATABASE=your-db;UID=user;PWD=your-password'
```

Real passwords in command-line arguments can appear in shell history and
process listings. For regular use, add a profile to a private Harlequin
config file (for example `~/.harlequin.toml`) instead:

```toml
[profiles.vertica]
adapter = "odbc-vertica"
conn_str = ["DRIVER={Vertica};SERVER=your-server;PORT=5433;DATABASE=your-db;UID=user;PWD=your-password"]
```

Replace the placeholders locally, restrict the file with
`chmod 600 ~/.harlequin.toml`, and launch with `harlequin -P vertica`.

## Troubleshooting

- **"Could not load an adapter named odbc-vertica"**: the plug-in is missing
  from the Python environment used by the `harlequin` executable. Check
  `harlequin --version` and reinstall into that environment as above.
- **`odbcinst -q -d` reports `SQLGetPrivateProfileString failed`**: inspect
  the `DRIVERS` path from `odbcinst -j`; no driver definitions may be
  available to this unixODBC installation. Install/register the native
  driver as described above.
- **"[unixODBC][Driver Manager] Can't open lib 'Vertica'"**: the native
  driver is missing, unregistered, or points to a library that cannot be
  loaded. Check `odbcinst -j`, `odbcinst -q -d`, the `Driver` path, and the
  library's architecture (`file /absolute/path/to/installed/library`).
- **`H000` / `50404` after registering the driver on macOS**: check
  [`VERTICAINI` and Homebrew unixODBC encoding](#macos-with-homebrew-unixodbc).
- **Connection/authentication error after the driver loads**: check the
  server, port, database, credentials, and network access; registering a
  driver does not establish a database connection.
- **Empty catalog or column metadata errors with `-a odbc`**: use
  `-a odbc-vertica`, which applies the Vertica-specific metadata fixes.
- **Catalog error `(20)` executing `SELECT current_database()`**: older
  adapter builds issue this query while iterating `SQLTables` on the same
  connection. Install a build containing the cursor-ordering fix into
  Harlequin's Python environment and restart Harlequin. This source resolves
  the database name before starting the table metadata result.

## License

MIT
