Skip to content

ODBCDbc

[Source]

ODBCDbc

The class that wraps our ODBC Database handle.

Usage

var env: ODBCEnv = ODBCEnv
var dbc: ODBCDbc = env.dbc()?

// Disable autocommit, set application name, and connect to database
try
  dbc
  .> set_autocommit(false)?         // Disable Autocommit
  .> connect("mydsn")?              // Connect to DSN "mydsn"
else
  Debug.out("We failed.")
end

An example that demonstrates .commit() and .rollback() will be documented in ODBCStmt as that requires an appropriate context to make sense.

Error Handling

ODBCDbc maintains an error chain that records all errors during connection operations. You can also access errors from all child statements via all_errors():

// Get just this connection's errors
for err in dbc.error_chain().values() do
  env.err.print(err.string())
end

// Get all errors including child statements, sorted by sequence
for err in dbc.all_errors().values() do
  env.err.print(err.string())
end
class ref ODBCDbc is
  SqlState ref

Implements


Public fields

var dbc: ODBCHandleDbc tag

[Source]


var strict: Bool val

[Source]


Public Functions

stmt

[Source]

Used to create an ODBCStmt object from this ODBCDbc connection.

fun ref stmt(
  sl: SourceLoc val = __loc)
: ODBCStmt ref ?

Parameters

Returns


sqlstates

[Source]

Returns an array of SQL States

fun box sqlstates()
: Array[(String val , String val)] val

Returns


get_autocommit

[Source]

Returns whether autocommit is enabled or disabled.

fun ref get_autocommit(
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


set_autocommit

[Source]

Enables or disables autocommit. Many RDBMSs require that this be configured before you initiate the actual connection with connect()?

fun ref set_autocommit(
  setting: Bool val,
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


commit

[Source]

Instructs the database to commit your transaction and open a new one.

fun ref commit(
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


rollback

[Source]

Instructs the database to rollback your transaction and open a new one.

fun ref rollback(
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


get_info_varchar

[Source]

SQLGetInfo returns general information about the driver and data source associated with a connection.

fun ref get_info_varchar(
  infotype: U16 val,
  buf: SQLType ref,
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


connect

[Source]

Initiates the database connection to the database as defined by the DSN.

fun ref connect(
  dsn: String val,
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


error_chain

[Source]

Access the error chain for inspection.

fun box error_chain()
: ODBCErrorChain box

Returns


last_error

[Source]

Convenience method: get the most recent error frame.

fun box last_error()
: (ODBCErrorFrame val | None val)

Returns


configure_error_chain

[Source]

Configure error chain behavior.

  • max_frames: Maximum number of frames to store (default: 100)
  • auto_clear: Clear chain on prepare()/finish() (default: true)
  • log_success: Also record successful operations (default: false)
fun ref configure_error_chain(
  max_frames: USize val = 100,
  auto_clear: Bool val = true,
  log_success: Bool val = false)
: None val

Parameters

  • max_frames: USize val = 100
  • auto_clear: Bool val = true
  • log_success: Bool val = false

Returns


all_errors

[Source]

Returns this connection's errors plus all statement errors, sorted by sequence.

fun box all_errors()
: Array[ODBCErrorFrame val] val

Returns


disconnect

[Source]

Disconnects the database connection from the database.

fun ref disconnect(
  sl: SourceLoc val = __loc)
: Bool val ?

Parameters

Returns


is_connected

[Source]

Returns true if the connection is currently connected to a database.

fun box is_connected()
: Bool val

Returns


connection_epoch

[Source]

Returns the connection epoch. This increments each time connect() is called. Used internally to track statement validity across reconnections.

fun box connection_epoch()
: USize val

Returns