SQL::Eval - Base for deriving evaluation objects for SQL::Statement |
SQL::Eval - Base for deriving evaluation objects for SQL::Statement
require SQL::Statement; require SQL::Eval;
# Create an SQL statement; use a concrete subclass of # SQL::Statement my $stmt = MyStatement->new("SELECT * FROM foo, bar", SQL::Parser->new('Ansi'));
# Get an eval object by calling open_tables; this # will call MyStatement::open_table my $eval = $stmt->open_tables($data);
# Set parameter 0 to 'Van Gogh' $eval->param(0, 'Van Gogh'); # Get parameter 2 my $param = $eval->param(2);
# Get the SQL::Eval::Table object referring the 'foo' table my $fooTable = $eval->table('foo');
This module implements two classes that can be used for deriving
subclasses to evaluate SQL::Statement objects. The SQL::Eval object
can be thought as an abstract state engine for executing SQL queries
and the SQL::Eval::Table object is a table abstraction. It implements
methods for fetching or storing rows, retrieving column names and
numbers and so on. See the test.pl
script as an example for
implementing a subclass.
While reading on, keep in mind that these are abstract classes, you *must* implement at least some of the methods described below. In addition, you need not derive from SQL::Eval or SQL::Eval::Table, you just need to implement the method interface.
All methods throw a Perl exception in case of errors.
$eval = SQL::Eval->new(\%attr);
Blesses the hash ref \%attr into the SQL::Eval class (or a subclass).
INSERT INTO foo VALUES (?, ?);
Example:
$eval->param(0, $val); # Set parameter 0 $eval->param(0); # Get parameter 0
$eval->params($params); # Set the array $eval->params(); # Get the array
$eval->table('foo', $fooTable); # Set the 'foo' table object $eval->table('foo'); # Return the 'foo' table object
$col = $eval->column('foo', 'id'); # Return the 'id' column of # the current row in the # 'foo' table
This is equivalent to and a shorthand for
$col = $eval->table('foo')->column('id');
_gen_access_fastpath
of the
referenced table.
$eval = SQL::Eval::Table->new(\%attr);
Blesses the hash ref \%attr into the SQL::Eval::Table class (or a subclass).
The following attributes are used by SQL::Eval::Table
:
col_names
.
column
and column_num
a subroutine reference is returned which
directly access the internal data structures. For all other cases a
subroutine directly calling $self->column($_[0])
is returned.
$table->fetchrow()
.
Example:
$row = $table->row();
$table->fetchrow()
. Example:
$col = $table->column($colName);
$colNum = $table->column_num($colNum);
The following capabilities are used (and requested) by SQL::Statement:
This capability is evaluated automatically on first request and must not be handled by any derived classes.
This capability is evaluated automatically on first request and must not be handled by derived classes.
inplace_update
.
This capability is evaluated automatically on first request and must not be handled by derived classes.
update_one_row
, update_specific_row
or update_current_row
.
The update_current_row
is only evaluated if the table has the
inplace_update
capability.
This capability is evaluated automatically on first request and must not be handled by derived classes.
Example: The table storage is using a hash on the PRIMARY KEY
of
the table. Real perl hashes do not care when an item is updated while
the hash is traversed using each
. SDBM_File
1.06 has a bug,
which does not adjust the traversal pointer when an item is deleted.
SQL::Statement::RAM::Table
recognizes such situations and adjusts
the traversal pointer.
This might not be possible for all implementations which can update single rows.
This capability could be provided by a derived class only.
This capability is evaluated automatically on first request and must not be handled by derived classes.
inplace_delete
capability.
This capability is evaluated automatically on first request and must not be handled by derived classes.
row-wise
delete capabilities are delete_one_row
and
delete_current_row
.
This capability is evaluated automatically on first request and must not be handled by derived classes.
This capability should be provided by a derived class only.
insert_new_row
.
This capability is evaluated automatically on first request and must not be handled by derived classes.
If the capabilities rowwise_update and insert_new_row are
provided, the table primitive push_row
is not required anymore and
may be omitted.
The above methods are implemented by SQL::Eval::Table. The following
methods are not, so that they *must* be implemented by the
subclass. See the DBD::DBM::Table
or DBD::CSV::Table
for
example.
$table-
drop($data)>.
undef
, if the last
row was already fetched. The argument $data is for private use of
the subclass. Example:
$row = $table->fetch_row($data);
Note, that you may use
$row = $table->row();
for retrieving the same row again, until the next call of fetch_row
.
SQL::Statement
requires that the last fetched row is available again
and again via $table-
row()>.
$table->push_row($data, $row);
$table->push_names($data, $names);
$table->seek($data, $whence, $rowNum);
Actually the current implementation only uses seek($data, 0, 0)
(first row) and seek($data, 2, 0)
(beyond last row, end of file).
$table->truncate($data);
The current implementation is quite simple: An SQL::Eval object is an
hash ref with only two attributes. The params
attribute is an array
ref of parameters. The tables
attribute is an hash ref of table
names (keys) and table objects (values).
SQL::Eval::Table instances are implemented as hash refs. Attributes
used are row
(the array ref of the current row), col_nums
(an
hash ref of column names as keys and column numbers as values) and
col_names
, an array ref of column names with the column numbers as
indexes.
All methods are working with instance-local data only, thus the module is reentrant and thread safe, if you either don't share handles between threads or grant serialized use.
Please report any bugs or feature requests to bug-sql-statement at
rt.cpan.org
, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html. I
will be notified, and then you will automatically be notified of
progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc SQL::Eval perldoc SQL::Statement
You can also look for information at:
Written by Jochen Wiedmann and currently maintained by Jens Rehsack.
This module is Copyright (C) 1998 by
Jochen Wiedmann Am Eisteich 9 72555 Metzingen Germany
Email: joe@ispsoft.de Phone: +49 7123 14887
and Copyright (C) 2009, 2010 by
Jens Rehsack < rehsackATcpan.org>
All rights reserved.
You may distribute this module under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
SQL::Eval - Base for deriving evaluation objects for SQL::Statement |