DATABASEACCESS
process statement
$sth = $dbi_interface -> process ("SELECT * FROM foo");
print "Table foo contains ", $sth -> rows, " rows.\n";
Processes statement by just combining the prepare and execute steps of the DBI. Returns statement
handle in case of success.
insert tablecolumnvalue [columnvalue] ...
$sth = $dbi_interface -> insert ('bar', drink => 'Caipirinha');
Inserts the given column/value pairs into table. Determines from the SQL data type which values has
to been quoted. Just pass a reference to the value to protect values with SQL functions from quoting.
update tableconditionscolumnvalue [columnvalue] ...
$dbi_interface -> update ('components', "table='ram'", price => 100);
$dbi_interface -> update ('components', "table='ram'", price => \"price + 20");
Updates any row of table which fulfill the conditions by inserting the given column/value pairs.
Scalar references can be used to embed strings without further quoting into the resulting SQL
statement. Returns the number of rows modified.
put tableconditionscolumnvalue [columnvalue] ...
delete tableconditions
$dbi_interface -> delete ('components', "stock=0");
Deletes any row of table which fulfill the conditions. Without conditions all rows are deleted.
Returns the number of rows deleted.
do_without_transaction statement
$sth = $dbi_interface -> do_without_transaction ("CREATE DATABASE foo");
Issues a DBI do statement while forcing autocommit. This is used for
statements that can't be run in transaction mode (like CREATE DATABASE
in PostgreSQL).
rows table [conditions]
$components = $dbi_interface -> rows ('components');
$components_needed = $dbi_interface -> rows ('components', 'stock = 0');
Returns the number of rows within table satisfying conditions if any.
makemap tablekeycolvalcol [condition]
$dbi_interface -> makemap ('components', 'idf', 'price');
$dbi_interface -> makemap ('components', 'idf', 'price', 'price > 10');
$dbi_interface -> makemap ('components', 'idf', '*');
$dbi_interface -> makemap ('components', 'idf', '*', 'price > 10');
Produces a mapping between the values within column keycol and column valcol from table. If an
condition is given, only rows matching this condition are used for the mapping.
In order to get the hash reference to the record as value of the mapping, use the asterisk as the
valcol parameter.
random_row tableconditions [map]
Returns random row of the specified table. If map is set, the result is a hash reference of the
selected row, otherwise an array reference. If the table doesn't contains rows, undefined is
returned.
serial tablesequence
Returns a serial number for table by querying the next value from sequence. Depending on the DBMS one
of the parameters is ignored. This is sequence for mSQL resp. table for PostgreSQL. mysql doesn't
support sequences, but the AUTO_INCREMENT keyword for fields. In this case this method returns 0 and
mysql generates a serial number for this field.
fill sthhashref [flagcolumn ...]
Fetches the next table row from the result stored into sth and records the value of each field in
hashref. If flag is set, only the fields specified by the column arguments are considered, otherwise
the fields specified by the column arguments are omitted.
view table [namevalue ...]
foreach my $table (sort $dbi_interface -> tables)
{
print $cgi -> h2 ('Contents of ', $cgi -> code ($table));
print $dbi_interface -> view ($table);
}
Produces plain text representation of the database table table. This method accepts the following
options as name/value pairs:
columns: Which columns to display.
order: Which column to sort the row after.
limit: Maximum number of rows to display.
separator: Separator inserted between the columns.
where: Display only rows matching this condition.
print $dbi_interface -> view ($table,
order => $cgi -> param ('order') || '',
where => "price > 0");
DATABASEINFORMATION
is_table NAME
Returns truth value if there exists a table NAME in this database.
tables
Returns list of all tables in this database.
sequences
Returns list of all sequences in this database (Postgres only).
columns TABLE
Returns list of the column names of TABLE.
types TABLE
Returns list of the column types of TABLE.
sizes TABLE
Returns list of the column sizes of TABLE.
typemap TABLE
Returns mapping between column names and column types for table TABLE.
sizemap TABLE
Returns mapping between column names and column sizes for table TABLE.
TIMEVALUES
now
$dbi_interface -> insert ('transaction',
id => serial ('transaction', 'transactionid'),
time => \$dbi_interface -> now);
Returns representation for the current time. Uses special values of the DBMS if possible.
MONETARYVALUES
money2num money
Converts the monetary value money to a numeric one.
MISCELLANEOUS
is_auth_error msg
This method decides if the error message msg is caused by an authentification error or not.