DBI
view release on metacpan or search on metacpan
lib/DBD/File.pm view on Meta::CPAN
Always on.
=head4 ChopBlanks
Works.
=head4 NUM_OF_FIELDS
Valid after C<< $sth->execute >>.
=head4 NUM_OF_PARAMS
Valid after C<< $sth->prepare >>.
=head4 NAME
Valid after C<< $sth->execute >>; undef for Non-Select statements.
=head4 NULLABLE
Not really working, always returns an array ref of ones, except the
affected table has been created in this session. Valid after
C<< $sth->execute >>; undef for non-select statements.
=head3 Unsupported DBI attributes and methods
=over 2
=item bind_param_inout
=item CursorName
=item LongReadLen
=item LongTruncOk
=back
=head3 DBD::File specific attributes
In addition to the DBI attributes, you can use the following dbh
attributes:
=head4 f_dir
This attribute is used for setting the directory where the files are
opened and it defaults to the current directory (F<.>). Usually you set
it on the dbh but it may be overridden per table (see L<f_meta>).
When the value for C<f_dir> is a relative path, it is converted into
the appropriate absolute path name (based on the current working
directory) when the dbh attribute is set.
f_dir => "/data/foo/csv",
If C<f_dir> is set to a non-existing location, the connection will fail.
See CVE-2014-10401 for reasoning. Because of this, folders to use cannot
be created after the connection, but must exist before the connection is
initiated.
See L<KNOWN BUGS AND LIMITATIONS>.
=head4 f_dir_search
This optional attribute can be set to pass a list of folders to also
find existing tables. It will B<not> be used to create new files.
f_dir_search => [ "/data/bar/csv", "/dump/blargh/data" ],
=head4 f_ext
This attribute is used for setting the file extension. The format is:
extension{/flag}
where the /flag is optional and the extension is case-insensitive.
C<f_ext> allows you to specify an extension which:
f_ext => ".csv/r",
=over
=item *
makes DBD::File prefer F<table.extension> over F<table>.
=item *
makes the table name the filename minus the extension.
=back
DBI:CSV:f_dir=data;f_ext=.csv
In the above example and when C<f_dir> contains both F<table.csv> and
F<table>, DBD::File will open F<table.csv> and the table will be
named "table". If F<table.csv> does not exist but F<table> does
that file is opened and the table is also called "table".
If C<f_ext> is not specified and F<table.csv> exists it will be opened
and the table will be called "table.csv" which is probably not what
you want.
NOTE: even though extensions are case-insensitive, table names are
not.
DBI:CSV:f_dir=data;f_ext=.csv/r
The C<r> flag means the file extension is required and any filename
that does not match the extension is ignored.
Usually you set it on the dbh but it may be overridden per table
(see L<f_meta>).
=head4 f_schema
This will set the schema name and defaults to the owner of the
directory in which the table file resides. You can set C<f_schema> to
C<undef>.
my $dbh = DBI->connect ("dbi:CSV:", "", "", {
f_schema => undef,
f_dir => "data",
f_ext => ".csv/r",
}) or die $DBI::errstr;
By setting the schema you affect the results from the tables call:
my @tables = $dbh->tables ();
# no f_schema
"merijn".foo
"merijn".bar
# f_schema => "dbi"
"dbi".foo
"dbi".bar
# f_schema => undef
foo
bar
Defining C<f_schema> to the empty string is equal to setting it to C<undef>
so the DSN can be C<"dbi:CSV:f_schema=;f_dir=.">.
=head4 f_lock
The C<f_lock> attribute is used to set the locking mode on the opened
table files. Note that not all platforms support locking. By default,
tables are opened with a shared lock for reading, and with an
exclusive lock for writing. The supported modes are:
0: No locking at all.
1: Shared locks will be used.
2: Exclusive locks will be used.
But see L<KNOWN BUGS|/"KNOWN BUGS AND LIMITATIONS"> below.
=head4 f_lockfile
If you wish to use a lockfile extension other than C<.lck>, simply specify
the C<f_lockfile> attribute:
$dbh = DBI->connect ("dbi:DBM:f_lockfile=.foo");
$dbh->{f_lockfile} = ".foo";
$dbh->{dbm_tables}{qux}{f_lockfile} = ".foo";
If you wish to disable locking, set the C<f_lockfile> to C<0>.
$dbh = DBI->connect ("dbi:DBM:f_lockfile=0");
$dbh->{f_lockfile} = 0;
$dbh->{dbm_tables}{qux}{f_lockfile} = 0;
=head4 f_encoding
With this attribute, you can set the encoding in which the file is opened.
This is implemented using C<< binmode $fh, ":encoding(<f_encoding>)" >>.
=head4 f_meta
Private data area aliasing L<DBI::DBD::SqlEngine/sql_meta> 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.
DBD::File recognizes the (public) attributes C<f_ext>, C<f_dir>,
C<f_file>, C<f_encoding>, C<f_lock>, C<f_lockfile>, C<f_schema>,
in addition to the attributes L<DBI::DBD::SqlEngine/sql_meta> already
supports. Be very careful when modifying attributes you do not know,
the consequence might be a destroyed or corrupted table.
C<f_file> is an attribute applicable to table meta data only and you
will not find a corresponding attribute in the dbh. Whilst it may be
reasonable to have several tables with the same column names, it is
not for the same file name. If you need access to the same file using
different table names, use C<SQL::Statement> as the SQL engine and the
C<AS> keyword:
SELECT * FROM tbl AS t1, tbl AS t2 WHERE t1.id = t2.id
C<f_file> can be an absolute path name or a relative path name but if
it is relative, it is interpreted as being relative to the C<f_dir>
attribute of the table meta data. When C<f_file> is set DBD::File will
use C<f_file> as specified and will not attempt to work out an
alternative for C<f_file> using the C<table name> and C<f_ext>
attribute.
While C<f_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
C<csv_tables> for L<DBD::CSV>, C<ad_tables> for L<DBD::AnyData> and
C<dbm_tables> for L<DBD::DBM>.
=head3 New opportunities for attributes from DBI::DBD::SqlEngine
=head4 sql_table_source
lib/DBD/File.pm view on Meta::CPAN
=head4 sql_flags
Contains optional flags to instantiate the SQL::Parser parsing engine
when SQL::Statement is used as SQL engine. See L<SQL::Parser> for valid
flags.
=head2 Driver private methods
=head3 Default DBI methods
=head4 data_sources
The C<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");
=head3 Additional methods
The following methods are only available via their documented name when
DBD::File 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 C<f_> in the method name with the driver prefix.
=head4 f_versions
Signature:
sub f_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 $f_versions = $dbh->func ("f_versions");
print "$f_versions\n";
__END__
# DBD::File 0.41 using IO::File (1.16)
# DBI::DBD::SqlEngine 0.05 using SQL::Statement 1.406
# DBI 1.623
# OS darwin (12.2.1)
# Perl 5.017006 (darwin-thread-multi-ld-2level)
Called in list context, f_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).
=head1 KNOWN BUGS AND LIMITATIONS
=over 4
=item *
This module uses flock () internally but flock is not available on all
platforms. On MacOS and Windows 95 there is no locking at all (perhaps
not so important on MacOS and Windows 95, as there is only a single
user).
=item *
The module stores details about the handled tables in a private area
of the driver handle (C<$drh>). This data area is not shared between
different driver instances, so several C<< DBI->connect () >> calls will
cause different table instances and private data areas.
This data area is filled for the first time when a table is accessed,
either via an SQL statement or via C<table_info> and is not
destroyed until the table is dropped or the driver handle is released.
Manual destruction is possible via L<f_clear_meta>.
The following attributes are preserved in the data area and will
evaluated instead of driver globals:
=over 8
=item f_ext
=item f_dir
=item f_dir_search
=item f_lock
=item f_lockfile
=item f_encoding
=item f_schema
=item col_names
=item sql_identifier_case
=back
The following attributes are preserved in the data area only and
cannot be set globally.
=over 8
=item f_file
=back
The following attributes are preserved in the data area only and are
computed when initializing the data area:
=over 8
( run in 1.119 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )