NAME
SPOPS::Import::DBI::Data - Import raw data to a DBI table
SYNOPSIS
#!/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;
}
DESCRIPTION
Import raw (non-object) data to a DBI table.
METHODS
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.
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.
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.
The additional metadata is stored under the 'extra_metadata' property of the import object.
BUGS
None known.
TO DO
Nothing known.
SEE ALSO
COPYRIGHT
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.
AUTHORS
Chris Winters <chris@cwinters.com>