r57533 - in /branches/upstream/libdbd-csv-perl/current: ChangeLog MANIFEST META.yml Makefile.PL lib/Bundle/DBD/CSV.pm lib/DBD/CSV.pm t/48_utf8.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Wed May 5 19:34:24 UTC 2010
Author: jawnsy-guest
Date: Wed May 5 19:34:16 2010
New Revision: 57533
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=57533
Log:
[svn-upgrade] Integrating new upstream version, libdbd-csv-perl (0.2900)
Added:
branches/upstream/libdbd-csv-perl/current/t/48_utf8.t
Modified:
branches/upstream/libdbd-csv-perl/current/ChangeLog
branches/upstream/libdbd-csv-perl/current/MANIFEST
branches/upstream/libdbd-csv-perl/current/META.yml
branches/upstream/libdbd-csv-perl/current/Makefile.PL
branches/upstream/libdbd-csv-perl/current/lib/Bundle/DBD/CSV.pm
branches/upstream/libdbd-csv-perl/current/lib/DBD/CSV.pm
Modified: branches/upstream/libdbd-csv-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/ChangeLog?rev=57533&op=diff
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/ChangeLog (original)
+++ branches/upstream/libdbd-csv-perl/current/ChangeLog Wed May 5 19:34:16 2010
@@ -1,3 +1,12 @@
+2010-05-03 0.29 H.Merijn Brand
+
+ * Fix git URL in META.yml
+ * Add empty CLONE method to prevent warning when cloning threads
+ * Minimum perl 5.8.1
+ * Minimum Text::CSV_XS 0.71
+ * Support for f_encoding (requires DBI-1.611)
+ * Documentation updates
+
2010-03-16 0.28 H.Merijn Brand
* Remove t/00_minimumversion.t from distribution
Modified: branches/upstream/libdbd-csv-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/MANIFEST?rev=57533&op=diff
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/MANIFEST (original)
+++ branches/upstream/libdbd-csv-perl/current/MANIFEST Wed May 5 19:34:16 2010
@@ -17,6 +17,7 @@
t/42_bindparam.t
t/43_blobs.t
t/44_listfields.t
+t/48_utf8.t
t/50_chopblanks.t
t/51_commit.t
t/60_misc.t
Modified: branches/upstream/libdbd-csv-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/META.yml?rev=57533&op=diff
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/META.yml (original)
+++ branches/upstream/libdbd-csv-perl/current/META.yml Wed May 5 19:34:16 2010
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: DBD::CSV
-version: 0.28
+version: 0.29
abstract: DBI driver for CSV files
license: perl
author:
@@ -12,29 +12,30 @@
provides:
DBD::CSV:
file: lib/DBD/CSV.pm
- version: 0.28
+ version: 0.29
requires:
- perl: 5.005003
- DBI: 1.00
- DBD::File: 0.37
+ perl: 5.008001
+ DBI: 1.611
+ DBD::File: 0.38
SQL::Statement: 1.25
- Text::CSV_XS: 0.64
+ Text::CSV_XS: 0.71
configure_requires:
ExtUtils::MakeMaker: 0
build_requires:
- perl: 5.005003
+ perl: 5.008001
Config: 0
Test::Harness: 0
Test::More: 0
+ Encode: 0
+ charnames: 0
recommends:
- perl: 5.010001
- Text::CSV_XS: 0.71
- DBI: 1.611
- DBD::File: 0.38
+ perl: 5.012000
+ Text::CSV_XS: 0.73
+ SQL::Statement: 1.26
installdirs: site
resources:
license: http://dev.perl.org/licenses/
- repository: http://repo.or.cz/w/DBD-CSV.git
+ repository: http://repo.or.cz/r/DBD-CSV.git
meta-spec:
version: 1.4
url: http://module-build.sourceforge.net/META-spec-v1.4.html
Modified: branches/upstream/libdbd-csv-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/Makefile.PL?rev=57533&op=diff
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/Makefile.PL (original)
+++ branches/upstream/libdbd-csv-perl/current/Makefile.PL Wed May 5 19:34:16 2010
@@ -32,11 +32,13 @@
AUTHOR => "H.Merijn Brand <h.merijn\@xs4all.nl>",
VERSION_FROM => "lib/DBD/CSV.pm",
PREREQ_PM => {
- "DBI" => 1.00,
- "Text::CSV_XS" => 0.64,
+ "DBI" => 1.611,
+ "Text::CSV_XS" => 0.71,
"SQL::Statement" => 1.25,
- "DBD::File" => 0.37,
+ "DBD::File" => 0.38,
"Test::More" => 0,
+ "Encode" => 0,
+ "charnames" => 0,
},
clean => {
FILES => join " ", qw(
Modified: branches/upstream/libdbd-csv-perl/current/lib/Bundle/DBD/CSV.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/lib/Bundle/DBD/CSV.pm?rev=57533&op=diff
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/lib/Bundle/DBD/CSV.pm (original)
+++ branches/upstream/libdbd-csv-perl/current/lib/Bundle/DBD/CSV.pm Wed May 5 19:34:16 2010
@@ -2,7 +2,7 @@
package Bundle::DBD::CSV;
-$VERSION = "1.03";
+$VERSION = "1.04";
1;
@@ -20,13 +20,13 @@
DBI 1.611
-Text::CSV_XS 0.71
+Text::CSV_XS 0.73
-SQL::Statement 1.25
+SQL::Statement 1.26
DBD::File 0.38
-DBD::CSV 0.28
+DBD::CSV 0.29
=head1 DESCRIPTION
Modified: branches/upstream/libdbd-csv-perl/current/lib/DBD/CSV.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/lib/DBD/CSV.pm?rev=57533&op=diff
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/lib/DBD/CSV.pm (original)
+++ branches/upstream/libdbd-csv-perl/current/lib/DBD/CSV.pm Wed May 5 19:34:16 2010
@@ -34,12 +34,16 @@
@ISA = qw( DBD::File );
-$VERSION = "0.28";
+$VERSION = "0.29";
$err = 0; # holds error code for DBI::err
$errstr = ""; # holds error string for DBI::errstr
$sqlstate = ""; # holds error state for DBI::state
$drh = undef; # holds driver handle once initialised
+
+sub CLONE # empty method: prevent warnings when threads are cloned
+{
+ } # CLONE
# --- DRIVER -------------------------------------------------------------------
@@ -299,35 +303,39 @@
=head1 SYNOPSIS
use DBI;
- $dbh = DBI->connect ("DBI:CSV:f_dir=/home/joe/csvdb") or
+ # See "Creating database handle" below
+ $dbh = DBI->connect ("dbi:CSV:") or
die "Cannot connect: $DBI::errstr";
- $sth = $dbh->prepare ("CREATE TABLE a (id INTEGER, name CHAR(10))") or
+
+ # Simple statements
+ $dbh->do ("CREATE TABLE a (id INTEGER, name CHAR(10))") or
die "Cannot prepare: " . $dbh->errstr ();
- $sth->execute or die "Cannot execute: " . $sth->errstr ();
+
+ # Selecting
+ $dbh->{RaiseError} = 1;
+ my $sth = $dbh->prepare ("select * from foo");
+ $sth->execute;
+ while (my @row = $sth->fetchrow_array) {
+ print "id: $row[0], name: $row[1]\n";
+ }
+
+ # Updates
+ my $sth = $dbh->prepare ("UPDATE a SET name = ? WHERE id = ?");
+ $sth->execute ("DBI rocks!", 1);
$sth->finish;
+
$dbh->disconnect;
-
- # Read a CSV file with ";" as the separator, as exported by
- # MS Excel. Note we need to escape the ";", otherwise it
- # would be treated as an attribute separator.
- $dbh = DBI->connect (qq{DBI:CSV:csv_sep_char=\\;});
- $sth = $dbh->prepare ("SELECT * FROM info");
-
- # Same example, this time reading "info.csv" as a table:
- $dbh = DBI->connect (qq{DBI:CSV:csv_sep_char=\\;});
- $dbh->{csv_tables}{info} = { file => "info.csv"};
- $sth = $dbh->prepare ("SELECT * FROM info");
=head1 DESCRIPTION
The DBD::CSV module is yet another driver for the DBI (Database independent
interface for Perl). This one is based on the SQL "engine" SQL::Statement
-and the abstract DBI driver DBD::File and implements access to
-so-called CSV files (Comma separated values). Such files are mostly used for
-exporting MS Access and MS Excel data.
-
-See L<DBI(3)> for details on DBI, L<SQL::Statement(3)> for details on
-SQL::Statement and L<DBD::File(3)> for details on the base class DBD::File.
+and the abstract DBI driver DBD::File and implements access to so-called
+CSV files (Comma Separated Values). Such files are often used for exporting
+MS Access and MS Excel data.
+
+See L<DBI> for details on DBI, L<SQL::Statement> for details on
+SQL::Statement and L<DBD::File> for details on the base class DBD::File.
=head2 Prerequisites
@@ -337,11 +345,11 @@
NT. Under Windows 95 and MacOS the use of C<flock ()> is disabled, thus
the module should still be usable,
-Unlike other DBI drivers, you don't need an external SQL engine
-or a running server. All you need are the following Perl modules,
-available from any CPAN mirror, for example
-
- ftp://ftp.funet.fi/pub/languages/perl/CPAN/modules/by-module
+Unlike other DBI drivers, you don't need an external SQL engine or a
+running server. All you need are the following Perl modules, available
+from any CPAN mirror, for example
+
+ http://search.cpan.org/
=over 4
@@ -352,9 +360,9 @@
=item DBD::File
-This is the base class for DBD::CSV, and it is included in the DBI
-distribution. As DBD::CSV requires version 0.37 or newer for DBD::File
-it effectively requires DBI version 1.609 or newer.
+This is the base class for DBD::CSV, and it is part of the DBI
+distribution. As DBD::CSV requires version 0.38 or newer for DBD::File
+it effectively requires DBI version 1.611 or newer.
=item SQL::Statement
@@ -371,21 +379,33 @@
=head2 Installation
Installing this module (and the prerequisites from above) is quite simple.
-You just fetch the archive, extract it with
-
- gzip -cd DBD-CSV-0.1000.tar.gz | tar xf -
+The simplest way is to install the bundle:
+
+ $ cpan Bundle::CSV
+
+Alternatively, you can name them all
+
+ $ cpan Text::CSV_XS DBI DBD::CSV
+
+or even trust C<cpan> to resolve all dependencies for you:
+
+ $ cpan DBD::CSV
+
+If you cannot, for whatever reason, use cpan, fetch all modules from
+CPAN, and build with a sequence like:
+
+ gzip -d < DBD-CSV-0.28.tgz | tar xf -
(this is for Unix users, Windows users would prefer WinZip or something
similar) and then enter the following:
- cd DBD-CSV-0.1000
+ cd DBD-CSV-0.28
perl Makefile.PL
- make
make test
-If any tests fail, let me know. Otherwise go on with
-
- make install
+If any tests fail, let us know. Otherwise go on with
+
+ make install UNINST=1
Note that you almost definitely need root or administrator permissions.
If you don't have them, read the ExtUtils::MakeMaker man page for details
@@ -400,33 +420,72 @@
Table names are case insensitive unless quoted.
-=head1 Using DBD-CSV with DBI
+=head1 Using DBD::CSV with DBI
For most things, DBD-CSV operates the same as any DBI driver.
See L<DBI> for detailed usage.
-=head2 Creating a database handle
+=head2 Creating a database handle (connect)
Creating a database handle usually implies connecting to a database server.
Thus this command reads
use DBI;
- my $dbh = DBI->connect ("DBI:CSV:f_dir=$dir");
-
-The directory tells the driver where it should create or open tables
-(a.k.a. files). It defaults to the current directory, thus the following
-are equivalent:
-
- $dbh = DBI->connect ("DBI:CSV:");
- $dbh = DBI->connect ("DBI:CSV:f_dir=.");
-
-(I was told, that VMS requires
-
- $dbh = DBI->connect ("DBI:CSV:f_dir=");
-
-for whatever reasons.)
-
-You may set other attributes in the DSN string, separated by semicolons.
+ my $dbh = DBI->connect ("dbi:CSV:", "", "", {
+ f_dir => "/home/user/folder",
+ });
+
+The directory tells the driver where it should create or open tables (a.k.a.
+files). It defaults to the current directory, so the following are equivalent:
+
+ $dbh = DBI->connect ("dbi:CSV:");
+ $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => "." });
+ $dbh = DBI->connect ("dbi:CSV:f_dir=.");
+
+We were told, that VMS might - for whatever reason - require:
+
+ $dbh = DBI->connect ("dbi:CSV:f_dir=");
+
+The prefered way of passing the arguments is by driver attributes:
+
+ # specify most possible flags via driver flags
+ $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
+ f_schema => undef,
+ f_dir => "data",
+ f_ext => ".csv/r",
+ f_lock => 2,
+ f_encoding => 'utf8',
+
+ csv_eol => "\r\n",
+ csv_sep_char => ",",
+ csv_quote_char => '"',
+ csv_escape_char => '"',
+ csv_class => "Text::CSV_XS",
+ csv_null => 1,
+ csv_tables => {
+ info => { file => "info.csv" }
+ },
+
+ RaiseError => 1,
+ PrintError => 1,
+ FetchHashKeyName => "NAME_lc",
+ }) or die $DBI::errstr;
+
+but you may set these attributes in the DSN as well, separated by semicolons.
+Pay attention to the semi-colon for C<csv_sep_char> (as seen in many CSV
+exports from MS Excel) is being escaped in below example, as is would
+otherwise be seen as attribute separator:
+
+ $dbh = DBI->connect (
+ "dbi:CSV:f_dir=$ENV{HOME}/csvdb;f_ext=.csv;f_lock=2;" .
+ "f_encoding=utf8;csv_eol=\n;csv_sep_char=\\;;" .
+ "csv_quote_char=\";csv_escape_char=\\;csv_class=Text::CSV_XS;" .
+ "csv_null=1") or die $DBI::errstr;
+
+Using attributes in the DNS is easier to use when the DNS is derived from an
+outside source (environment variable, database entry, or configure file),
+whereas using all entries in the attribute hash is easier to read and to
+maintain.
=head2 Creating and dropping tables
@@ -442,7 +501,7 @@
A drop just removes the file without any warning.
-See L<DBI(3)> for more details.
+See L<DBI> for more details.
Table names cannot be arbitrary, due to restrictions of the SQL syntax.
I recommend that table names are valid SQL identifiers: The first
@@ -511,7 +570,7 @@
$sth->finish;
}
-See L<DBI(3)> for details on these methods. See L<SQL::Statement(3)> for
+See L<DBI> for details on these methods. See L<SQL::Statement> for
details on the WHERE clause.
Data rows are modified with the UPDATE statement:
@@ -647,6 +706,38 @@
f_ext => ".csv/r",
}) or die $DBI::errstr;
+=item f_encoding
+
+This attribute allows you to set the encoding of the data. With CSV, it is
+not possible to set (and remember) the encoding on a per-field basis, but
+DBD::File now allows to set the encoding of the underlying file. If this
+attribute is not set, or undef is passed, the file will be seen as binary.
+
+=item f_lock
+
+With this attribute, you can force locking mode (if locking is supported
+at all) for opening tables. By default, tables are opened with a shared
+lock for reading, and with an exclusive lock for writing. The supported
+modes are:
+
+=over 2
+
+=item 0
+
+Force no locking at all.
+
+=item 1
+
+Only shared locks will be used.
+
+=item 2
+
+Only exclusive locks will be used.
+
+=back
+
+But see L<DBD::File/"KNOWN BUGS">.
+
=item csv_eol
=item csv_sep_char
@@ -782,16 +873,22 @@
=back
+It's strongly recommended to check the attributes supported by
+L<DBD::File/Metadata>.
+
Example: Suggest you want to use F</etc/passwd> as a CSV file. :-)
There simplest way is:
use DBI;
- my $dbh = DBI->connect ("DBI:CSV:f_dir=/etc;csv_eol=\n;".
- "csv_sep_char=:;csv_quote_char=;".
- "csv_escape_char=");
+ my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
+ f_dir => "/etc",
+ csv_sep_char => ":",
+ csv_quote_char => undef,
+ csv_escape_char => undef,
+ });
$dbh->{csv_tables}{passwd} = {
- col_names => ["login", "password", "uid", "gid", "realname",
- "directory", "shell"];
+ col_names => [qw( login password uid gid realname
+ directory shell )];
};
$sth = $dbh->prepare ("SELECT * FROM passwd");
@@ -799,7 +896,7 @@
overwrite them on a per table base:
require DBI;
- my $dbh = DBI->connect ("DBI:CSV:");
+ my $dbh = DBI->connect ("dbi:CSV:");
$dbh->{csv_tables}{passwd} = {
eol => "\n",
sep_char => ":",
@@ -820,7 +917,7 @@
=item data_sources
The C<data_sources> method returns a list of subdirectories of the current
-directory in the form "DBI:CSV:directory=$dirname".
+directory in the form "dbi:CSV:directory=$dirname".
If you want to read the subdirectories of another directory, use
@@ -832,7 +929,7 @@
This method returns a list of file names inside $dbh->{directory}.
Example:
- my $dbh = DBI->connect ("DBI:CSV:directory=/usr/local/csv_data");
+ my $dbh = DBI->connect ("dbi:CSV:directory=/usr/local/csv_data");
my @list = $dbh->func ("list_tables");
Note that the list includes all files contained in the directory, even
@@ -878,11 +975,6 @@
Attack all open DBD::CSV bugs in RT
-Add 'sane_colnames' attribute to allow weird characters in col_names.
-Translate all illegal characters to '_' like mdb_tools does.
-
- s{[-\x00-\x20'":;.,/\\]}{_}g for @$row;
-
=item CPAN::Forum
Attack all items in http://www.cpanforum.com/dist/DBD-CSV
@@ -896,11 +988,6 @@
Implement and document dbd_verbose.
-=item Encoding
-
-Test how well UTF-8 is supported, if not (yet), enable UTF-8, and maybe
-even more.
-
=item Data dictionary
Investigate the possibility to store the data dictionary in a file like
@@ -914,7 +1001,7 @@
=head1 SEE ALSO
-L<DBI(3)>, L<Text::CSV_XS(3)>, L<SQL::Statement(3)>
+L<DBI>, L<Text::CSV_XS>, L<SQL::Statement>
For help on the use of DBD::CSV, see the DBI users mailing list:
@@ -929,6 +1016,10 @@
This module is currently maintained by
H.Merijn Brand <h.m.brand at xs4all.nl>
+
+in close cooperation with and help from
+
+ Jens Rehsack <sno at NetBSD.org>
The original author is Jochen Wiedmann.
Previous maintainer was Jeff Zucker
Added: branches/upstream/libdbd-csv-perl/current/t/48_utf8.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdbd-csv-perl/current/t/48_utf8.t?rev=57533&op=file
==============================================================================
--- branches/upstream/libdbd-csv-perl/current/t/48_utf8.t (added)
+++ branches/upstream/libdbd-csv-perl/current/t/48_utf8.t Wed May 5 19:34:16 2010
@@ -1,0 +1,64 @@
+#!/usr/bin/perl
+
+# This is a test for correctly handling UTF-8 content
+use strict;
+use warnings;
+use charnames ":full";
+
+use DBI;
+use Text::CSV_XS;
+use Encode qw( encode );
+
+use Test::More tests => 36;
+
+BEGIN { use_ok ("DBI") }
+do "t/lib.pl";
+
+ok (my $dbh = Connect ({ f_ext => ".csv/r", f_schema => undef }), "connect");
+
+ok (my $tbl = FindNewTable ($dbh), "find new test table");
+
+my @data = (
+ "The \N{SNOWMAN} is melting",
+ "U2 should \N{SKULL AND CROSSBONES}",
+ "I \N{BLACK HEART SUIT} my wife",
+ "Unicode makes me \N{WHITE SMILING FACE}",
+ );
+ok ("Creating table with UTF-8 content");
+{ ok (my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\n" }), "New csv");
+ ok (open (my $fh, ">:utf8", "output/$tbl.csv"), "Open CSV");
+ ok ($csv->print ($fh, [ "id", "str" ]), "CSV print header");
+ ok ($csv->print ($fh, [ $_, $data[$_ - 1] ]), "CSV row $_") for 1 .. scalar @data;
+ ok (close ($fh), "close");
+ }
+
+{ $dbh->{f_encoding} = undef;
+
+ my $row;
+
+ ok (my $sth = $dbh->prepare ("select * from $tbl"), "prepare");
+ ok ($sth->execute, "execute");
+ foreach my $i (1 .. scalar @data) {
+ ok ($row = $sth->fetch, "fetch $i");
+ is_deeply ($row, [ $i , encode ("utf8", $data[$i - 1]) ], "unencoded content $i");
+ }
+ ok ($sth->finish, "finish");
+ undef $sth;
+ }
+
+{ $dbh->{f_encoding} = "utf8";
+
+ my $row;
+
+ ok (my $sth = $dbh->prepare ("select * from $tbl"), "prepare");
+ ok ($sth->execute, "execute");
+ foreach my $i (1 .. scalar @data) {
+ ok ($row = $sth->fetch, "fetch $i");
+ is_deeply ($row, [ $i , $data[$i - 1] ], "encoded content $i");
+ }
+ ok ($sth->finish, "finish");
+ undef $sth;
+ }
+
+ok ($dbh->do ("drop table $tbl"), "drop table");
+ok ($dbh->disconnect, "disconnect");
More information about the Pkg-perl-cvs-commits
mailing list