transactionBegin method

int transactionBegin(
  1. int connectionId,
  2. int isolationLevel, {
  3. int savepointDialect = 0,
  4. int accessMode = 0,
  5. int lockTimeoutMs = 0,
})

Begins a new transaction with the specified isolation level.

The connectionId must be a valid active connection. The isolationLevel should be a numeric value (0-3 — see IsolationLevel). The savepointDialect is the wire code from SavepointDialect.code (default 0 = auto, resolved on the Rust side via SQLGetInfo). The accessMode is the wire code from TransactionAccessMode.code (default 0 = readWrite). When the loaded native library predates Sprint 4.1 the parameter is silently ignored — see supportsTransactionAccessMode. The lockTimeoutMs is the per-transaction lock timeout in milliseconds (default 0 = engine default). Sprint 4.2. When the loaded native library predates Sprint 4.2 the parameter is silently ignored — see supportsTransactionLockTimeout.

Returns a transaction ID on success, 0 on failure.

Implementation

int transactionBegin(
  int connectionId,
  int isolationLevel, {
  int savepointDialect = 0,
  int accessMode = 0,
  int lockTimeoutMs = 0,
}) {
  if (accessMode == 0 && lockTimeoutMs == 0) {
    // Stay on the v1 entry-point when the caller is OK with every
    // engine default. Avoids touching v2/v3 at all so any FFI
    // mismatch surfaces only when the caller actually asks for the
    // newer features.
    return _bindings.odbc_transaction_begin(
      connectionId,
      isolationLevel,
      savepointDialect,
    );
  }
  if (lockTimeoutMs == 0) {
    // Caller wants accessMode but not the timeout — stay on v2 so
    // we don't require a v3 binary unnecessarily.
    return _bindings.odbc_transaction_begin_v2(
      connectionId,
      isolationLevel,
      savepointDialect,
      accessMode,
    );
  }
  return _bindings.odbc_transaction_begin_v3(
    connectionId,
    isolationLevel,
    savepointDialect,
    accessMode,
    lockTimeoutMs,
  );
}