Data::Direct - Perl module to emulate seqeuntial access to SQL tables.


Data-Direct documentation  | view source Contained in the Data-Direct distribution.

Index


NAME

Top

Data::Direct - Perl module to emulate seqeuntial access to SQL tables.

SYNOPSIS

Top

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:

DESCRIPTION

Top

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

Top

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.

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

Top

Ariel Brosh, schop@cpan.org

SEE ALSO

Top

DBI.


Data-Direct documentation  | view source Contained in the Data-Direct distribution.