TABLEOp - Module for Table level operations
use TABLEop; $titles = new TABLEop ( $dbh, "titles" ); $titles->insert ( \%data ); $titles->update ( \%data, \%where ); $titles->delete ( \%where ); @all_rows = $titles->select (" where title_id < 10 "); %one_row = $titles->select ( " where title_id = 4 ");
These routines allow you to treat your data as hashes. They generate insert, delete, update statments and actually run them against the server. It does the work of generating sql for you. It puts the necessary quotes if the datatype is char, datetime etc. Additionally you could also do select and get all rows as an array of hash-references or get just one row as a single hash-reference. Specification of table follows the usual Sybase conventions, i.e. if you did not specify absolute name, it looks if the user has a table by the same name. The module remembers the full path name of the table and uses it for all operations. This avoids the risk of inadvertant changes to your application's database context.
use TABLEop; $titles = new TABLEop ( $dbh, "titles" );
%data = ('title_id' => 50, 'title' => 'Perl Book', 'price' => 50.24, 'pub_date' => 'Jan 1 1900' ); $titles->insert ( \%data );
%where = ( 'title_id' => 50 ); $titles->delete ( \%where );
%data = ('title' => 'Perl New Book', 'price' => 150.24, 'pub_date' => 'Jan 1 2100' ); %where = ('title_id' = 50 ); $titles->update ( \%data, \%where );
The select behaves defferently depending on whether you are expecting one row OR many rows. If you wantarray, you get an Array of hash-references, else you get just a single hash-reference. @all_rows = $titles->select ("where title_id < 50"); OR @all_rows = $titles->select (""); #Select all the rows ! foreach $row ( @all_rows) { printf "title is %s\n", $row->{'title'}; } OR you could, $arow = $title->select ( "where title_id = 30"); printf "The title is %s.\n", $arow->{'title');
Currently does not handle NULL in update/delete/insert. This will cause an error. All error handling is left to the caller. It would be nice to automatically generate single row updates by figuring out unique key columns. Manish I Shah mshah@bfm.com
2 POD Errors
The following errors were encountered while parsing the POD:
=over without closing =back
Unknown directive: =back1
To install Sybase::BCP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sybase::BCP
CPAN shell
perl -MCPAN -e shell install Sybase::BCP
For more information on module installation, please visit the detailed CPAN module installation guide.