NAME

DBI::FrontEnd - provide soft and convenient interface to the DBI manpage.


DESCRIPTION

This package is front end to DBI package, providing interface to SQL queries. In developement.


SYNOPSIS

  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();


REQUIREMENTS

the DBI manpage, the Exception manpage, the Debug manpage


CONSTANTS

$DRIV, $NAME, $USER, $PASS
$TEXT{N}_TYPE, {N} = 1..8
Customizable DataBase details.


CONSTRUCTOR

new

description
Creates instance of front-end-to-DBI object.

parameters
All parameters are optional.
  * 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.

returns
Reference to a new created object.


METHODS

connect

description
Connects to appropriated DB driver of DBI. Called automatically on first query if needed.

returns
  *  0 - on success.
  * -1 - already connected.
Throws exception, if can't connect.

disconnect

description
Disconnects from appropriated DB driver of DBI. Called automatically on DESTROY if needed.

returns
  *  0 - on success
  * -1 - already disconnected
Throws exception, if can't disconnect.

do

description
Executes SQL statement.

returns
1 on success, otherwise throws exception.

prepare

description
NOT USED. Like DBD::prepare.

returns
Statement handle ($sth), which can accept execute, fetch and finish.

fields

description
Returns field names of rows collected by collect rows.

synopsis
  print "Field names: ", join(", ", $db->fields());
  print "Field names: ", join(", ", @{$db->fields()});  # the same
returns
Array when wantarray, and reference to array otherwise.

values

description
Returns collected by collect rows. Has 4 cases (actually 7). First three cases can return reference to array or array itself, depending on wantarray.

synopsis
  1. $db->values()
  2. $db->values(row_index)
  3. $db->values(undef, col_index)
  4. $db->values(row_index, col_index)
returns
  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.

collect

description
Executes select SQL statement and collects all rows to be accessed by values and all colomn names by fields.

synopsis
  $db->collect('select id from article where last_modified > 909513874');
  my $values = $db->values;
parameters
SQL statement

returns
Number of collected rows. On failure throws exception.

select

description
Executes select SQL statement and collects all rows to be accessed by values and all colomn names by fields.

synopsis
  $db->select($table_name, $fields, $condition);
  my $values = $db->values;
parameters
  * table_name - table name (scalar)
  * fields - field names (array ref), empty [] means all "*" fields
  * condition - select (where) condition (scalar)
returns
Number of collected rows. On failure throws exception.

quote

description
Quotes string value to be ok in SQL queries.

synopsis
  $db->quote($field_value)
example
  $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.

returns
Quoted string (including enclosing single quotes).

insert

description
Forms and executes insert SQL statement.

synopsis
  $db->insert($table_name, $array_of_fields, $array_of_values)
example
  $db->insert("article", ['id', 'name', 'body'], ["100", "John Cohen", $body]);
returns
Calls do method and returns its returning value, which is: 1 on success, otherwise throws exception.

update

description
Forms and executes update SQL statement.

synopsis
  $db->update($table_name, $array_of_fields, $array_of_values, $condition)
example
  $db->update("article", ['author', 'date'], ["John Cohen", '14/10/97'], "id = 1");
returns
Calls do method and returns its returning value, which is: 1 on success, otherwise throws exception.

delete

description
Forms and executes delete SQL statement.

synopsis
  $db->delete($table_name, $condition)
example
  $db->delete("article", "id = 1");
  $db->delete("article", [["lang", "Eng"], ["active", 0]]);
parameters
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.

returns
Calls do method and returns its returning value, which is: 1 on success, otherwise throws exception.

drop

description
Forms and executes drop SQL statement.

synopsis
  $db->drop($table_name)
example
  $db->drop("article");
returns
Calls do method and returns its returning value, which is: 1 on success, otherwise throws exception.

set_auto_commit

description
Sets AutoCommit attribute of DBI. If set, every change to db is non-recoverable (usually needed otside transactions).

parameters
The value to set (0 or 1).

get_constant

description
Returns the constant value of the package by constant name.

synopsis
  $db->get_constant('TEXT1_TYPE')
returns
Scalar representing constant value or undef. Throws an exception, if no constant with the given name is defined.


TODO

Add methods, parallel to DBD::driver functions.