1SQL::Statement(3) User Contributed Perl Documentation SQL::Statement(3)
2
3
4
6 SQL::Statement - SQL parsing and processing engine
7
9 # ... depends on what you want to do, see below
10
12 The SQL::Statement module implements a pure Perl SQL parsing and
13 execution engine. While it by no means implements full ANSI standard,
14 it does support many features including column and table aliases,
15 built-in and user-defined functions, implicit and explicit joins,
16 complex nested search conditions, and other features.
17
18 SQL::Statement is a small embeddable Database Management System (DBMS).
19 This means that it provides all of the services of a simple DBMS except
20 that instead of a persistent storage mechanism, it has two things: 1)
21 an in-memory storage mechanism that allows you to prepare, execute, and
22 fetch from SQL statements using temporary tables and 2) a set of
23 software sockets where any author can plug in any storage mechanism.
24
25 There are three main uses for SQL::Statement. One or another (hopefully
26 not all) may be irrelevant for your needs: 1) to access and manipulate
27 data in CSV, XML, and other formats 2) to build your own DBD for a new
28 data source 3) to parse and examine the structure of SQL statements.
29
31 There are no prerequisites for using this as a standalone parser. If
32 you want to access persistent stored data, you either need to write a
33 subclass or use one of the DBI DBD drivers. You can install this
34 module using CPAN.pm, CPANPLUS.pm, PPM, apt-get, or other packaging
35 tools or you can download the tar.gz file from CPAN and use the
36 standard perl mantra:
37
38 perl Makefile.PL
39 make
40 make test
41 make install
42
43 It works fine on all platforms it has been tested on. On Windows, you
44 can use ppm or with the mantra use nmake, dmake, or make depending on
45 which is available.
46
48 How can I use SQL::Statement to access and modify data?
49 SQL::Statement provides the SQL engine for a number of existing DBI
50 drivers including DBD::CSV, DBD::DBM, DBD::AnyData, DBD::Excel,
51 DBD::Amazon, and others.
52
53 These modules provide access to Comma Separated Values, Fixed Length,
54 XML, HTML and many other kinds of text files, to Excel Spreadsheets, to
55 BerkeleyDB and other DBM formats, and to non-traditional data sources
56 like on-the-fly Amazon searches.
57
58 If you are interested in accessing and manipulating persistent data,
59 you may not really want to use SQL::Statement directly, but use DBI
60 along with one of the DBDs mentioned above instead. You will be using
61 SQL::Statement, but under the hood of the DBD. See
62 <http://dbi.perl.org> for help with DBI and see SQL::Statement::Syntax
63 for a description of the SQL syntax that SQL::Statement provides for
64 these modules and see the documentation for whichever DBD you are using
65 for additional details.
66
67 How can I use it to parse and examine the structure of SQL statements?
68 SQL::Statement can be used stand-alone (without a subclass and without
69 DBI) to parse and examine the structure of SQL statements. See
70 SQL::Statement::Structure for details.
71
72 How can I use it to embed a SQL engine in a DBD or other module?
73 SQL::Statement is designed to be easily embedded in other modules and
74 is especially suited for developing new DBI drivers (DBDs). See
75 SQL::Statement::Embed.
76
77 What SQL Syntax is supported?
78 SQL::Statement supports a small but powerful subset of SQL commands.
79 See SQL::Statement::Syntax.
80
81 How can I extend the supported SQL syntax?
82 You can modify and extend the SQL syntax either by issuing SQL commands
83 or by subclassing SQL::Statement. See SQL::Statement::Syntax.
84
86 SQL::Statement is a large module with many potential future directions.
87 You are invited to help plan, code, test, document, or kibbitz about
88 these directions. If you want to join the development team, or just
89 hear more about the development, write Jeff (<jzuckerATcpan.org>) or
90 Jens (<rehsackATcpan.org>) a note.
91
93 The following methods can or must be overridden by derived classes.
94
95 capability
96 $has_capability = $h->capability('capability_name');
97
98 Returns a true value if the specified capability is available.
99
100 Currently no capabilities are defined and this is a placeholder for
101 future use. It is envisioned it will be used like
102 "SQL::Eval::Table::capability".
103
104 open_table
105 The "open_table" method must be overridden by derived classes to
106 provide the capability of opening data tables. This is a necessity.
107
108 Arguments given to open_table call:
109
110 $data
111 The database memo parameter. See "execute".
112
113 $table
114 The name of the table to open as parsed from SQL statement.
115
116 $createMode
117 A flag indicating the mode ("CREATE TABLE ...") the table should be
118 opened with. Set to a true value in create mode.
119
120 $lockMode
121 A flag indicating whether the table should be opened for writing
122 (any other than "SELECT ..."). Set to a true value if the table is
123 to be opened for write access.
124
125 The following methods are required to use SQL::Statement in a DBD (for
126 example).
127
128 new
129 Instantiates a new SQL::Statement object.
130
131 Arguments:
132
133 $sql
134 The SQL statement for later actions.
135
136 $parser
137 An instance of a SQL::Parser object or flags for it's
138 instantiation. If omitted, default flags are used.
139
140 When the basic initialization is completed, "$self->prepare($sql,
141 $parser)" is invoked.
142
143 prepare
144 Prepares SQL::Statement to execute a SQL statement.
145
146 Arguments:
147
148 $sql
149 The SQL statement to parse and prepare.
150
151 $parser
152 Instance of a SQL::Parser object to parse the provided SQL
153 statement.
154
155 execute
156 Executes a prepared statement.
157
158 Arguments:
159
160 $data
161 Memo field passed through to calls of the instantiated $table
162 objects or "open_table" calls. In "CREATE" with subquery,
163 "$data->{Database}" must be a DBI database handle object.
164
165 $params
166 Bound params via DBI ...
167
168 errstr
169 Gives the error string of the last error, if any.
170
172 You can find documentation for this module with the perldoc command.
173
174 perldoc SQL::Statement
175
176 You can also look for information at:
177
178 · RT: CPAN's request tracker
179
180 http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Statement
181 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Statement>
182
183 · AnnoCPAN: Annotated CPAN documentation
184
185 http://annocpan.org/dist/SQL-Statement
186 <http://annocpan.org/dist/SQL-Statement>
187
188 · CPAN Ratings
189
190 http://cpanratings.perl.org/s/SQL-Statement
191 <http://cpanratings.perl.org/s/SQL-Statement>
192
193 · CPAN Search
194
195 http://search.cpan.org/dist/SQL-Statement/
196 <http://search.cpan.org/dist/SQL-Statement/>
197
198 Where can I go for help?
199 For questions about installation or usage, please ask on the
200 dbi-users@perl.org mailing list (see http://dbi.perl.org) or post a
201 question on PerlMonks (<http://www.perlmonks.org/>, where Jeff is known
202 as jZed). Jens does not visit PerlMonks on a regular basis.
203
204 If you have a bug report, a patch or a suggestion, please open a new
205 report ticket at CPAN (but please check previous reports first in case
206 your issue has already been addressed). You can mail any of the module
207 maintainers, but you are more assured of an answer by posting to the
208 dbi-users list or reporting the issue in RT.
209
210 Report tickets should contain a detailed description of the bug or
211 enhancement request and at least an easily verifiable way of
212 reproducing the issue or fix. Patches are always welcome, too.
213
214 Where can I go for help with a concrete version?
215 Bugs and feature requests are accepted against the latest version only.
216 To get patches for earlier versions, you need to get an agreement with
217 a developer of your choice - who may or not report the issue and a
218 suggested fix upstream (depends on the license you have chosen).
219
220 Business support and maintenance
221 For business support you can contact Jens via his CPAN email address
222 rehsackATcpan.org. Please keep in mind that business support is neither
223 available for free nor are you eligible to receive any support based on
224 the license distributed with this package.
225
227 Jochen Wiedmann created the original module as an XS (C) extension in
228 1998. Jeff Zucker took over the maintenance in 2001 and rewrote all of
229 the C portions in Perl and began extending the SQL support. More
230 recently Ilya Sterin provided help with SQL::Parser, Tim Bunce provided
231 both general and specific support, Dan Wright and Dean Arnold have
232 contributed extensively to the code, and dozens of people from around
233 the world have submitted patches, bug reports, and suggestions.
234
235 In 2008 Jens Rehsack took over the maintenance of the extended module
236 from Jeff. Together with H.Merijn Brand (who has taken DBD::CSV),
237 Detlef Wartke and Volker Schubbert (especially between 1.16 developer
238 versions until 1.22) and all submitters of bug reports via RT a lot of
239 issues have been fixed.
240
241 Thanks to all!
242
243 If you're interested in helping develop SQL::Statement or want to use
244 it with your own modules, feel free to contact Jeff or Jens.
245
247 · Currently we treat NULL and '' as the same in AnyData/CSV mode -
248 eventually fix.
249
250 · No nested C-style comments allowed as SQL99 says.
251
252 · There are some issues regarding combining outer joins with where
253 clauses.
254
255 · Aggregate functions cannot be used in where clause.
256
257 · Some SQL commands/features are not supported (most of them cannot
258 by design), as "LOCK TABLE", using indices, sub-selects etc.
259
260 Currently the statement for missing features is: I plan to create a
261 SQL::Statement v2.00 based on a pure Backus-Naur-Form parser and a
262 fully object oriented command pattern based engine implementation.
263 When the time is available, I will do it. Until then bugs will be
264 fixed or other Perl modules under my maintainership will receive my
265 time. Features which can be added without deep design changes might
266 be applied earlier - especially when their addition allows studying
267 effective ways to implement the feature in upcoming 2.00.
268
269 · Some people report that SQL::Statement is slower since the XS parts
270 were implemented in pure Perl. This might be true, but on the other
271 hand a large number of features have been added including support
272 for ANSI SQL 99.
273
274 For SQL::Statement 1.xx it's not planned to add new XS parts.
275
276 · Wildcards are expanded to lower cased identifiers. This might
277 confuse some people, but it was easier to implement.
278
279 The warning in DBI to never trust the case of returned column names
280 should be read more often. If you need to rely on identifiers,
281 always use "sth->{NAME_lc}" or "sth->{NAME_uc}" - never rely on
282 "sth->{NAME}":
283
284 $dbh->{FetchHashKeyName} = 'NAME_lc';
285 $sth = $dbh->prepare("SELECT FOO, BAR, ID, NAME, BAZ FROM TABLE");
286 $sth->execute;
287 $hash_ref = $sth->fetchall_hashref('id');
288 print "Name for id 42 is $hash_ref->{42}->{name}\n";
289
290 See "FetchHashKeyName" in DBI for more information.
291
292 Patches to fix bugs/limitations (or a grant to do it) would be very
293 welcome. Please note, that any patches must successfully pass all the
294 "SQL::Statement", DBD::File and DBD::CSV tests and must be a general
295 improvement.
296
298 Jochen Wiedmann created the original module as an XS (C) extension in
299 1998. Jeff Zucker took over the maintenance in 2001 and rewrote all of
300 the C portions in perl and began extending the SQL support. Since 2008,
301 Jens Rehsack is the maintainer.
302
303 Copyright (c) 2001,2005 by Jeff Zucker: jzuckerATcpan.org Copyright (c)
304 2007-2010 by Jens Rehsack: rehsackATcpan.org
305
306 Portions Copyright (C) 1998 by Jochen Wiedmann: jwiedATcpan.org
307
308 All rights reserved.
309
310 You may distribute this module under the terms of either the GNU
311 General Public License or the Artistic License, as specified in the
312 Perl README file.
313
314
315
316perl v5.12.1 2010-08-11 SQL::Statement(3)