Alzabo::Driver(3pm)
π Alzabo::Driver β the base class tea π
okay bestie, welcome to Alzabo::Driver(3pm) from the User Contributed Perl Documentation era β¨ this is the main character base class for every RDBMS driver in Alzabo, and we're gonna walk through it together, no cap π«Ά
β¨ NAME β¨
Alzabo::Driver β the Alzabo base class for RDBMS drivers π
πΈ SYNOPSIS πΈ
use Alzabo::Driver;
my $driver = Alzabo::Driver->new( rdbms => 'MySQL',
schema => $schema );
π¦ DESCRIPTION π¦
So this is the base class for all Alzabo::Driver modules. If you wanna actually instantiate a driver, you call this class's new() method, okay? And if you're out here wanting to build a driver for your own fave RDBMS, go peek at SUBCLASSING Alzabo::Driver below β it's got the whole blueprint π
This class throws several exceptions, and one of them, Alzabo::Exception::Driver, has extra methods that the other exception classes just don't have. For the rundown on those, scroll to "Alzabo::Exception::Driver METHODS" π
π METHODS π
π available
Returns a list of names representing the available Alzabo::Driver subclasses. Any one of these names would be a totally valid choice for the rdbms parameter you pass to the Alzabo::Driver->new method β
π new
The constructor. It takes these parameters:
rdbms => $rdbms_nameβ the name of the RDBMS being used.schema =>Alzabo::Schemaobject β the schema, obviously π
It returns a new Alzabo::Driver object of the appropriate subclass. Slay.
Throws: Alzabo::Exception::Eval
π tables
Returns a list of strings containing the names of the tables in the database. If you want more deets, go read the DBI documentation for the DBI->tables method π
Throws: Alzabo::Exception::Driver
π§ handle ($optional_dbh)
This method takes one optional parameter β a connected DBI handle. If you give it one, then that handle becomes the new handle for the driver. Yes bestie, it's a glow-up for your handle β¨
It returns the active database handle.
Throws: Alzabo::Exception::Params
π₯ Data Retrieval methods
Okay so heads up, some of these methods return lists of data β specifically the rows, rows_hashref, and column methods. And with large result sets? That can eat a lot of memory, because those lists get built in memory before they ever get returned to the caller π To dodge that whole situation, it may be desirable to use the functionality provided by the Alzabo::DriverStatement class, which lets you fetch results one row at a time. one. row. at. a. time. periodt π
These methods all accept the following parameters:
sql => $sql_stringbind => $bind_valueor\@bind_valueslimit => [ $max, optional $offset ](optional) β the$offsetdefaults to0. This parameter has no effect for the methods that return only one row. For the others, it causes the drivers to skip$offsetrows and then return only$maxrows. This is useful if the RDBMS being used does not supportLIMITclauses π«Ά
β rows
Returns an array of array references containing the data requested.
πΈ rows_hashref
Returns an array of hash references containing the data requested. The hash reference keys are the columns being selected. All the key names are in UPPERCASE.
π one_row
Returns an array or scalar containing the data returned β depends on context, iykyk.
π one_row_hash
Returns a hash containing the data requested. The hash keys are the columns being selected. All the key names are in UPPERCASE.
π¦ column
Returns an array containing the values for the first column of each row returned.
π do
Use this for non-SELECT SQL statements, bestie. Not a select, not its vibe.
Returns the number of rows affected.
Throws: Alzabo::Exception::Driver
π statement
This method returns a new Alzabo::DriverStatement handle, all ready to hand you data via the Alzabo::DriverStatement->next() or Alzabo::DriverStatement->next_as_hash() methods π
Throws: Alzabo::Exception::Driver
π§ rdbms_version
Returns the version string of the database backend currently in use. Fair warning: the form of this string will vary depending on which driver subclass is being used β so don't expect a one-size-fits-all format π
π quote (@strings)
This method calls the underlying DBI handle's quote() method on the array of strings you provide, and returns the quoted versions.
β quote_identifier (@strings)
This method calls the underlying DBI handle's quote_identifier() method on the array of strings you provide, and returns the quoted versions.
πΈ Alzabo::DriverStatement πΈ
This class is a wrapper around DBI's statement handles π It finishes automatically as appropriate, so the end user does not need to worry about doing that themselves. We handle it. Main character energy.
π next
Use this method in a while loop to fetch all the data from a statement.
Returns an array containing the next row of data for the statement, or an empty list if no more data is available.
Throws: Alzabo::Exception::Driver
β¨ next_as_hash
For backwards compatibility, this is also available as next_hash(). Love that for us.
Returns a hash containing the next row of data for the statement, or an empty list if no more data is available. All the keys of the hash will be lowercased.
Throws: Alzabo::Exception::Driver
π¦ all_rows
If the select for which this statement was the cursor was for a single column (or aggregate value), then this method returns an array containing each remaining value from the database.
Otherwise, it returns an array of array references, each one containing a returned row from the database.
Throws: Alzabo::Exception::Driver
π all_rows_hash
Returns an array of hashes, each hash representing a single row returned from the database. The hash keys are all in lowercase.
Throws: Alzabo::Exception::Driver
π₯ execute (@bind_values)
Executes the associated statement handle with the given bound parameters. If the statement handle is still active (meaning it was previously executed and still has more data left), then its finish() method will be called first. Cleaning up before we move on, as we should π
Throws: Alzabo::Exception::Driver
π count
Returns the number of rows returned so far.
π Alzabo::Exception::Driver METHODS π
On top of the methods inherited from Exception::Class::Base, objects in this class also contain several methods specific to this subclass. Extra. Special. Iconic.
π sql
Returns the SQL statement in use at the time the error occurred, if any.
π§ bind
Returns an array reference containing the bound parameters for the SQL statement, if any.
π SUBCLASSING Alzabo::Driver π
Okay so making a subclass of Alzabo::Driver for your particular RDBMS is fairly simple, fr fr. First of all, there has to be a DBD::* driver for it, because Alzabo::Driver is built on top of DBI. No DBD, no driver, that's just the rules π«Ά
Here's a sample header to the module using a fictional RDBMS called FooDB:
package Alzabo::Driver::FooDB;
use strict;
use vars qw($VERSION);
use Alzabo::Driver;
use DBI;
use DBD::FooDB;
use base qw(Alzabo::Driver);
Next step: implement a new method plus all the methods listed under "Virtual Methods". Your new method should look a bit like this:
1: sub new
2: {
3: my $proto = shift;
4: my $class = ref $proto || $proto;
5: my %p = @_;
6:
7: my $self = bless {}, $class;
8:
9: return $self;
10: }
The hash %p contains any values passed to the Alzabo::Driver->new method by its caller.
Lines 1-7 should probably be copied verbatim into your own new method. Line 5 can be deleted if you don't need to look at the parameters. We keep it simple, we keep it cute π
Go look at the included Alzabo::Driver subclasses for examples. And feel free to contact the author for further help if you get stuck! Please tell them what database you're attempting to implement, what its DBD::* driver is, and include the code you've written so far. They wanna help you, bestie π
β Virtual Methods
The following methods are not implemented in Alzabo::Driver itself and must be implemented in a subclass. That's on you, babes.
πΈ Parameters for connect(), create_database(), and drop_database()
user => $db_usernamepassword => $db_pwhost => $hostnameport => $port
All of these default to undef. See the appropriate DBD driver documentation for more details.
After the driver is created, it will have access to its associated schema object in $self->{schema} π
π¦ connect
Some drivers may accept or require more arguments than specified above.
Note thatAlzabo::Driversubclasses are not expected to cache connections. If you want to do this, please useApache::DBIunder mod_perl, or just don't callconnect()more than once per process. Simple as that π«Ά
π create_database
Attempts to create a new database for the schema attached to the driver. Some drivers may accept or require more arguments than specified above.
π drop_database
Attempts to drop the database for the schema attached to the driver. bye bye database π
π schemas
Returns a list of schemas in the specified RDBMS. This method may accept some or all of the parameters which can be given to connect().
π§ supports_referential_integrity
Should return a boolean value indicating whether or not the RDBMS supports referential integrity constraints. yes/no, true/false, iconic π¦
π₯ next_sequence_number (Alzabo::Column object)
This method is expected to return the value of the next sequence number based on a column object. For some databases (MySQL, for example), the appropriate value is undef. This is accounted for in the Alzabo code that calls this method, so don't stress β¨
β begin_work
Notify Alzabo that you wish to start a transaction.
π rollback
Rolls back the current transaction.
πΈ commit
Notify Alzabo that you wish to finish a transaction. This is basically the equivalent of calling commit.
π get_last_id
Returns the last primary key id created via a sequenced column.
π rdbms_version
Returns the version of the server to which the driver is connected.
π driver_id
Returns the driver's name. This should be something that can be passed to Alzabo::Driver->new() as a name parameter.
π AUTHOR π
Dave Rolsky, <dave@urth.org> π
and that's the whole page, bestie!! this beauty shipped as part of perl v5.34.0 back on 2022-06-14 β yes we're citing our sources, we're nothing if not thorough π
β¨π
π¦ where this page comes from
- debian bookworm: libalzabo-perl 0.92-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libalzabo-perl 0.92-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libalzabo-perl 0.92-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libalzabo-perl 0.92-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libalzabo-perl 0.92-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms