NativeOdbcConnection class
Native ODBC connection implementation using FFI bindings.
Provides direct access to the Rust-based ODBC engine through FFI. This is the low-level implementation that handles all native ODBC operations including connections, queries, transactions, prepared statements, connection pooling, and streaming.
Example:
final native = NativeOdbcConnection();
native.initialize();
final connId = native.connect('DSN=MyDatabase');
- Implemented types
Constructors
- NativeOdbcConnection()
- Creates a new NativeOdbcConnection instance.
Properties
- auditLogger → OdbcAuditLogger
-
Typed wrapper for native audit APIs.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInitialized → bool
-
Whether the ODBC environment has been initialized.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- supportsAsyncExecuteApi → bool
-
Whether the loaded native library supports async execute FFI endpoints.
no setter
- supportsAsyncStreamApi → bool
-
Whether the loaded native library supports async stream FFI endpoints.
no setter
- supportsAuditApi → bool
-
Whether the loaded native library supports audit FFI endpoints.
no setter
- supportsDriverCapabilitiesApi → bool
-
Whether the loaded native library supports driver capabilities FFI API.
no setter
- supportsMetadataCacheApi → bool
-
Whether the loaded native library supports metadata cache FFI endpoints.
no setter
- supportsStructuredErrorForConnection → bool
-
Whether the native library supports per-connection structured error API.
no setter
Methods
-
asyncCancel(
int requestId) → bool - Best-effort cancellation for an async request.
-
asyncFree(
int requestId) → bool - Frees async request resources.
-
asyncGetResult(
int requestId) → Uint8List? - Retrieves binary result for a completed async request.
-
asyncPoll(
int requestId) → int? -
Polls async request status:
0pending,1ready,-1error,-2cancelled. -
beginTransaction(
int connectionId, int isolationLevel) → int - Begins a new transaction with the specified isolation level.
-
beginTransactionHandle(
int connectionId, int isolationLevel) → TransactionHandle? - Begins a new transaction and returns a TransactionHandle wrapper.
-
bulkInsertArray(
int connectionId, String table, List< String> columns, Uint8List dataBuffer, int rowCount) → int - Performs a bulk insert operation.
-
bulkInsertParallel(
int poolId, String table, List< String> columns, Uint8List dataBuffer, int parallelism) → int -
Performs parallel bulk insert through
poolId.override -
cancelStatement(
int stmtId) → bool - Requests cancellation of a prepared statement execution.
-
catalogColumns(
int connectionId, String table) → Uint8List? -
Queries the database catalog for column information.
override
-
catalogQuery(
int connectionId) → CatalogQuery - Creates a CatalogQuery wrapper for database catalog queries.
-
catalogTables(
int connectionId, {String catalog = '', String schema = ''}) → Uint8List? -
Queries the database catalog for table information.
override
-
catalogTypeInfo(
int connectionId) → Uint8List? -
Queries the database catalog for data type information.
override
-
clearAllStatements(
) → int -
Clears all prepared statements.
override
-
clearAuditEvents(
) → bool - Clears in-memory native audit events.
-
clearMetadataCache(
) → bool - Clears metadata cache entries.
-
clearStatementCache(
) → bool - Clears the prepared statement cache.
-
closeStatement(
int stmtId) → bool -
Closes and releases a prepared statement.
override
-
commitTransaction(
int txnId) → bool -
Commits a transaction.
override
-
connect(
String connectionString) → int - Establishes a new database connection.
-
connectWithTimeout(
String connectionString, int timeoutMs) → int - Establishes a connection with a login timeout.
-
createConnectionPool(
String connectionString, int maxSize) → ConnectionPool? - Creates a new connection pool and returns a ConnectionPool wrapper.
-
createSavepoint(
int txnId, String name) → bool -
Creates a savepoint within an active transaction.
override
-
detectDriver(
String connectionString) → String? - Detects the database driver from a connection string.
-
disconnect(
int connectionId) → bool - Closes and disconnects a connection.
-
dispose(
) → void - Disposes of native resources.
-
executeAsyncStart(
int connectionId, String sql) → int? - Starts non-blocking query execution and returns async request ID.
-
executePrepared(
int stmtId, List< ParamValue> ? params, int timeoutOverrideMs, int fetchSize, {int? maxBufferBytes}) → Uint8List? -
Executes a prepared statement with optional parameters.
override
-
executePreparedRaw(
int stmtId, Uint8List? serializedParams, int timeoutOverrideMs, int fetchSize, {int? maxBufferBytes}) → Uint8List? - Executes a prepared statement with params already serialized (bytes).
-
executeQueryMulti(
int connectionId, String sql, {int? maxBufferBytes}) → Uint8List? - Executes a SQL query that returns multiple result sets.
-
executeQueryParams(
int connectionId, String sql, List< ParamValue> params, {int? maxBufferBytes}) → Uint8List? - Executes a SQL query with parameters.
-
executeQueryParamsRaw(
int connectionId, String sql, Uint8List? serializedParams, {int? maxBufferBytes}) → Uint8List? - Executes a parameterized query with params already serialized (bytes).
-
getAuditEventsJson(
{int limit = 0}) → String? - Gets audit events as JSON payload.
-
getAuditStatusJson(
) → String? - Gets audit status as JSON payload.
-
getCacheMetrics(
) → PreparedStatementMetrics? -
Gets prepared statement metrics.
override
-
getDriverCapabilities(
String connectionString) → DriverCapabilities? -
Returns typed driver capabilities from
connectionString, or null when API is unavailable or invalid. -
getDriverCapabilitiesJson(
String connectionString) → String? - Returns driver capabilities payload as JSON, or null on failure.
-
getError(
) → String - Gets the last error message from the native engine.
-
getMetadataCacheStatsJson(
) → String? - Returns metadata cache stats JSON payload.
-
getMetrics(
) → OdbcMetrics? -
getStructuredError(
) → StructuredError? - Gets structured error information including SQLSTATE and native code.
-
getStructuredErrorForConnection(
int connectionId) → StructuredError? - Gets structured error for a specific connection (per-connection isolation).
-
getVersion(
) → Map< String, String> ? - Gets performance and operational metrics.
-
initialize(
) → bool - Initializes the ODBC environment.
-
metadataCacheEnable(
{required int maxEntries, required int ttlSeconds}) → bool - Enables metadata cache in native engine.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
poolClose(
int poolId) → bool -
Closes the connection pool and releases all connections.
override
-
poolCreate(
String connectionString, int maxSize) → int - Creates a new connection pool.
-
poolGetConnection(
int poolId) → int -
Gets a connection from the pool.
override
-
poolGetState(
int poolId) → ({int idle, int size})? -
Gets the current state of the connection pool.
override
-
poolGetStateJson(
int poolId) → Map< String, dynamic> ? - Returns pool state telemetry payload as JSON, or null on failure.
-
poolHealthCheck(
int poolId) → bool -
Performs a health check on the connection pool.
override
-
poolReleaseConnection(
int connectionId) → bool -
Releases a connection back to the pool.
override
-
poolSetSize(
int poolId, int newMaxSize) → bool -
Resizes the pool by recreating it with
newMaxSize.override -
prepare(
int connectionId, String sql, {int timeoutMs = 0}) → int - Prepares a SQL statement for execution.
-
prepareStatement(
int connectionId, String sql, {int timeoutMs = 0}) → PreparedStatement? - Prepares a SQL statement and returns a PreparedStatement wrapper.
-
prepareStatementNamed(
int connectionId, String sql, {int timeoutMs = 0}) → PreparedStatement? -
Prepares a SQL statement with named parameters and returns a
PreparedStatementwrapper that supportsexecuteNamed. -
releaseSavepoint(
int txnId, String name) → bool -
Releases a savepoint. The transaction remains active.
override
-
rollbackToSavepoint(
int txnId, String name) → bool -
Rolls back to a savepoint. The transaction remains active.
override
-
rollbackTransaction(
int txnId) → bool -
Rolls back a transaction.
override
-
setAuditEnabled(
{required bool enabled}) → bool - Enables/disables native audit event collection.
-
streamCancel(
int streamId) → bool - Requests cancellation for a low-level native stream.
-
streamClose(
int streamId) → bool - Closes a low-level native stream.
-
streamFetch(
int streamId) → StreamFetchResult - Fetches the next chunk for a low-level native stream.
-
streamPollAsync(
int streamId) → int? -
Polls async stream status:
0pending,1ready,2done,-1error,-2cancelled. -
streamQuery(
int connectionId, String sql, {int chunkSize = 1000}) → Stream< ParsedRowBuffer> - Executes a SQL query and returns results as a stream.
-
streamQueryBatched(
int connectionId, String sql, {int fetchSize = 1000, int chunkSize = 64 * 1024}) → Stream< ParsedRowBuffer> - Executes a SQL query and returns results as a batched stream.
-
streamStart(
int connectionId, String sql, {int chunkSize = 1000}) → int - Starts a low-level streaming query and returns a native stream ID.
-
streamStartAsync(
int connectionId, String sql, {int fetchSize = 1000, int chunkSize = 64 * 1024}) → int? - Starts async stream and returns stream ID.
-
streamStartBatched(
int connectionId, String sql, {int fetchSize = 1000, int chunkSize = 64 * 1024}) → int - Starts a low-level batched streaming query and returns stream ID.
-
toString(
) → String -
A string representation of this object.
inherited
-
validateConnectionString(
String connectionString) → String? - Validates connection string format without opening a connection.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited