Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test_odbc.sqlite
lars_notes.md
.claude/
ODBC
/docs/superpowers/plans/
2 changes: 0 additions & 2 deletions src/connection.rs

This file was deleted.

9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use odbc_sys::{Integer, WChar};

mod connection;
mod logging;
mod odbc;

/// Registers the SQLite implementation with the driver's handle factory.
/// Called once at driver startup (from SQLAllocHandle for environment handles).
pub(crate) fn init_driver() {
odbc::handles::register_factory(Box::new(
odbc::implementation::query::SqliteDbConnectionFactory,
));
}

// Cross-platform ODBC library linking configuration
// These attributes handle the complexity of linking against different ODBC implementations
// across Windows, Linux, and macOS with support for both static and dynamic linking.
Expand Down
3 changes: 2 additions & 1 deletion src/odbc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod api;
mod def;
mod implementation;
pub(crate) mod handles;
pub(crate) mod implementation;
mod utils;
16 changes: 8 additions & 8 deletions src/odbc/api/sqlallochandle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::logging;
use crate::odbc::implementation::alloc_handles::{
ConnectionHandle, EnvironmentHandle, allocate_stmt_handle, impl_allocate_dbc_handle,
impl_allocate_environment_handle,
};
use crate::odbc::handles::{ConnectionHandle, EnvironmentHandle};
use crate::odbc::utils::{get_from_wrapper, wrap_and_set};
use odbc_sys::{HandleType, Pointer, SmallInt, SqlReturn};
use tracing::{debug, error, info};
Expand Down Expand Up @@ -50,8 +47,10 @@ pub extern "C" fn SQLAllocHandle(
return SqlReturn::ERROR;
}

// Call the implementation and convert the output properly
let handle = impl_allocate_environment_handle();
// Register the SQLite factory on first use.
crate::init_driver();

let handle = EnvironmentHandle::default();
wrap_and_set(handle_type, handle, output_handle);

info!("Successfully allocated an environment handle");
Expand Down Expand Up @@ -79,7 +78,8 @@ pub extern "C" fn SQLAllocHandle(
}
};

let handle = impl_allocate_dbc_handle(env_handle);
let handle = ConnectionHandle { connection: None };
let _ = env_handle; // env_handle validated above; connection state lives in the handle
wrap_and_set(handle_type, handle, output_handle);

info!("Successfully allocated a Dbc handle");
Expand All @@ -97,7 +97,7 @@ pub extern "C" fn SQLAllocHandle(
}
};

let handle = match allocate_stmt_handle(connection_handle) {
let handle = match connection_handle.allocate_stmt_handle() {
Some(handle) => handle,
None => {
error!("Cannot allocate statement handle: no active connection");
Expand Down
Loading