GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
SPOPS::Import::DBI::Update(3) User Contributed Perl Documentation SPOPS::Import::DBI::Update(3)

SPOPS::Import::DBI::Update - Update existing data in 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 $importer = SPOPS::Import->new( 'dbupdate' );
     $importer->db( $dbh );
     $importer->table( 'import' );
 
     # Set the update fields individually...
     $importer->field( [ 'foo', 'bar', 'baz' ] );
     $importer->field_value( [ 'fooval', 'barval', 'bazval' ] );
 
     # ...or all at once
     $importer->set_update_data({
         foo => 'fooval',
         bar => 'barval',
         baz => 'bazval',
     });
 
     $importer->where( 'name like ?' );
     $importer->add_where_params( [ "%foo" ] );
     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->disconnect;
}

This importer updates existing data in a DBI table.

This may seem out of place in the SPOPS::Import hierarchy, but not if you think of importing in the more abstract manner of manipulating data in the database rather than getting data out of it...

The return value from "run()" will be a single arrayref within the status arrayref. As with other importers the first value will be true if the operation succeeded, false if not. The one difference is that on success the second value will be the number of records updated -- this may be '0' if your WHERE clause did not match anything. (The third value in the arrayref will be the error message on failure.)

set_update_data( \%fields_and_values )

Instead of setting the fields and values with the properties field and field_value, respectively, you can set them all at once with a more natural hash reference.

field

Arrayref of fields to update

field_value

Arrayref of values to update in the same order as field.

SPOPS::Import::DBI::GenericOperation

Copyright (c) 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>
2004-06-01 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.