Skip to content

Commit 8866cf4

Browse files
cursoragentlovasoa
andcommitted
feat: Add ODBC build modes and documentation
Co-authored-by: contact <[email protected]>
1 parent 186686b commit 8866cf4

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

CONTRIBUTING.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,33 @@ cargo build --release
3737

3838
The resulting executable will be in `target/release/sqlpage`.
3939

40+
### ODBC build modes
41+
42+
SQLPage supports three additive build modes for ODBC. Choose the mode via Cargo features:
43+
44+
- Dynamic ODBC (default):
45+
- Works on Linux, macOS and Windows (Windows has ODBC built-in).
46+
- Command:
47+
```bash
48+
cargo build # or: cargo build --features odbc-dynamic
49+
```
50+
- Static ODBC (Linux only):
51+
- Statically links the ODBC driver manager; simplifies distribution.
52+
- Command:
53+
```bash
54+
cargo build --features odbc-static
55+
```
56+
- No ODBC:
57+
- Disables ODBC support entirely.
58+
- Command:
59+
```bash
60+
cargo build --no-default-features
61+
```
62+
63+
Notes:
64+
- When cross-compiling in Docker, headers come from the base image (e.g. `unixodbc-dev`).
65+
- Runtime rpath on Linux includes `$ORIGIN/sqlpage:$ORIGIN/lib` so you can colocate drivers next to the binary when needed.
66+
4067
## Code Style and Linting
4168

4269
### Rust
@@ -199,8 +226,6 @@ git checkout -b feature/your-feature-name
199226
- Run frontend linting with Biome
200227
- Test against multiple databases (PostgreSQL, MySQL, MSSQL)
201228
202-
5. Wait for review and address any feedback
203-
204229
## Release Process
205230
206231
Releases are automated when pushing tags that match the pattern `v*` (e.g., `v1.0.0`). The CI pipeline will:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ You can skip this section if you want to use one of the built-in database driver
190190
191191
SQLPage supports ODBC connections to connect to databases that don't have native drivers, such as Oracle, Snowflake, BigQuery, IBM DB2, and many others.
192192

193-
On Linux, the SQLPage binary and Docker image now statically link against the `unixODBC` driver manager, so you generally do not need to install `unixodbc` on the host anymore. You still need to install the database-specific ODBC driver for the database you want to connect to. SQLPage also searches for drivers in a `sqlpage/` directory placed next to the executable (rpath includes `$ORIGIN/sqlpage`). You can drop driver `.so` files there when packaging a self-contained application.
193+
On Linux, SQLPage supports both dynamic and static ODBC linking. The Docker image uses the system `unixODBC` (dynamic). Release binaries can be built with static ODBC linking by enabling the `odbc-static` feature. You still need to install or provide the database-specific ODBC driver for the database you want to connect to. SQLPage also searches for drivers in a `sqlpage/` directory placed next to the executable (rpath includes `$ORIGIN/sqlpage`).
194194

195195
#### Install ODBC
196196

src/webserver/database/connect.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use anyhow::Context;
1010
use futures_util::future::BoxFuture;
1111
use sqlx::{
1212
any::{Any, AnyConnectOptions, AnyKind},
13-
odbc::OdbcConnectOptions,
1413
pool::PoolOptions,
1514
sqlite::{Function, SqliteConnectOptions, SqliteFunctionCtx},
1615
ConnectOptions, Connection, Executor,
1716
};
17+
#[cfg(feature = "odbc")]
18+
use sqlx::odbc::OdbcConnectOptions;
1819

1920
impl Database {
2021
pub async fn init(config: &AppConfig) -> anyhow::Result<Self> {
@@ -209,8 +210,11 @@ fn set_custom_connect_options(options: &mut AnyConnectOptions, config: &AppConfi
209210
if let Some(sqlite_options) = options.as_sqlite_mut() {
210211
set_custom_connect_options_sqlite(sqlite_options, config);
211212
}
212-
if let Some(odbc_options) = options.as_odbc_mut() {
213-
set_custom_connect_options_odbc(odbc_options, config);
213+
#[cfg(feature = "odbc")]
214+
{
215+
if let Some(odbc_options) = options.as_odbc_mut() {
216+
set_custom_connect_options_odbc(odbc_options, config);
217+
}
214218
}
215219
}
216220

@@ -239,6 +243,7 @@ fn make_sqlite_fun(name: &str, f: fn(&str) -> String) -> Function {
239243
})
240244
}
241245

246+
#[cfg(feature = "odbc")]
242247
fn set_custom_connect_options_odbc(odbc_options: &mut OdbcConnectOptions, config: &AppConfig) {
243248
// Allow fetching very large text fields when using ODBC by removing the max column size limit
244249
let batch_size = config.max_pending_rows.clamp(1, 1024);

0 commit comments

Comments
 (0)