Name

SPVM::DBI::Db - Database Handle

Description

DBI::Db class in SPVM represents a database handle. This class is a base class for database handles, and each method is expected to be overridden in child classes like DBI::Db::SQLite.

Usage

class DBD::MyDriver::Db extends DBI::Db {
  
  # Overriding the prepare method
  method prepare : DBI::St ($ctx : Go::Context, $sql : string, $options : object[] = undef) {
    
    my $sth = DBD::MyDriver::St->new;
    
    # Call the common preparation logic provided by the base class
    $self->prepare_common($sth, $ctx, $sql, $options);
    
    # Implement the driver-specific logic to prepare a statement
    # ...
    
    return $sth;
  }
  
}

Fields

Name

has Name : ro string;

The data source name (DSN). This field stores the part of the DSN after the second colon (e.g., "dbname=:memory:" if the DSN is "dbi:SQLite:dbname=:memory:").

Username

has Username : ro string;

The username for the database connection. This field stores the username extracted from the DSN.

AutoCommit

has AutoCommit : ro byte;

The AutoCommit status.

The default value is set to 1. Driver authors must ensure that the initial database connection state matches this default (i.e., transactions are automatically committed after each statement).

InactiveDestroy

has InactiveDestroy : rw byte;

The InactiveDestroy status.

IdleTimeoutDurationNsec

has IdleTimeoutDurationNsec : rw long;

The maximum duration that a connection can remain idle, in nanoseconds. If the idle time exceeds this duration, the connection is expected to be closed, typically by a connection pool.

ConnectTimeoutDurationNsec

has ConnectTimeoutDurationNsec : rw long;

The timeout value for establishing a new database connection, in nanoseconds.

ReadTimeoutDurationNsec

has ReadTimeoutDurationNsec : rw long;

The timeout value for read operations, in nanoseconds. If a read operation does not complete within this duration, the operation is canceled.

WriteTimeoutDurationNsec

has WriteTimeoutDurationNsec : rw long;

The timeout value for write operations, in nanoseconds. If a write operation does not complete within this duration, the operation is canceled.

SocketKeepAliveDurationNsec

has SocketKeepAliveDurationNsec : rw long;

The duration for TCP keep-alive idle time, in nanoseconds.

If this field is not explicitly set, it is recommended that the driver calls apply_modern_tcp_settings (or a similar method) to apply the modern default value. Set to 0 to explicitly disable keep-alive.

TCPNoDelay

has TCPNoDelay : rw byte;

The TCP_NODELAY status.

A boolean value (1 or 0). If this field is not explicitly set, it is recommended that the driver calls apply_modern_tcp_settings (or a similar method) to apply the modern default (usually 1). If set to 1, Nagle's algorithm is disabled, which ensures that small database query packets are sent immediately without delay.

Instance Methods

prepare

method prepare : DBI::St ($ctx : Go::Context, $sql : string, $options : object[] = undef)

In a child class, this method must prepare the SQL statement and return a statement handle (DBI::St).

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

begin_work

method begin_work : void ($ctx : Go::Context)

In a child class, this method must start a new transaction.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

commit

method commit : void ($ctx : Go::Context)

In a child class, this method must commit the current transaction.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

rollback

method rollback : void ($ctx : Go::Context)

In a child class, this method must roll back the current transaction.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

last_insert_id

method last_insert_id : object ($ctx : Go::Context, $catalog : string = undef, $schema : string = undef, $table : string = undef, $field : string = undef, $options : object[] = undef)

In a child class, this method must return the ID of the last inserted row.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

ping

method ping : int ($ctx : Go::Context)

In a child class, this method must check if the database connection is still alive.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

get_info

method get_info : object ($ctx : Go::Context, $info_type : int)

In a child class, this method must return information about the database.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

table_info

method table_info : DBI::St ($ctx : Go::Context, $catalog : string, $schema : string, $table : string, $type : string, $options : object[] = undef)

In a child class, this method must return a statement handle containing information about tables.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

column_info

method column_info : DBI::St ($ctx : Go::Context, $catalog : string, $schema : string, $table : string, $column : string)

In a child class, this method must return a statement handle containing information about columns.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

quote

method quote : string ($ctx : Go::Context, $str : string, $type : int = -1)

In a child class, this method must quote a string for use in a SQL statement.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

quote_identifier

method quote_identifier : string ($ctx : Go::Context, $catalog : string, $schema : string, $table : string, $options : object[] = undef)

In a child class, this method must quote an identifier for use in a SQL statement.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

disconnect

method disconnect : void ()

In a child class, this method is expected to disconnect from the database.

Exceptions:

Always throws a DBI::Error::SQLState exception whose message begins with a 5-character SQLSTATE "IM001" because this method is not implemented.

DESTROY

method DESTROY : void ()

The destructor. Unless "InactiveDestroy" is true, it calls "disconnect".

See Also

DBI, DBI::St, Go::Context

Repository

https://github.com/yuki-kimoto/SPVM-DBI

Author

Yuki Kimoto kimoto.yuki@gmail.com

Copyright & License

Copyright (c) 2026 Yuki Kimoto

MIT License