DBI::FrontEnd - provide soft and convenient interface to the DBI manpage.
This package is front end to DBI package, providing interface to SQL queries. In developement.
use DBI::FrontEnd; my $db = DBI::FrontEnd->new(@params);
# not really needed, connected automatically on the first query $db->connect();
$db->insert("article", ['id', 'name'], [1, 'News Today']);
$db->update("article", ['name'], ['News Yesterday'], [['id', 1]]);
$db->select("article", [], [['id', 1]]);
print join(", ", $db->values(0)), "\n";
# the same as the two lines above:
$db->collect("select * from article where id = 1");
print join(", ", $db->values(0)), "\n";
# the same as the two lines above:
#use DBI;
#$sth = $db->prepare("select * from table where id = 1");
#$sth->execute;
#print join(", ", $sth->fetch), "\n";
#$sth->finish;
$db->delete("article", [['id', 1]]);
# not really needed, disconnected automatically on DESTROY $db->disconnect();
the DBI manpage, the Exception manpage, the Debug manpage
* driv - DBD driver name (if not specified C<$DRIV> is taken) * name - database name (if not specified C<$NAME> is taken) * user - user name (if not specified C<$USER> is taken) * pass - password (if not specified C<$PASS> is taken)
driv is normally scalar, like 'Oracle', but can be array ref,
like ['Oracle', 'ODBC']. In this case DBD::ODBC used, but it is supposed
we work with oracle.
* 0 - on success. * -1 - already connected. Throws exception, if can't connect.
* 0 - on success * -1 - already disconnected Throws exception, if can't disconnect.
print "Field names: ", join(", ", $db->fields());
print "Field names: ", join(", ", @{$db->fields()}); # the same
1. $db->values() 2. $db->values(row_index) 3. $db->values(undef, col_index) 4. $db->values(row_index, col_index)
1. [ref to] array of references to rows (arrays of data values) 2. [ref to] row number row_index (array of data values) 3. [ref to] column number col_index (array of data values) 4. data value on row number row_index, column number col_index
When requesting array and not wantarray, the reference to an array is returned, so there are actually 7 return cases depending on parameters and wantarray.
select SQL statement and collects all rows to be accessed
by values and all colomn names by fields.
$db->collect('select id from article where last_modified > 909513874');
my $values = $db->values;
select SQL statement and collects all rows to be accessed
by values and all colomn names by fields.
$db->select($table_name, $fields, $condition); my $values = $db->values;
* table_name - table name (scalar) * fields - field names (array ref), empty [] means all "*" fields * condition - select (where) condition (scalar)
$db->quote($field_value)
$db->quote(q{this "is" a 'test' \value})
Returns string 'this ``is'' a ''test'' \value' for Oracle, and 'this \``is\'' a \'test\' \\value' for Pg.
insert SQL statement.
$db->insert($table_name, $array_of_fields, $array_of_values)
$db->insert("article", ['id', 'name', 'body'], ["100", "John Cohen", $body]);
do method and returns its returning value, which is:
1 on success, otherwise throws exception.
update SQL statement.
$db->update($table_name, $array_of_fields, $array_of_values, $condition)
$db->update("article", ['author', 'date'], ["John Cohen", '14/10/97'], "id = 1");
do method and returns its returning value, which is:
1 on success, otherwise throws exception.
delete SQL statement.
$db->delete($table_name, $condition)
$db->delete("article", "id = 1");
$db->delete("article", [["lang", "Eng"], ["active", 0]]);
table_name - name of the table to delete from
condition - string, which goes after ``where '';
or array of form: [ [ field, value ]* ],
from which where clause will be composed;
or undef, in this case all rows will be deleted from the table.
do method and returns its returning value, which is:
1 on success, otherwise throws exception.
drop SQL statement.
$db->drop($table_name)
$db->drop("article");
do method and returns its returning value, which is:
1 on success, otherwise throws exception.
$db->get_constant('TEXT1_TYPE')
Add methods, parallel to DBD::driver functions.