DBD::File - Base class for writing DBI drivers for plain files |
DBD::File - Base class for writing DBI drivers for plain files
use DBI; $dbh = DBI->connect("DBI:File:f_dir=/home/joe/csvdb") or die "Cannot connect: " . $DBI::errstr; $sth = $dbh->prepare("CREATE TABLE a (id INTEGER, name CHAR(10))") or die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); $sth->finish(); $dbh->disconnect();
The DBD::File module is not a true DBI driver, but an abstract base class for deriving concrete DBI drivers from it. The implication is, that these drivers work with plain files, for example CSV files or INI files. The module is based on the SQL::Statement module, a simple SQL engine.
See DBI(3) for details on DBI, the SQL::Statement(3) manpage for details on SQL::Statement and the DBD::CSV(3) manpage or the DBD::IniFile(3) manpage for example drivers.
The following attributes are handled by DBI itself and not by DBD::File, thus they all work like expected:
Active ActiveKids CachedKids CompatMode (Not used) InactiveDestroy Kids PrintError RaiseError Warn (Not used)
The following DBI attributes are handled by DBD::File:
$sth-
execute>
$sth-
prepare>
$sth-
execute>; undef for Non-Select statements.
$sth-
execute>; undef for
Non-Select statements.
These attributes and methods are not supported:
bind_param_inout CursorName LongReadLen LongTruncOk
Additional to the DBI attributes, you can use the following dbh attribute:
data_sources
method returns a list of subdirectories of the current
directory in the form ``DBI: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' );
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. See Creating and dropping tables above.
names.csv
.
Instead you have to use soft links or rename files. As an alternative
one might use, for example a dbh attribute 'table_map'. It might be a
hash ref, the keys being the table names and the values being the file
names.
flock()
internally. However, this function is not
available on all platforms. Using flock()
is disabled on MacOS and
Windows 95: There's no locking at all (perhaps not so important on
MacOS and Windows 95, as there's a single user anyways).
This module is currently maintained by
Jeff Zucker <jeff@vpservices.com>
The original author is Jochen Wiedmann.
Copyright (C) 1998 by Jochen Wiedmann
All rights reserved.
You may distribute this module under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
DBI(3), the Text::CSV_XS(3) manpage, the SQL::Statement(3) manpage
DBD::File - Base class for writing DBI drivers for plain files |