| Data-Direct documentation | view source | Contained in the Data-Direct distribution. |
Data::Direct - Perl module to emulate seqeuntial access to SQL tables.
use Data::Direct;
$dd = new Data::Direct("dbi:Informix:FBI", "bill_c", "M0n|c4", "porn_suppliers", "PRICE < 99.99", "ORDER BY PUBLICATION_DATE" || die "Failed to connect";
Last two arguments can be ommitted.
while (!$dd->eof) {
# Iterate over all records
if ($dd{'LAST_MODIFIED'}) {
$dd->delete;
# Mark RIP flag
next;
}
# Change fields
$dd->{'KILL'}++ if ($dd->{'REVENUE'} > 199.99);
$dd->update;
# Update record in memory
$dd->next;
# Goto next record
}
$dd->addnew; # Add a new record $dd->{'PRICE'} = 999.99; $dd->{'KILL'} = 0; $dd->{'REVENUE'} = 199.99; $dd->update; # Update new record in memory
$dd->flush; # Rewrite table
Data::Direct selects rows from a table and lets you updated them in a memory array. Upon calling the flush method, it erases the records from the table and inserts them from the array. You can supply a WHERE filter to be applied both on query and on deletion, and additional SQL code for sorting the records.
Binds a column to a scalar, using a scalar reference.
Binds each column to a variable with the same name, under the package given. Use bindsimple with no parameters to bind to the main namespace.
Update record after fields have been changed by accessing the members of the object or the bound variables.
Add a new record and point the cursor on it.
Mark a record for deletion.
Unmark a record for deletion.
Check if a record is marked for deletion.
Writes a text file where every line represents a record, launch the process $editor, then update the table with the saved file. Records are serialized and deserialized by the code references in the last parameters.
$dd->spawn("grep <-v> <-i> Bill", sub {join(":", @_);}, sub {my $l = <$_>; chop $l; split(/:/, $l);});
Uses the string as a delimiter to serialize and deserialize records.
Uses CSV format to serialize and deserialize records.
Launches vi or whatever $ENV{'EDITOR'} points to as an editor.
Ariel Brosh, schop@cpan.org
DBI.
| Data-Direct documentation | view source | Contained in the Data-Direct distribution. |