ODBCDbc¶
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
Implements¶
- SqlState ref
Public fields¶
var dbc: ODBCHandleDbc tag¶
var strict: Bool val¶
Public Functions¶
stmt¶
Used to create an ODBCStmt object from this ODBCDbc connection.
Parameters¶
- sl: SourceLoc val = __loc
Returns¶
- ODBCStmt ref ?
sqlstates¶
Returns an array of SQL States
Returns¶
get_autocommit¶
Returns whether autocommit is enabled or disabled.
Parameters¶
- sl: SourceLoc val = __loc
Returns¶
- Bool val ?
set_autocommit¶
Enables or disables autocommit. Many RDBMSs require that this be configured before you initiate the actual connection with connect()?
Parameters¶
Returns¶
- Bool val ?
commit¶
Instructs the database to commit your transaction and open a new one.
Parameters¶
- sl: SourceLoc val = __loc
Returns¶
- Bool val ?
rollback¶
Instructs the database to rollback your transaction and open a new one.
Parameters¶
- sl: SourceLoc val = __loc
Returns¶
- Bool val ?
get_info_varchar¶
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¶
- Bool val ?
connect¶
Initiates the database connection to the database as defined by the DSN.
Parameters¶
Returns¶
- Bool val ?
error_chain¶
Access the error chain for inspection.
Returns¶
- ODBCErrorChain box
last_error¶
Convenience method: get the most recent error frame.
Returns¶
- (ODBCErrorFrame val | None val)
configure_error_chain¶
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¶
Returns¶
- None val
all_errors¶
Returns this connection's errors plus all statement errors, sorted by sequence.
Returns¶
- Array[ODBCErrorFrame val] val
disconnect¶
Disconnects the database connection from the database.
Parameters¶
- sl: SourceLoc val = __loc
Returns¶
- Bool val ?
is_connected¶
Returns true if the connection is currently connected to a database.
Returns¶
- Bool val
connection_epoch¶
Returns the connection epoch. This increments each time connect() is called. Used internally to track statement validity across reconnections.
Returns¶
- USize val