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
native OdbcNative
Internal — exposes the underlying bindings.OdbcNative to helpers like XaTransactionHandle that need to drive the FFI directly. Not part of the public API; callers should use the high-level methods on this class.
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
supportsConnectionDbmsInfoApi bool
Whether the loaded native library exposes live DBMS introspection (v2.1 odbc_get_connection_dbms_info).
no setter
supportsDriverCapabilitiesApi bool
Whether the loaded native library supports driver capabilities FFI API.
no setter
supportsExecuteQueryMultiParams bool
Whether the loaded native library exports odbc_exec_query_multi_params (added in v3.2.0).
no setter
supportsMetadataCacheApi bool
Whether the loaded native library supports metadata cache FFI endpoints.
no setter
supportsStreamQueryMulti bool
Whether the loaded native library exports the M8 streaming multi-result FFIs (added in v3.3.0).
no setter
supportsStructuredErrorForConnection bool
Whether the native library supports per-connection structured error API.
no setter
supportsTransactionAccessMode bool
True when the loaded native library supports odbc_transaction_begin_v2 (Sprint 4.1, the accessMode parameter of beginTransaction). When false, accessMode is silently ignored and every transaction is READ WRITE.
no setter
supportsTransactionLockTimeout bool
True when the loaded native library supports odbc_transaction_begin_v3 (Sprint 4.2, the lockTimeoutMs parameter of beginTransaction). When false, lockTimeoutMs is silently ignored and every transaction uses the engine default lock timeout.
no setter
supportsXa bool
True when the loaded native library supports the XA / 2PC FFI family (Sprint 4.3). Callers should gate on this before invoking xaStart / xaRecover / xaResumePrepared; older binaries throw UnsupportedError.
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: 0 pending, 1 ready, -1 error, -2 cancelled.
beginTransaction(int connectionId, int isolationLevel, {int savepointDialect = 0, int accessMode = 0, int lockTimeoutMs = 0}) int
Begins a new transaction with the specified isolation level.
beginTransactionHandle(int connectionId, int isolationLevel, {int savepointDialect = 0, int accessMode = 0, int lockTimeoutMs = 0}) 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
catalogForeignKeys(int connectionId, String table) Uint8List?
Queries the database catalog for foreign key information.
override
catalogIndexes(int connectionId, String table) Uint8List?
Queries the database catalog for index information.
override
catalogPrimaryKeys(int connectionId, String table) Uint8List?
Queries the database catalog for primary key 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, {PoolOptions? options}) 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.
executeQueryMultiParams(int connectionId, String sql, Uint8List? paramsBuffer, {int? maxBufferBytes}) Uint8List?
Executes a parameterised batch SQL that may return 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
getConnectionDbmsInfoJson(int connectionId) String?
Returns the live DBMS introspection JSON for connectionId, or null when the call fails or the API is unavailable. Use the high-level OdbcDriverCapabilities.getDbmsInfoForConnection to obtain a typed DbmsInfo instead of raw JSON.
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, {PoolOptions? options}) int
Creates a new connection pool.
poolCreateWithOptions(String connectionString, int maxSize, {String? optionsJson}) int
Creates a pool from a pre-encoded native options JSON payload.
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 PreparedStatement wrapper that supports executeNamed.
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.
setLogLevel(int level) → void
Sets native engine log verbosity (0=off, 5=trace).
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.
streamMultiStartAsync(int connectionId, String sql, {int chunkSize = 64 * 1024}) int?
Async variant of streamMultiStartBatched. Combine with streamPollAsync for non-blocking readiness.
streamMultiStartBatched(int connectionId, String sql, {int chunkSize = 64 * 1024}) int?
Starts a streaming multi-result batch in batched mode and returns the new stream id (or null on failure / unsupported native lib). Use streamFetch / streamCancel / streamClose to drive it.
streamPollAsync(int streamId) int?
Polls async stream status: 0 pending, 1 ready, 2 done, -1 error, -2 cancelled.
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.
xaRecover(int connectionId) List<Xid>?
xa_recover: list every XID currently in the XaState.prepared state on the resource manager. Used after process restart to discover branches awaiting a Phase 2 decision.
xaResumePrepared(int connectionId, Xid xid) XaTransactionHandle?
Resume a previously prepared xid — rebuilds an XaTransactionHandle in the XaState.prepared state for crash- recovery scenarios. Returns null on failure.
xaStart(int connectionId, Xid xid) XaTransactionHandle?
xa_start: open a new XA branch on connectionId with the given xid. Returns a live XaTransactionHandle in the XaState.active state on success, null on failure (call getStructuredError to inspect the cause).

Operators

operator ==(Object other) bool
The equality operator.
inherited