Name
SPVM::DBI::Dr - Driver Handle
Description
DBI::Dr class in SPVM represents a driver handle. This class is a base class for driver handles, and each method is expected to be overridden in child classes like DBD::SQLite::Dr.
Usage
class DBD::MyDriver::Dr extends DBI::Dr {
# Overriding the connect method
method connect : DBI::Db ($ctx : Go::Context, $dsn : string, $user : string = undef, $password : string = undef, $options : object[] = undef) {
my $dbh = DBD::MyDriver::Db->new;
# Call the common connection logic provided by the base class
$self->connect_common($dbh, $ctx, $dsn, $user, $password, $options);
# Implement the driver-specific logic to connect to a database
# ...
return $dbh;
}
}
Instance Methods
connect
method connect : DBI::Db ($ctx : Go::Context, $dsn : string, $user : string = undef, $password : string = undef, $options : object[] = undef)
In a child class, this method must establish a database connection and return a database handle (DBI::Db).
Exceptions:
Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.
connect_common
protected method connect_common : void ($dbh : DBI::Db, $ctx : Go::Context, $dsn : string, $user : string = undef, $password : string = undef, $options : object[] = undef)
This method provides common initialization logic for a database handle. It is intended to be called by driver authors within their connect implementation.
This method performs the following tasks:
Validates the option names in
$optionsusing option_names.Parses the DSN to extract the database name and username.
Sets the AutoCommit field of
$dbhto 1.If an option exists in
$options, its value is mapped to the corresponding field in$dbh. The mapped fields include:By using
existscheck internally, this method allows driver authors to distinguish whether a field was explicitly set by the user or should be initialized with a modern default.
option_names
protected method option_names : string[] ()
Returns an array of supported option names for the database handle.
In the base class DBI::Db, this method returns the following default options:
InactiveDestroyIdleTimeoutDurationNsecConnectTimeoutDurationNsecReadTimeoutDurationNsecWriteTimeoutDurationNsecSocketKeepAliveDurationNsecTCPNoDelay
Driver authors can override this method to add driver-specific options. These names are used by connect_common or prepare_common to validate the options provided by the user via Fn#check_option_names.
See Also
Repository
https://github.com/yuki-kimoto/SPVM-DBI
Author
Yuki Kimoto kimoto.yuki@gmail.com
Copyright & License
Copyright (c) 2026 Yuki Kimoto
MIT License