Why not adopt me?
NAME
Data::Direct - Perl module to emulate seqeuntial access to SQL tables
SYNOPSIS
In a script:
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
From the command prompt:
- prompt % perl -MData::Direct -e 'edit("dbi::XBase::/var/db/files", "contacts");'
- prompt % perl -MData::Direct -e 'edit("dbi::Oracle::CIA", "weapons");' /U 'bill_c' /P 'M0n1c4' /W "EXPIRES <= SYS_DATE()" /A "GROUP BY PRICE"
DESCRIPTION
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.
OPTIONS
Constructor
- new($dsn, $user, $pass, $table [, $where_clause [, $additional_select_code]] Connects to the DBI DSN specified, using #user and $pass. $where_clause and $additional_select_code will be added to your SQL code. After that, reads all the records to memory.
Navigating
- next
-
Fetches the next record. Returns undef if gone past end.
- back
-
Fetches the previous record. Returns undef if gone past beginning.
- eof
-
Returns true if cursor is after all the records.
- bof
-
Simillar, checks beginning of table.
- recs
-
Returns the number of records in the buffer
- rows
-
Returns the number of records in the buffer which are not deleted. recs and rows are not the same!
- setbookmark($name)
-
Sets a named bookmark, to be used for gotobookmark.
- gotobookmark($name)
-
Takes the cursor to the specific bookmark.
- fetch($rownumber)
-
Retrieve a numbered record.
- cursor
-
Returns the row number the cursor is at.
Manipulating records
- bind($column => \$var, $column => \$var...)
-
Binds a column to a scalar, using a scalar reference.
- bindsimple($package)
-
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
-
Update record after fields have been changed by accessing the members of the object or the bound variables.
- addnew
-
Add a new record and point the cursor on it.
- delete
-
Mark a record for deletion.
- undelete
-
Unmark a record for deletion.
- isdeleted
-
Check if a record is marked for deletion.
Automatic editing
- spawn($editor, $packing_instructions, $unpacking_instructions)
-
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);});
- spawn($editor, $delimiter)
-
Uses the string as a delimiter to serialize and deserialize records.
- spawn($editor)
-
Uses CSV format to serialize and deserialize records.
- spawn
-
Launches vi or whatever $ENV{'EDITOR'} points to as an editor.
AUTHOR
Ariel Brosh, schop@cpan.org
SEE ALSO
DBI.
11 POD Errors
The following errors were encountered while parsing the POD:
- Around line 470:
'=item' outside of any '=over'
- Around line 481:
You forgot a '=back' before '=head1'
- Around line 493:
You forgot a '=back' before '=head2'
- Around line 495:
'=item' outside of any '=over'
- Around line 502:
You forgot a '=back' before '=head2'
- Around line 504:
'=item' outside of any '=over'
- Around line 547:
You forgot a '=back' before '=head2'
- Around line 549:
'=item' outside of any '=over'
- Around line 582:
You forgot a '=back' before '=head2'
- Around line 584:
'=item' outside of any '=over'
- Around line 606:
You forgot a '=back' before '=head1'