OdbcNative class
Native ODBC bindings wrapper.
Provides a high-level Dart interface to the native ODBC engine through FFI bindings. Handles connection management, queries, transactions, prepared statements, connection pooling, and streaming.
Constructors
- OdbcNative()
- Creates a new OdbcNative instance.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- rawBindings → OdbcBindings
-
Read-only access to the raw bindings. Use only for new capabilities
implemented in companion modules (e.g.
driver_capabilities_v3.dart).no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- supportsAsyncExecuteApi → bool
-
True when the loaded native library exposes async execute FFI APIs.
no setter
- supportsAsyncMultiResultStream → bool
-
no setter
- supportsAsyncStreamApi → bool
-
True when the loaded native library exposes async stream FFI APIs.
no setter
- supportsAuditApi → bool
-
True when the loaded native library exposes the audit FFI API.
no setter
- supportsConnectionDbmsInfoApi → bool
-
True when the loaded native library exposes the v2.1 live DBMS
introspection FFI (
odbc_get_connection_dbms_info).no setter - supportsDriverCapabilitiesApi → bool
-
True when the loaded native library exposes driver capabilities FFI API.
no setter
- supportsExecQueryMultiParams → bool
-
Whether the loaded native library exports
odbc_exec_query_multi_params(added in v3.2.0).no setter - supportsMetadataCacheApi → bool
-
True when the loaded native library exposes metadata cache FFI APIs.
no setter
- supportsMultiResultStream → bool
-
Whether the loaded native library exports the M8 streaming
multi-result FFIs (added in v3.3.0).
no setter
- supportsPoolCreateWithOptions → bool
-
Whether the loaded native library exposes the v3.0
odbc_pool_create_with_optionsentry point.no setter - supportsStructuredErrorForConnection → bool
-
Whether the native library exposes per-connection structured error API.
no setter
- supportsTransactionAccessMode → bool
-
True when the loaded native library exports
odbc_transaction_begin_v2(Sprint 4.1). Callers that intend to pass a non-defaultaccessModeshould gate on this flag; older binaries fall back to v1 andREAD ONLYbecomes a silent no-op.no setter - supportsTransactionLockTimeout → bool
-
True when the loaded native library exports
odbc_transaction_begin_v3(Sprint 4.2). Callers that intend to pass a non-defaultlockTimeoutMsshould gate on this flag; older binaries fall back to v2/v1 and the timeout becomes a silent no-op (engine default).no setter - supportsXa → bool
-
True when the loaded native library exports the XA / 2PC FFI
family (Sprint 4.3). Callers should gate on this before using
any of the xaStart / xaPrepare / etc. methods — 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 async query result payload for a completed request.
-
asyncPoll(
int requestId) → int? - Polls async request status.
-
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 a parallel bulk insert operation through
poolId. -
cancelStatement(
int stmtId) → bool - Cancels a prepared statement execution.
-
catalogColumns(
int connectionId, String table) → Uint8List? - Queries the database catalog for column information.
-
catalogForeignKeys(
int connectionId, String table) → Uint8List? - Queries the database catalog for foreign key information.
-
catalogIndexes(
int connectionId, String table) → Uint8List? - Queries the database catalog for index information.
-
catalogPrimaryKeys(
int connectionId, String table) → Uint8List? - Queries the database catalog for primary key information.
-
catalogTables(
int connectionId, {String catalog = '', String schema = ''}) → Uint8List? - Queries the database catalog for table information.
-
catalogTypeInfo(
int connectionId) → Uint8List? - Queries the database catalog for data type information.
-
clearAllStatements(
) → int - Clears all prepared statements.
-
clearAuditEvents(
) → bool - Clears all in-memory native audit events.
-
clearStatementCache(
) → bool - Clears the prepared statement cache.
-
closeStatement(
int stmtId) → bool - Closes and releases a prepared statement.
-
connect(
String connectionString) → int - Establishes a new database connection.
-
connectWithTimeout(
String connectionString, int timeoutMs) → int - Establishes a connection with a login timeout.
-
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.
-
execQuery(
int connectionId, String sql, {int? maxBufferBytes}) → Uint8List? - Executes a SQL query and returns binary result data.
-
execQueryMulti(
int connectionId, String sql, {int? maxBufferBytes}) → Uint8List? - Executes a SQL query that returns multiple result sets.
-
execQueryMultiParams(
int connectionId, String sql, Uint8List? paramsBuffer, {int? maxBufferBytes}) → Uint8List? - Executes a parameterised batch SQL that may return multiple result sets.
-
execQueryParams(
int connectionId, String sql, Uint8List? params, {int? maxBufferBytes}) → Uint8List? - Executes a SQL query with binary parameters.
-
execQueryParamsTyped(
int connectionId, String sql, List< ParamValue> params, {int? maxBufferBytes}) → Uint8List? - Executes a SQL query with typed parameters.
-
execute(
int stmtId, [Uint8List? params, int timeoutOverrideMs = 0, int fetchSize = 1000, int? maxBufferBytes]) → Uint8List? - Executes a prepared statement with optional binary parameters.
-
executeAsyncStart(
int connectionId, String sql) → int? - Starts non-blocking query execution and returns async request ID.
-
executeTyped(
int stmtId, [List< ParamValue> ? params, int timeoutOverrideMs = 0, int fetchSize = 1000, int? maxBufferBytes]) → Uint8List? - Executes a prepared statement with typed parameters.
-
execWithBuffer(
int op(Pointer< Uint8> buf, int bufLen, Pointer<Uint32> outWritten)) → Uint8List? - Re-export of the buffer-allocation helper so capability modules can reuse the same retry/grow logic used internally.
-
getAuditEventsJson(
{int limit = 0}) → String? - Gets audit events encoded as UTF-8 JSON array.
-
getAuditStatusJson(
) → String? - Gets current audit status encoded as UTF-8 JSON object.
-
getCacheMetrics(
) → PreparedStatementMetrics? - Gets prepared statement cache metrics.
-
getConnectionDbmsInfoJson(
int connectionId) → String? -
Live DBMS introspection (v2.1). Returns the JSON document produced by
odbc_get_connection_dbms_infofor the given connection id, or null when the FFI is unavailable / the call fails. -
getDriverCapabilitiesJson(
String connectionString) → String? - Gets driver capabilities from connection string as UTF-8 JSON object.
-
getError(
) → String - Gets the last error message from the native engine.
-
getMetrics(
) → OdbcMetrics? - Gets performance and operational metrics.
-
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> ? - Returns engine version (api + abi) for client compatibility checks.
-
init(
) → bool - Initializes the ODBC environment.
-
metadataCacheClear(
) → bool - Clears all metadata cache entries.
-
metadataCacheEnable(
{required int maxEntries, required int ttlSeconds}) → bool - Enables or reconfigures metadata cache in native engine.
-
metadataCacheStatsJson(
) → String? - Returns metadata cache statistics as JSON payload.
-
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.
-
poolCreate(
String connectionString, int maxSize) → int - Creates a new connection pool.
-
poolCreateWithOptions(
String connectionString, int maxSize, {String? optionsJson}) → int - Creates a pool with explicit eviction/timeout options (v3.0).
-
poolGetConnection(
int poolId) → int - Gets a connection from the pool.
-
poolGetState(
int poolId) → ({int idle, int size})? - Gets the current state of the connection pool.
-
poolGetStateJson(
int poolId) → Map< String, dynamic> ? - Gets pool state as JSON (detailed metrics for monitoring).
-
poolHealthCheck(
int poolId) → bool - Performs a health check on the connection pool.
-
poolReleaseConnection(
int connectionId) → bool - Releases a connection back to the pool.
-
poolSetSize(
int poolId, int newMaxSize) → bool -
Resizes the pool by recreating it with
newMaxSize. -
prepare(
int connectionId, String sql, {int timeoutMs = 0}) → int - Prepares a SQL statement for execution.
-
savepointCreate(
int txnId, String name) → bool - Creates a savepoint within an active transaction.
-
savepointRelease(
int txnId, String name) → bool - Releases a savepoint. The transaction remains active.
-
savepointRollback(
int txnId, String name) → bool - Rolls back to a savepoint. The transaction remains active.
-
setAuditEnabled(
{required bool enabled}) → bool - Enables or disables native audit event collection.
-
setLogLevel(
int level) → void - Sets the native engine log level (0=Off, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Trace). A logger must be initialized by the host for output to appear.
-
streamCancel(
int streamId) → bool - Requests cancellation of a batched stream.
-
streamClose(
int streamId) → bool - Closes a streaming query.
-
streamFetch(
int streamId) → StreamFetchResult - Fetches the next chunk of data from a streaming query.
-
streamMultiStartAsync(
int connectionId, String sql, {int chunkSize = 64 * 1024}) → int? - Async variant of streamMultiStartBatched. Status is observable via the existing streamPollAsync.
-
streamMultiStartBatched(
int connectionId, String sql, {int chunkSize = 64 * 1024}) → int? - Starts a streaming multi-result batch in batched mode.
-
streamPollAsync(
int streamId) → int? - Polls async stream status.
-
streamStart(
int connectionId, String sql, {int chunkSize = _defaultStreamChunkSize}) → int - Starts a streaming query.
-
streamStartAsync(
int connectionId, String sql, {int fetchSize = 1000, int chunkSize = 64 * 1024}) → int? - Starts async batched streaming query execution.
-
streamStartBatched(
int connectionId, String sql, {int fetchSize = 1000, int chunkSize = 64 * 1024}) → int - Starts a batched streaming query.
-
toString(
) → String -
A string representation of this object.
inherited
-
transactionBegin(
int connectionId, int isolationLevel, {int savepointDialect = 0, int accessMode = 0, int lockTimeoutMs = 0}) → int - Begins a new transaction with the specified isolation level.
-
transactionCommit(
int txnId) → bool - Commits a transaction.
-
transactionRollback(
int txnId) → bool - Rolls back a transaction.
-
validateConnectionString(
String connectionString) → String? - Validates connection string format without connecting.
-
xaCommitOnePhase(
int xaId) → int -
1RM optimisation: fuse
prepare → commiton an active branch when this RM is the sole participant. -
xaCommitPrepared(
int xaId) → int -
xa_commit(Phase 2) for a previously prepared branch. -
xaEnd(
int xaId) → int -
xa_end: detach the branch from the connection. Returns 0 on success, non-zero on failure. -
xaPrepare(
int xaId) → int -
xa_prepare: Phase 1 of 2PC. -
xaRecoverCount(
int connectionId) → int -
xa_recover: list every XID currently in thePreparedstate on the resource manager. Two-step protocol: this call queries the engine and returns the count; xaRecoverGet extracts the XID components by index. -
xaRecoverGet(
int index) → ({Uint8List bqual, int formatId, Uint8List gtrid})? -
Extract the XID at
indexfrom the cache populated by the most recent xaRecoverCount call. Returnsnullwhen the index is out of range or the FFI fails. -
xaResumePrepared(
{required int connectionId, required int formatId, required Uint8List gtrid, required Uint8List bqual}) → int -
Resume a previously prepared XID — rebuilds an
xa_idhandle for crash-recovery scenarios. Returns thexa_idon success,0on failure. -
xaRollbackActive(
int xaId) → int - Roll back an Active branch (no PREPARE issued). No recovery path exists after this call.
-
xaRollbackPrepared(
int xaId) → int -
xa_rollback(Phase 2) for a previously prepared branch. -
xaStart(
{required int connectionId, required int formatId, required Uint8List gtrid, required Uint8List bqual}) → int -
xa_start: open a new XA branch onconnectionIdwith the given XID components. Returns thexa_idon success,0on failure.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited