home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_11eada26c4f0c893423d214e34e80f99
< prev
next >
Wrap
Text File
|
2000-03-23
|
10KB
|
263 lines
<HTML>
<HEAD>
<TITLE>SQL::Eval - Base for deriving evalution objects for SQL::Statement</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> SQL::Eval - Base for deriving evalution objects for SQL::Statement</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<UL>
<LI><A HREF="#method interface of sql::eval">Method interface of SQL::Eval</A></LI>
<LI><A HREF="#method interface of sql::eval::table">Method interface of SQL::Eval::Table</A></LI>
</UL>
<LI><A HREF="#internals">INTERNALS</A></LI>
<LI><A HREF="#multithreading">MULTITHREADING</A></LI>
<LI><A HREF="#author and copyright">AUTHOR AND COPYRIGHT</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>SQL::Eval - Base for deriving evalution objects for SQL::Statement</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
require SQL::Statement;
require SQL::Eval;</PRE>
<PRE>
# Create an SQL statement; use a concrete subclass of
# SQL::Statement
my $stmt = MyStatement->new("SELECT * FROM foo, bar",
SQL::Parser->new('Ansi'));</PRE>
<PRE>
# Get an eval object by calling open_tables; this
# will call MyStatement::open_table
my $eval = $stmt->open_tables($data);</PRE>
<PRE>
# Set parameter 0 to 'Van Gogh'
$eval->param(0, 'Van Gogh');
# Get parameter 2
my $param = $eval->param(2);</PRE>
<PRE>
# Get the SQL::Eval::Table object referring the 'foo' table
my $fooTable = $eval->table('foo');</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>This module implements two classes that can be used for deriving
concrete subclasses to evaluate SQL::Statement objects. The
SQL::Eval object can be thought as an abstract state engine for
executing SQL queries, the SQL::Eval::Table object can be considered
a *very* table abstraction. It implements method for fetching or
storing rows, retrieving column names and numbers and so on.
See the <CODE>test.pl</CODE> script as an example for implementing a concrete
subclass.</P>
<P>While reading on, keep in mind that these are abstract classes,
you *must* implement at least some of the methods describe below.
Even more, you need not derive from SQL::Eval or SQL::Eval::Table,
you just need to implement the method interface.</P>
<P>All methods just throw a Perl exception in case of errors.</P>
<P>
<H2><A NAME="method interface of sql::eval">Method interface of SQL::Eval</A></H2>
<DL>
<DT><STRONG><A NAME="item_new">new</A></STRONG><BR>
<DD>
Constructor; use it like this:
<PRE>
$eval = SQL::Eval->new(\%attr);</PRE>
<P>Blesses the hash ref \%attr into the SQL::Eval class (or a subclass).</P>
<P></P>
<DT><STRONG><A NAME="item_param">param</A></STRONG><BR>
<DD>
Used for getting or setting input parameters, as in the SQL query
<PRE>
INSERT INTO foo VALUES (?, ?);</PRE>
<P>Example:</P>
<PRE>
$eval->param(0, $val); # Set parameter 0
$eval->param(0); # Get parameter 0</PRE>
<P></P>
<DT><STRONG><A NAME="item_params">params</A></STRONG><BR>
<DD>
Likewise used for getting or setting the complete array of input
parameters. Example:
<PRE>
$eval->params($params); # Set the array
$eval->params(); # Get the array</PRE>
<P></P>
<DT><STRONG><A NAME="item_table">table</A></STRONG><BR>
<DD>
Returns or sets a table object. Example:
<PRE>
$eval->table('foo', $fooTable); # Set the 'foo' table object
$eval->table('foo'); # Return the 'foo' table object</PRE>
<P></P>
<DT><STRONG><A NAME="item_column">column</A></STRONG><BR>
<DD>
Return the value of a column with a given name; example:
<PRE>
$col = $eval->column('foo', 'id'); # Return the 'id' column of
# the current row in the
# 'foo' table</PRE>
<P>This is equivalent and just a shorthand for</P>
<PRE>
$col = $eval->table('foo')->column('id');</PRE>
<P></P></DL>
<P>
<H2><A NAME="method interface of sql::eval::table">Method interface of SQL::Eval::Table</A></H2>
<DL>
<DT><STRONG>new</STRONG><BR>
<DD>
Constructor; use it like this:
<PRE>
$eval = SQL::Eval::Table->new(\%attr);</PRE>
<P>Blesses the hash ref \%attr into the SQL::Eval::Table class (or a
subclass).</P>
<P></P>
<DT><STRONG><A NAME="item_row">row</A></STRONG><BR>
<DD>
Used to get the current row as an array ref. Do not mismatch
getting the current row with the fetch_row method! In fact this
method is valid only after a successfull <CODE>$table->fetchrow()</CODE>.
Example:
<PRE>
$row = $table->row();</PRE>
<P></P>
<DT><STRONG>column</STRONG><BR>
<DD>
Get the column with a given name in the current row. Valid only after
a successfull <CODE>$table->fetchrow()</CODE>. Example:
<PRE>
$col = $table->column($colName);</PRE>
<P></P>
<DT><STRONG><A NAME="item_column_num">column_num</A></STRONG><BR>
<DD>
Return the number of the given column name. Column numbers start with
0. Returns undef, if a column name is not defined, so that you can
well use this for verifying valid column names. Example:
<PRE>
$colNum = $table->column_num($colNum);</PRE>
<P></P>
<DT><STRONG><A NAME="item_column_names">column_names</A></STRONG><BR>
<DD>
Returns an array ref of column names.
<P></P></DL>
<P>The above methods are implemented by SQL::Eval::Table. The following
methods aren't, so that they *must* be implemented by concrete
subclassed. See the <CODE>test.pl</CODE> script for example.</P>
<DL>
<DT><STRONG><A NAME="item_fetch_row">fetch_row</A></STRONG><BR>
<DD>
Fetches the next row from the table. Returns <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A>, if the last
row was already fetched. The argument $data is for private use of
the concrete subclass. Example:
<PRE>
$row = $table->fetch_row($data);</PRE>
<P>Note, that you may use</P>
<PRE>
$row = $table->row();</PRE>
<P>for retrieving the same row again, until the next call of <A HREF="#item_fetch_row"><CODE>fetch_row</CODE></A>.</P>
<P></P>
<DT><STRONG><A NAME="item_push_row">push_row</A></STRONG><BR>
<DD>
Likewise for storing rows. Example:
<PRE>
$table->push_row($data, $row);</PRE>
<P></P>
<DT><STRONG><A NAME="item_push_names">push_names</A></STRONG><BR>
<DD>
Used by the <EM>CREATE TABLE</EM> statement to set the column names of the
new table. Receives an array ref of names. Example:
<PRE>
$table->push_names($data, $names);</PRE>
<P></P>
<DT><STRONG><A NAME="item_seek">seek</A></STRONG><BR>
<DD>
Similar to the seek method of a filehandle; used for setting the number
of the next row being written. Example:
<PRE>
$table->seek($data, $whence, $rowNum);</PRE>
<P>Actually the current implementation is using only <A HREF="#item_seek"><CODE>seek($data, 0,0)</CODE></A>
(first row) and <A HREF="#item_seek"><CODE>seek($data, 2,0)</CODE></A> (last row, end of file).</P>
<P></P>
<DT><STRONG><A NAME="item_truncate">truncate</A></STRONG><BR>
<DD>
Truncates a table after the current row. Example:
<PRE>
$table->truncate($data);</PRE>
<P></P></DL>
<P>
<HR>
<H1><A NAME="internals">INTERNALS</A></H1>
<P>The current implementation is quite simple: An SQL::Eval object is an
hash ref with only two attributes. The <A HREF="#item_params"><CODE>params</CODE></A> attribute is an array
ref of parameters. The <CODE>tables</CODE> attribute is an hash ref of table
names (keys) and table objects (values).</P>
<P>SQL::Eval::Table instances are implemented as hash refs. Used attributes
are <A HREF="#item_row"><CODE>row</CODE></A> (the array ref of the current row), <CODE>col_nums</CODE> (an hash ref
of column names as keys and column numbers as values) and <CODE>col_names</CODE>,
an array ref of column names with the column numbers as indexes.</P>
<P>
<HR>
<H1><A NAME="multithreading">MULTITHREADING</A></H1>
<P>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.</P>
<P>
<HR>
<H1><A NAME="author and copyright">AUTHOR AND COPYRIGHT</A></H1>
<P>This module is Copyright (C) 1998 by</P>
<PRE>
Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Germany</PRE>
<PRE>
Email: joe@ispsoft.de
Phone: +49 7123 14887</PRE>
<P>All rights reserved.</P>
<P>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.</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><A HREF="../../../SQL/Statement(3).html">the SQL::Statement(3) manpage</A></P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> SQL::Eval - Base for deriving evalution objects for SQL::Statement</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>