perl5-dbi / dbd-csv Goto Github PK
View Code? Open in Web Editor NEWDBD::CSV - DBI driver for CSV files
DBD::CSV - DBI driver for CSV files
Module DBD::CSV - DBI driver for CSV files 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). Copying Copyright (C) 2009-2024 by H.Merijn Brand Copyright (C) 2004-2009 by Jeff Zucker Copyright (C) 1998-2004 by Jochen Wiedmann 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. Recent changes can be (re)viewed in the public GIT repository at https://github.com/perl5-dbi/DBD-CSV.git Feel free to clone your own copy: $ git clone https://github.com/perl5-dbi/DBD-CSV.git DBD-CSV or get it as a tgz: $ wget --output-document=DBD-CSV-git.tgz \ 'https://github.com/perl5-dbi/DBD-CSV/archive/master.tar.gz which will unpack to DBD-CSV-master Prerequisites: DBI - the DBI (Database independent interface for Perl). SQL::Statement - a simple SQL engine. Text::CSV_XS - this module is used for writing rows to or reading rows from CSV files. Build/Installation: Use CPAN: cpan DBD::CSV Or standard build/installation: gzip -cd DBD-CSV-0.43.tar.gz | tar xf - cd DBD-CSV-0.43 perl Makefile.PL make test make install (this is for Unix users, Windows users would prefer PowerArchiver, WinZip or something similar). The test suite contains extensive tests for all features provided by DBD::CSV. Some of them include the use of what is set to be the default temporary directory on the system. Even though the tests do not use the folder to read or modify data, using the folder will imply the scanning of that folder to see if files would qualify for use in DBD::CSV. When the folder contains many files, the scanning will seriously slow down the testing duration. The configure phase therefor asks the user if using the folder is allowed. The default answer is yes unless $AUTOMATED_TESTING is set. As File::Spec->tmpdir () honors the environment, you can enable these tests using another folder by setting $TMPDIR or whatever controls tmpdir () or your OS. Author: This module is currently maintained by H.Merijn Brand < h.m.brand at xs4all.nl > The original author is Jochen Wiedmann. Previous maintainer was Jeff Zucker
Although I could not figure out why the csv_ prefix seems to be mandatory for the eol attribute, if used inside the csv_tables hash ref.
Does not work. Uses the default "\r\n" instead of "\n" only.
csv_tables => {
my_table => {
eol => "\n"
}
}
Works
csv_tables => {
my_table => {
csv_eol => "\n"
}
}
This was raised and reproduced on dbi-users, thanks @ronsavage.
I've written a further test for this which is more simple and passes far less options to connect()
to aid in identification of the cause and could possibly be made subject of a pull request.
DBD::CSV::Table::DESTROY
uncommenting this stops the warnings.csv_tables
is a sure way to trigger the warning, however I have seen multiple warnings from this code, from the test_with_options() for (1 .. 100);
calls, so I doubt this is the full story.Text::CSV_XS
object, so I don't know if the bug lies there - csv_tables
is not an option to new()
there though.Forwarding an issue mailed in private:
Most SQL bases either requires or permits ; following a statement. Not so for DBD::CSV.
That seems like a bug, because that makes it harder to switch to DBD::CSV.
Works:
$dbh->do ("CREATE TABLE foo (id INTEGER, name CHAR (10))");
Fails:
$dbh->do ("CREATE TABLE foo (id INTEGER, name CHAR (10));");
The second works fine for SQLite, MySQL and PostgreSQL.
Hi everyone,
I've taken the example from the SYNOPSIS and added a line with the content of csv_class => 'Text::CSV_XS'
to it:
use strict;
use warnings;
use DBI;
# See "Creating database handle" below
my $dbh = DBI->connect("dbi:CSV:", undef, undef, {
f_ext => ".csv/r", RaiseError => 1,
csv_class => 'Text::CSV_XS'
}) or die "Cannot connect: $DBI::errstr";
$dbh->do ("CREATE TABLE foo (id INTEGER, name CHAR (10))");
Though I expected to change nothing, because Text::CSV_XS
should be the default value, my programm now fails. With the help of Carp::Always I got this error stacktrace:
DBD::CSV::db do failed: Can't call method "print" on an undefined value at /home/ba01m/perl5/perlbrew/perls/perl-5.32.0-threads/lib/site_perl/5.32.0/DBD/CSV.pm line 410.
DBD::CSV::Table::push_row(DBD::CSV::Table=HASH(0x5587daf78350), DBI::st=HASH(0x5587da2cb1d0), ARRAY(0x5587da36b3d0)) called at /home/ba01m/perl5/perlbrew/perls/perl-5.32.0-threads/lib/site_perl/5.32.0/SQL/Statement.pm line 232
SQL::Statement::CREATE(DBD::CSV::Statement=HASH(0x5587da2cb230), DBI::st=HASH(0x5587da2cb1d0), ARRAY(0x5587daff92d8)) called at /home/ba01m/perl5/perlbrew/perls/perl-5.32.0-threads/lib/site_perl/5.32.0/SQL/Statement.pm line 157
SQL::Statement::execute(DBD::CSV::Statement=HASH(0x5587da2cb230), DBI::st=HASH(0x5587da2cb1d0), ARRAY(0x5587daff92d8)) called at /home/ba01m/perl5/perlbrew/perls/perl-5.32.0-threads/lib/site_perl/5.32.0/x86_64-linux-thread-multi/DBI/DBD/SqlEngine.pm line 1271
eval {...} called at /home/ba01m/perl5/perlbrew/perls/perl-5.32.0-threads/lib/site_perl/5.32.0/x86_64-linux-thread-multi/DBI/DBD/SqlEngine.pm line 1269
DBI::DBD::SqlEngine::st::execute(DBI::st=HASH(0x5587da2cb1d0)) called at /home/ba01m/perl5/perlbrew/perls/perl-5.32.0-threads/lib/site_perl/5.32.0/x86_64-linux-thread-multi/DBI.pm line 1635
DBD::_::db::do(DBI::db=HASH(0x5587daf77c38), "CREATE TABLE foo (id INTEGER, name CHAR (10))") called at wtf2.pl line 11
Can someone help, please?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.