NAME

DBIx::Array - This modules is a wrapper around DBI with array interfaces

SYNOPSIS

use DBIx::Array;
$dba->connect($connection, $user, $pass, \%opt); #passed to DBI
my @array=$dba->sqlarray($sql, @params);

DESCRIPTION

USAGE

CONSTRUCTOR

new

my $dba = DBIx::Array->new();

METHODS

initialize

name

Set or returns a user friendly identification string for this database connection

my $name=$sdb->name;
my $name=$sdb->name($string);

connect

Connects to the database and returns the database handle.

$dba->connect($connection, $user, $pass, \%opt);

disconnect

Calls $dbh->disconnect

$dba->disconnect;

commit

rollback

AutoCommit

RaiseError

errstr

Returns $DBI::errstr

dbh

Sets or returns the database handle object.

$dba->dbh;
$dba->dbh($dbh);  #if you don't use DBI.

sqlcursor

Returns the SQL cursor so that you can use the cursor elsewhere.

sqlscalar

Returns the SQL query as a scalar.

This works great for selecting one value.

$scalar=$dba->sqlscalar($sql, @parameters);

sqlarray

Returns the SQL query as an array or array reference.

This works great for selecting one column from a table or selecting one row from a table.

$array=$dba->sqlarray($sql, @parameters);
@array=$dba->sqlarray($sql, @parameters);

sqlhash

Returns the first two columns of the SQL query as a hash or hash reference {Key=>Value, Key=>Value, ...}

$hash=$dba->sqlhash($sql, @parameters);
%hash=$dba->sqlhash($sql, @parameters);
@hash=$dba->sqlhash($sql, @parameters); #this is ordered
@keys=grep {!($n++ % 2)} @hash;         #ordered keys

sqlarrayarray

Returns the SQL data as an array or array ref of array references ([],[],...) or [[],[],...]

$array=$dba->sqlarrayarray($sql, @parameters);
@array=$dba->sqlarrayarray($sql, @parameters);

sqlarrayarrayname

Returns the SQL data as an array or array ref of array references ([],[],...) or [[],[],...] where the first rows is the column names

$array=$dba->sqlarrayarrayname($sql, @parameters);
@array=$dba->sqlarrayarrayname($sql, @parameters);

_sqlarrayarray

$array=$dba->_sqlarrayarray(sql=>$sql, param=>\@parameters, name=>1);
@array=$dba->_sqlarrayarray(sql=>$sql, param=>\@parameters, name=>1);
$array=$dba->_sqlarrayarray(sql=>$sql, param=>\@parameters, name=>0);
@array=$dba->_sqlarrayarray(sql=>$sql, param=>\@parameters, name=>0);

sqlarrayhash

Returns the SQL data as an array or array ref of hash references ({},{},...) or [{},{},...]

$array=$dba->sqlarrayhash($sql, @parameters);
@array=$dba->sqlarrayhash($sql, @parameters);

sqlarrayhashname

Returns the SQL of data as an array or array ref of hash references ([],{},{},...) or [[],{},{},...] where the first rows is an array reference of the column names

$array=$dba->sqlarrayhashname($sql, @parameters);
@array=$dba->sqlarrayhashname($sql, @parameters);

_sqlarrayhash

Returns the SQL data as an array or array ref of hash references ({},{},...) or [{},{},...]

$array=$dba->_sqlarrayhash(sql=>$sql, param=>\@parameters, name=>1);
@array=$dba->_sqlarrayhash(sql=>$sql, param=>\@parameters, name=>1);
$array=$dba->_sqlarrayhash(sql=>$sql, param=>\@parameters, name=>0);
@array=$dba->_sqlarrayhash(sql=>$sql, param=>\@parameters, name=>0);

sqlsort

Returns the SQL statments with the correct ORDER BY clause given a SQL statment (without an ORDER BY clause) and a signed integer on which column to sort.

my $sql=$dba->sqlsort(qq{SELECT 1,'Z' FROM DUAL UNION SELECT 2,'A' FROM DUAL}, -2);

Returns

SELECT 1,'Z' FROM DUAL UNION SELECT 2,'A' FROM DUAL ORDER BY 2 DESC

See also the STOP::HTML->sqlarrayarraynamesort function

sqlarrayarraynamesort

Returns a sqlarrayarrayname for $sql sorted on column $n where n is an integer asending for positive, desending for negative, and 0 for no sort.

my $data=$dba->sqlarrayarraynamesort($sql, $n, @parameters);

Note: $sql must not have an "ORDER BY" clause in order for this function to work corectly.

update, delete, exec, execute

Returns the number of rows updated or deleted by the SQL statement.

$rows=$dba->update($sql, @parameters);
$rows=$dba->delete($sql, @parameters);

Remember to commit or use AutoCommit

TODO

I would like to add caching service in the sqlcursor method.

BUGS

SUPPORT

AUTHOR

Michael R. Davis
CPAN ID: MRDVT
STOP, LLC
domain=>stopllc,tld=>com,account=>mdavis
http://www.stopllc.com/

COPYRIGHT

This program is free software licensed under the...

The BSD License

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO