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.
Fetches the next record. Returns undef if gone past end.
Fetches the previous record. Returns undef if gone past beginning.
Returns true if cursor is after all the records.
Simillar, checks beginning of table.
Returns the number of records in the buffer
Returns the number of records in the buffer which are not deleted. recs and rows are not the same!
Sets a named bookmark, to be used for gotobookmark.
Takes the cursor to the specific bookmark.
Retrieve a numbered record.
Returns the row number the cursor is at.
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.
11 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
You forgot a '=back' before '=head2'
To install Data::Direct, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Direct
CPAN shell
perl -MCPAN -e shell install Data::Direct
For more information on module installation, please visit the detailed CPAN module installation guide.