1SQL::Eval(3)          User Contributed Perl Documentation         SQL::Eval(3)
2
3
4

NAME

6       SQL::Eval - Base for deriving evalution objects for SQL::Statement
7

SYNOPSIS

9           require SQL::Statement;
10           require SQL::Eval;
11
12           # Create an SQL statement; use a concrete subclass of
13           # SQL::Statement
14           my $stmt = MyStatement->new("SELECT * FROM foo, bar",
15                                       SQL::Parser->new('Ansi'));
16
17           # Get an eval object by calling open_tables; this
18           # will call MyStatement::open_table
19           my $eval = $stmt->open_tables($data);
20
21           # Set parameter 0 to 'Van Gogh'
22           $eval->param(0, 'Van Gogh');
23           # Get parameter 2
24           my $param = $eval->param(2);
25
26           # Get the SQL::Eval::Table object referring the 'foo' table
27           my $fooTable = $eval->table('foo');
28

DESCRIPTION

30       This module implements two classes that can be used for deriving con‐
31       crete subclasses to evaluate SQL::Statement objects. The SQL::Eval
32       object can be thought as an abstract state engine for executing SQL
33       queries, the SQL::Eval::Table object can be considered a *very* table
34       abstraction. It implements method for fetching or storing rows,
35       retrieving column names and numbers and so on.  See the "test.pl"
36       script as an example for implementing a concrete subclass.
37
38       While reading on, keep in mind that these are abstract classes, you
39       *must* implement at least some of the methods describe below.  Even
40       more, you need not derive from SQL::Eval or SQL::Eval::Table, you just
41       need to implement the method interface.
42
43       All methods just throw a Perl exception in case of errors.
44
45       Method interface of SQL::Eval
46
47       new     Constructor; use it like this:
48
49                   $eval = SQL::Eval->new(\%attr);
50
51               Blesses the hash ref \%attr into the SQL::Eval class (or a sub‐
52               class).
53
54       param   Used for getting or setting input parameters, as in the SQL
55               query
56
57                   INSERT INTO foo VALUES (?, ?);
58
59               Example:
60
61                   $eval->param(0, $val);        # Set parameter 0
62                   $eval->param(0);              # Get parameter 0
63
64       params  Likewise used for getting or setting the complete array of
65               input parameters. Example:
66
67                   $eval->params($params);       # Set the array
68                   $eval->params();              # Get the array
69
70       table   Returns or sets a table object. Example:
71
72                   $eval->table('foo', $fooTable);  # Set the 'foo' table object
73                   $eval->table('foo');             # Return the 'foo' table object
74
75       column  Return the value of a column with a given name; example:
76
77                   $col = $eval->column('foo', 'id');  # Return the 'id' column of
78                                                       # the current row in the
79                                                       # 'foo' table
80
81               This is equivalent and just a shorthand for
82
83                   $col = $eval->table('foo')->column('id');
84
85       Method interface of SQL::Eval::Table
86
87       new     Constructor; use it like this:
88
89                   $eval = SQL::Eval::Table->new(\%attr);
90
91               Blesses the hash ref \%attr into the SQL::Eval::Table class (or
92               a subclass).
93
94       row     Used to get the current row as an array ref. Do not mismatch
95               getting the current row with the fetch_row method! In fact this
96               method is valid only after a successfull "$table->fetchrow()".
97               Example:
98
99                   $row = $table->row();
100
101       column  Get the column with a given name in the current row. Valid only
102               after a successfull "$table->fetchrow()". Example:
103
104                   $col = $table->column($colName);
105
106       column_num
107               Return the number of the given column name. Column numbers
108               start with 0. Returns undef, if a column name is not defined,
109               so that you can well use this for verifying valid column names.
110               Example:
111
112                   $colNum = $table->column_num($colNum);
113
114       column_names
115               Returns an array ref of column names.
116
117       The above methods are implemented by SQL::Eval::Table. The following
118       methods aren't, so that they *must* be implemented by concrete sub‐
119       classed. See the "test.pl" script for example.
120
121       fetch_row
122               Fetches the next row from the table. Returns "undef", if the
123               last row was already fetched. The argument $data is for private
124               use of the concrete subclass. Example:
125
126                   $row = $table->fetch_row($data);
127
128               Note, that you may use
129
130                   $row = $table->row();
131
132               for retrieving the same row again, until the next call of
133               "fetch_row".
134
135       push_row
136               Likewise for storing rows. Example:
137
138                   $table->push_row($data, $row);
139
140       push_names
141               Used by the CREATE TABLE statement to set the column names of
142               the new table. Receives an array ref of names. Example:
143
144                   $table->push_names($data, $names);
145
146       seek    Similar to the seek method of a filehandle; used for setting
147               the number of the next row being written. Example:
148
149                   $table->seek($data, $whence, $rowNum);
150
151               Actually the current implementation is using only "seek($data,
152               0,0)" (first row) and "seek($data, 2,0)" (last row, end of
153               file).
154
155       truncate
156               Truncates a table after the current row. Example:
157
158                   $table->truncate($data);
159

INTERNALS

161       The current implementation is quite simple: An SQL::Eval object is an
162       hash ref with only two attributes. The "params" attribute is an array
163       ref of parameters. The "tables" attribute is an hash ref of table names
164       (keys) and table objects (values).
165
166       SQL::Eval::Table instances are implemented as hash refs. Used
167       attributes are "row" (the array ref of the current row), "col_nums" (an
168       hash ref of column names as keys and column numbers as values) and
169       "col_names", an array ref of column names with the column numbers as
170       indexes.
171

MULTITHREADING

173       All methods are working with instance-local data only, thus the module
174       is reentrant and thread safe, if you either don't share handles between
175       threads or grant serialized use.
176
178       This module is Copyright (C) 1998 by
179
180           Jochen Wiedmann
181           Am Eisteich 9
182           72555 Metzingen
183           Germany
184
185           Email: joe@ispsoft.de
186           Phone: +49 7123 14887
187
188       All rights reserved.
189
190       You may distribute this module under the terms of either the GNU Gen‐
191       eral Public License or the Artistic License, as specified in the Perl
192       README file.
193

SEE ALSO

195       SQL::Statement(3)
196
197
198
199perl v5.8.8                       2005-04-18                      SQL::Eval(3)
Impressum