DBI::DB...qlEngine(3)
π DBI::DBD::SqlEngine(3) β User Contributed Perl Documentation π
okay so you're here for DBI::DBD::SqlEngine(3) and bestie, you came to the right place β¨ this is the page where we learn how to build a whole DBI driver without dragging your own SQL engine along for the ride.
β¨ NAME β¨
DBI::DBD::SqlEngine β the base class for DBI drivers that don't have their own SQL engine π
π¦ SYNOPSIS π¦
like, here's the whole vibe of what a driver built on this looks like, no cap:
package DBD::myDriver;
use base qw(DBI::DBD::SqlEngine);
sub driver {
...
my $drh = $proto->SUPER::driver ($attr);
...
return $drh->{class};
}
package DBD::myDriver::dr;
our @ISA = qw(DBI::DBD::SqlEngine::dr);
sub data_sources { ... }
...
package DBD::myDriver::db;
our @ISA = qw(DBI::DBD::SqlEngine::db);
sub init_valid_attributes { ... }
sub init_default_attributes { ... }
sub set_versions { ... }
sub validate_STORE_attr { my ($dbh, $attrib, $value) = @_; ... }
sub validate_FETCH_attr { my ($dbh, $attrib) = @_; ... }
sub get_myd_versions { ... }
sub get_avail_tables { ... }
package DBD::myDriver::st;
our @ISA = qw(DBI::DBD::SqlEngine::st);
sub FETCH { ... }
sub STORE { ... }
package DBD::myDriver::Statement;
our @ISA = qw(DBI::DBD::SqlEngine::Statement);
sub open_table { ... }
package DBD::myDriver::Table;
our @ISA = qw(DBI::DBD::SqlEngine::Table);
sub new { ... }
π DESCRIPTION π
so DBI::DBD::SqlEngine abstracts the usage of SQL engines away from the DBD π«Ά that means you, the DBD author, get to concentrate on the data retrieval you actually want to provide. main character energy fr.
it is strongly recommended that you read DBD::File::Developers and DBD::File::Roadmap, because a lot of the DBD::File API is provided by DBI::DBD::SqlEngine π
currently the API of DBI::DBD::SqlEngine is experimental and will likely change in the near future to provide the table meta data basics like DBD::File π (we're all just living in it).
DBI::DBD::SqlEngine expects that any driver in the inheritance chain has a DBI prefix π
πΈ Metadata πΈ
the following attributes are handled by DBI itself and not by DBI::DBD::SqlEngine, so they all work as expected, periodt:
Active
ActiveKids
CachedKids
CompatMode (Not used)
InactiveDestroy
AutoInactiveDestroy
Kids
PrintError
RaiseError
Warn (Not used)
the following DBI attributes are handled by DBI::DBD::SqlEngine:
AutoCommitβ always on. no off switch, it's committed to commitment πChopBlanksβ works. slay β¨NUM_OF_FIELDSβ valid after$sth->execute.NUM_OF_PARAMSβ valid after$sth->prepare.NAMEβ valid after$sth->execute; probablyundeffor Non-Select statements πNULLABLEβ not really working, always returns an array ref of ones, asDBD::CSVdoes not verify input data. valid after$sth->execute;undeffor non-select statements. it's giving "sure bestie whatever you say" energy π
the following DBI attributes and methods are not supported, sorry babes:
bind_param_inout
CursorName
LongReadLen
LongTruncOk
π DBI::DBD::SqlEngine specific attributes π
in addition to the DBI attributes, you can use the following dbh attributes:
sql_engine_versionβ contains the module version of this driver (readonly).sql_nano_versionβ contains the module version ofDBI::SQL::Nano(readonly).sql_statement_versionβ contains the module version ofSQL::Statement, if available (readonly).sql_handlerβ contains the SQL Statement engine, eitherDBI::SQL::NanoorSQL::Statement(readonly).sql_parser_objectβ contains an instantiated instance ofSQL::Parser(readonly). this is filled when used first time (only when used withSQL::Statement).sql_sponge_driverβ contains an internally usedDBD::Spongehandle (readonly).sql_valid_attrsβ contains the list of valid attributes for eachDBI::DBD::SqlEnginebased driver (readonly).sql_readonly_attrsβ contains the list of those attributes which are readonly (readonly). (yes, the readonly list is itself readonly, iconic π )sql_identifier_caseβ contains howDBI::DBD::SqlEnginedeals with non-quoted SQL identifiers:SQL_IC_UPPER(1) means all identifiers are internally converted into upper-cased pendantsSQL_IC_LOWER(2) means all identifiers are internally converted into lower-cased pendantsSQL_IC_MIXED(4) means all identifiers are taken as they are
these conversions happen if (and only if) no existing identifier matches. once existing identifier is used as known.
the SQL statement execution classes doesn't have to care, so don't expect sql_identifier_case to affect column names in statements like
SELECT * FROM foo
sql_quoted_identifier_caseβ contains howDBI::DBD::SqlEnginedeals with quoted SQL identifiers (readonly). it's fixated toSQL_IC_SENSITIVE(3), which is interpreted asSQL_IC_MIXED.sql_flagsβ contains additional flags to instantiate anSQL::Parser. because anSQL::Parseris instantiated only once, it's recommended to set this flag before any statement is executed.sql_dialectβ controls the dialect understood bySQL::Parser. possible values (delivery state ofSQL::Statement):ANSICSVAnyData
defaults to "CSV". because an SQL::Parser is instantiated only once and SQL::Parser doesn't allow one to modify the dialect once instantiated, it's strongly recommended to set this flag before any statement is executed (best place is the connect attribute hash).
sql_engine_in_goferβ this value has a true value in case of this driver is operated viaDBD::Gofer. the impact of being operated via Gofer is a read-only driver (not read-only databases!), so you cannot modify any attributes later β neither any table settings. but you won't get an error in cases you modify table attributes, so please carefully watchsql_engine_in_goferπ
bestie this one is sneaky. it'll silently not do the thing. watch it like a hawk π¦
sql_metaβ private data area which contains information about the tables this module handles. table meta data might not be available until the table has been accessed for the first time, e.g., by issuing a select on it β however it is possible to pre-initialize attributes for each table you use.
DBI::DBD::SqlEngine recognizes the (public) attributes col_names, table_name, readonly, sql_data_source and sql_identifier_case. be very careful when modifying attributes you do not know, the consequence might be a destroyed or corrupted table π
while sql_meta is a private and readonly attribute (which means, you cannot modify it's values), derived drivers might provide restricted write access through another attribute. well known accessors are csv_tables for DBD::CSV, ad_tables for DBD::AnyData and dbm_tables for DBD::DBM.
sql_table_sourceβ controls the class which will be used for fetching available tables.
see DBI::DBD::SqlEngine::TableSource for details π
sql_data_sourceβ contains the class name to be used for opening tables.
see DBI::DBD::SqlEngine::DataSource for details β¨
π Driver private methods π
Default DBI methods
data_sourcesβ thedata_sourcesmethod returns a list of subdirectories of the current directory in the formdbi:CSV:f_dir=$dirname.
if you want to read the subdirectories of another directory, use:
my ($drh) = DBI->install_driver ("CSV");
my (@list) = $drh->data_sources (f_dir => "/usr/local/csv_data");
list_tablesβ this method returns a list of file names inside$dbh->{f_dir}. example:
my ($dbh) = DBI->connect ("dbi:CSV:f_dir=/usr/local/csv_data");
my (@list) = $dbh->func ("list_tables");
note that the list includes all files contained in the directory, even those that have non-valid table names, from the view of SQL π«
Additional methods
the following methods are only available via their documented name when DBI::DBD::SQlEngine is used directly. because this is only reasonable for testing purposes, the real names must be used instead. those names can be computed by replacing the sql_ in the method name with the driver prefix π
sql_versions
signature:
sub sql_versions (;$) {
my ($table_name) = @_;
$table_name ||= ".";
...
}
returns the versions of the driver, including the DBI version, the Perl version, DBI::PurePerl version (if DBI::PurePerl is active) and the version of the SQL engine in use.
my $dbh = DBI->connect ("dbi:File:");
my $sql_versions = $dbh->func( "sql_versions" );
print "$sql_versions\n";
__END__
# DBI::DBD::SqlEngine 0.05 using SQL::Statement 1.402
# DBI 1.623
# OS netbsd (6.99.12)
# Perl 5.016002 (x86_64-netbsd-thread-multi)
called in list context, sql_versions will return an array containing each line as single entry.
some drivers might use the optional (table name) argument and modify version information related to the table (e.g. DBD::DBM provides storage backend information for the requested table, when it has a table name) π
sql_get_meta
signature:
sub sql_get_meta ($$) {
my ($table_name, $attrib) = @_;
...
}
returns the value of a meta attribute set for a specific table, if any. see sql_meta for the possible attributes.
a table name of "." (single dot) is interpreted as the default table. this will retrieve the appropriate attribute globally from the dbh. this has the same restrictions as $dbh->{$attrib} π
sql_set_meta
signature:
sub sql_set_meta ($$$) {
my ($table_name, $attrib, $value) = @_;
...
}
sets the value of a meta attribute set for a specific table. see sql_meta for the possible attributes.
a table name of "." (single dot) is interpreted as the default table which will set the specified attribute globally for the dbh. this has the same restrictions as $dbh->{$attrib} = $value.
sql_clear_meta
signature:
sub sql_clear_meta ($) {
my ($table_name) = @_;
...
}
clears the table specific meta information in the private storage of the dbh π§Ήβ¨
π Extensibility π
DBI::DBD::SqlEngine::TableSource
provides data sources and table information on database driver and database handle level π
package DBI::DBD::SqlEngine::TableSource;
sub data_sources ($;$) {
my ($class, $drh, $attrs) = @_;
...
}
sub avail_tables {
my ( $class, $drh ) = @_;
...
}
the data_sources method is called when the user invokes any of the following:
@ary = DBI->data_sources ($driver);
@ary = DBI->data_sources ($driver, \%attr);
@ary = $dbh->data_sources ();
@ary = $dbh->data_sources (\%attr);
the avail_tables method is called when the user invokes any of the following:
@names = $dbh->tables ($catalog, $schema, $table, $type);
β¨ okay bestie, we're back β¨ and we're picking up right where we left off. No recap, no fluff, let's get into it π
So, table_info can be called like this:
$sth = $dbh->table_info ($catalog, $schema, $table, $type);
$sth = $dbh->table_info ($catalog, $schema, $table, $type, \%attr);
$dbh->func ("list_tables");
And listen: any time there's a \%attr argument you can pass in, that \%attr object's sql_table_source attribute gets priority over the $dbh attribute or the driver default. Like, it wins. straight up:
@ary = DBI->data_sources ("dbi:CSV:", {
f_dir => "/your/csv/tables",
# note: this class doesn't comes with DBI
sql_table_source => "DBD::File::Archive::Tar::TableSource",
# scan tarballs instead of directories
});
πΈ So if you're out here building your own DBD::File::Archive::Tar::TableSource class, remember to add the correct attributes (including sql_table_source and sql_data_source) to the DSN's you return. Don't forget, bestie, it's giving β¨incompleteβ¨ otherwise.
DBI::DBD::SqlEngine::DataSource
This one provides the base functionality for dealing with tables π«Ά It's primarily designed to let you transparently access files on disk or already-opened (file-)streams (e.g. for DBD::CSV).
Derived classes shall be restricted to similar functionality, too (e.g. opening streams from an archive, transparently compress/uncompress log files before parsing them,
package DBI::DBD::SqlEngine::DataSource;
sub complete_table_name ($$;$) {
my ($self, $meta, $table, $respect_case) = @_;
...
}
The method complete_table_name is called when first setting up the meta information for a table:
"SELECT user.id, user.name, user.shell FROM user WHERE ..."
β¦and that results in opening the table user π First step of the table open process is completing the name. So picture this: you've got a DBD::CSV handle with these settings:
$dbh->{sql_identifier_case} = SQL_IC_LOWER;
$dbh->{f_ext} = '.lst';
$dbh->{f_dir} = '/data/web/adrmgr';
Those settings will result in looking for files matching [Uu][Ss][Ee][Rr](\.lst)?$ in /data/web/adrmgr/. The scanning of the directory /data/web/adrmgr/ and the pattern match check will be done in DBD::File::DataSource::File by the complete_table_name method. iykyk π
Now β if you intend to provide other sources of data streams than files, in addition to providing an appropriate complete_table_name method, you also need a method to open the resource:
package DBI::DBD::SqlEngine::DataSource;
sub open_data ($) {
my ($self, $meta, $attrs, $flags) = @_;
...
}
After the method open_data has been run successfully, the table's meta information is in a state which allows the table's data accessor methods to be able to fetch/store row information. The implementation details heavily depend on the table implementation, whereby the most famous is surely DBD::File::Table. iconic fr fr π₯
SQL ENGINES π§
DBI::DBD::SqlEngine currently supports two SQL engines: SQL::Statement and DBI::SQL::Nano::Statement_. DBI::SQL::Nano supports a very limited subset of SQL statements, but it might be faster for some very simple tasks. SQL::Statement, in contrast, supports a much larger subset of ANSI SQL. slay π
To use SQL::Statement, you need at least version 1.401 of SQL::Statement and the environment variable DBI_SQL_NANO must not be set to a true value. that's the vibe check right there β
SUPPORT π«Ά
You can find documentation for this module with the perldoc command.
perldoc DBI::DBD::SqlEngine
You can also look for information at:
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBI>
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Statement>
- CPAN Ratings
<http://cpanratings.perl.org/d/DBI>
- Search CPAN
<http://search.cpan.org/dist/DBI/>
Where can I go for more help? π
For questions about installation or usage, please ask on the dbi-dev@perl.org mailing list. bestie the mailing list is right there, use it πΈ
If you have a bug report, patch or suggestion, please open a new report ticket on CPAN, if there is not already one for the issue you want to report. Of course, you can mail any of the module maintainers, but it is less likely to be missed if it is reported on RT. (translation: RT is the main character here, emails get lost in the group chat)
Report tickets should contain a detailed description of the bug or enhancement request you want to report and at least an easy way to verify/reproduce the issue and any supplied fix. Patches are always welcome, too. no cap, we love a patch π
ACKNOWLEDGEMENTS π
Thanks to Tim Bunce, Martin Evans and H.Merijn Brand for their continued support while developing DBD::File, DBD::DBM and DBD::AnyData. Their support, hints and feedback helped to design and implement this module. genuinely so grateful π«Άβ¨
AUTHOR π
This module is currently maintained by
H.Merijn Brand < perl5 at tux.freedom.nl > and Jens Rehsack < rehsack at googlemail.com >
The original authors are Jochen Wiedmann and Jeff Zucker. legends, honestly β
COPYRIGHT AND LICENSE π
Copyright (C) 2009-2026 by H.Merijn Brand & Jens Rehsack
Copyright (C) 2004-2009 by Jeff Zucker
Copyright (C) 1998-2004 by Jochen Wiedmann
All rights reserved.
You may freely distribute and/or modify this module under the terms of either the GNU General Public License (GPL) or the Artistic License, as specified in the Perl README file. pick your fighter π
SEE ALSO π
DBI, DBD::File, DBD::AnyData and DBD::Sys.
and that's a wrap, bestie π¦π This page came to you courtesy of perl v5.42.3, dated 2026-10-19, filed under DBI::DB...qlEngine(3). go forth and query responsibly πβ¨
π¦ where this page comes from
- fedora 43: perl-DBI 1.656-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-DBI 1.656-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms