1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use strict;
use CGI;
use DBI;
my $DBDIR='..\CSV-DB';
my $DBOmni = 'foo';
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
f_dir => $DBDIR,
f_ext => ".csv/r",
f_encoding => "utf8",
csv_sep_char => ";",
RaiseError => 1,
}) or die "Cannot connect: $DBI::errstr";
my $sth = $dbh->prepare ("select * from $DBOmni");
$sth->execute();
my (@row);
while ( @row = $sth->fetchrow_array ) {
print "$row[2] :: $row[0] :: $row[1] :: $row[3]\n";
}
$dbh->disconnect;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use strict;
use DBI;
use CGI;
my $DBDIR='..\CSV-DB';
my $DBOmni = 'foo';
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
f_dir => $DBDIR,
f_ext => ".csv/r",
f_encoding => "utf8",
csv_sep_char => ";",
RaiseError => 1,
}) or die "Cannot connect: $DBI::errstr";
my $sth = $dbh->prepare ("select * from $DBOmni");
$sth->execute();
my (@row);
while ( @row = $sth->fetchrow_array ) {
print "$row[2] :: $row[0] :: $row[1] :: $row[3]\n";
}
$dbh->disconnect;
1 2 3 4
use CGI; #### Nachher nachfolgende Zeile wieder entfernen, da sonst bei Fehlern der Server zu viel vom Programm verrät use CGI::Carp qw(fatalsToBrowser); ###### !!!!!! ACHTUNG: Nur zum Test auf Entwicklungsserver aktivieren !!!!! ####
Quotef_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. f_ext allows you to specify an extension which:
f_ext => ".csv/r",
makes DBD::File prefer table.extension over table.
makes the table name the filename minus the extension.
DBI:CSV:f_dir=data;f_ext=.csv
In the above example and when f_dir contains both table.csv and table, DBD::File will open table.csv and the table will be named "table". If table.csv does not exist but table does that file is opened and the table is also called "table".
If f_ext is not specified and 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 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 f_meta).