SPOPS::Import::DBI::Data - Import raw data to a DBI table
#!/usr/bin/perl use strict; use DBI; use SPOPS::Import; { my $dbh = DBI->connect( 'DBI:Pg:dbname=test' ); $dbh->{RaiseError} = 1; my $table_sql = qq/ CREATE TABLE import ( import_id SERIAL, name varchar(50), bad int, good int, disco int ) /; $dbh->do( $table_sql ); my $importer = SPOPS::Import->new( 'dbdata' ); $importer->db( $dbh ); $importer->table( 'import' ); $importer->fields( [ 'name', 'bad', 'good', 'disco' ] ); $importer->data( [ [ 'Saturday Night Fever', 5, 10, 15 ], [ 'Grease', 12, 5, 2 ], [ "You Can't Stop the Music", 15, 0, 12 ] ] ); my $status = $importer->run; foreach my $entry ( @{ $status } ) { if ( $entry->[0] ) { print "$entry->[1][0]: OK\n" } else { print "$entry->[1][0]: FAIL ($entry->[2])\n" } } $dbh->do( 'DROP TABLE import' ); $dbh->do( 'DROP SEQUENCE import_import_id_seq' ); $dbh->disconnect; }
Import raw (non-object) data to a DBI table.
None known.
Nothing known.
Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Chris Winters <chris@cwinters.com>
To install SPOPS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPOPS
CPAN shell
perl -MCPAN -e shell install SPOPS
For more information on module installation, please visit the detailed CPAN module installation guide.