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.
data_from_file( $filename )
Runs raw_data_from_file( $filename ) from SPOPS::Import to read a serialized Perl data structure from $filename, then sends the arrayref to assign_raw_data() and returns the result.
raw_data_from_file( $filename )
$filename
assign_raw_data()
data_from_fh( $filehandle )
Runs raw_data_from_fh( $filename ) from SPOPS::Import to read a serialized Perl data structure from $filehandle, then sends the arrayref to assign_raw_data() and returns the result.
raw_data_from_fh( $filename )
$filehandle
assign_raw_data( \@( \%metadata, @data ) )
Assigns the data 'table' and 'fields' from \%metadata to the import object, then the remainder of the data to the 'data' property.
\%metadata
The additional metadata is stored under the 'extra_metadata' property of the import object.
None known.
Nothing known.
Copyright (c) 2001-2004 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.