1DBI::SQL::Nano(3) User Contributed Perl Documentation DBI::SQL::Nano(3)
2
3
4
6 DBI::SQL::Nano - a very tiny SQL engine
7
9 BEGIN { $ENV{DBI_SQL_NANO}=1 } # forces use of Nano rather than SQL::Statement
10 use DBI::SQL::Nano;
11 use Data::Dumper;
12 my $stmt = DBI::SQL::Nano::Statement->new(
13 "SELECT bar,baz FROM foo WHERE qux = 1"
14 ) or die "Couldn't parse";
15 print Dumper $stmt;
16
18 DBI::SQL::Nano is meant as a *very* minimal SQL engine for use in
19 situations where SQL::Statement is not available. In most situations
20 you are better off installing SQL::Statement although DBI::SQL::Nano
21 may be faster for some very simple tasks.
22
23 DBI::SQL::Nano, like SQL::Statement is primarily intended to provide a
24 SQL engine for use with some pure perl DBDs including DBD::DBM,
25 DBD::CSV, DBD::AnyData, and DBD::Excel. It isn't of much use in and of
26 itself. You can dump out the structure of a parsed SQL statement, but
27 that's about it.
28
30 Setting the DBI_SQL_NANO flag
31 By default, when a DBD uses DBI::SQL::Nano, the module will look to see
32 if SQL::Statement is installed. If it is, SQL::Statement objects are
33 used. If SQL::Statement is not available, DBI::SQL::Nano objects are
34 used.
35
36 In some cases, you may wish to use DBI::SQL::Nano objects even if
37 SQL::Statement is available. To force usage of DBI::SQL::Nano objects
38 regardless of the availability of SQL::Statement, set the environment
39 variable DBI_SQL_NANO to 1.
40
41 You can set the environment variable in your shell prior to running
42 your script (with SET or EXPORT or whatever), or else you can set it in
43 your script by putting this at the top of the script:
44
45 BEGIN { $ENV{DBI_SQL_NANO} = 1 }
46
47 Supported SQL syntax
48 Here's a pseudo-BNF. Square brackets [] indicate optional items;
49 Angle brackets <> indicate items defined elsewhere in the BNF.
50
51 statement ::=
52 DROP TABLE [IF EXISTS] <table_name>
53 | CREATE TABLE <table_name> <col_def_list>
54 | INSERT INTO <table_name> [<insert_col_list>] VALUES <val_list>
55 | DELETE FROM <table_name> [<where_clause>]
56 | UPDATE <table_name> SET <set_clause> <where_clause>
57 | SELECT <select_col_list> FROM <table_name> [<where_clause>]
58 [<order_clause>]
59
60 the optional IF EXISTS clause ::=
61 * similar to MySQL - prevents errors when trying to drop
62 a table that doesn't exist
63
64 identifiers ::=
65 * table and column names should be valid SQL identifiers
66 * especially avoid using spaces and commas in identifiers
67 * note: there is no error checking for invalid names, some
68 will be accepted, others will cause parse failures
69
70 table_name ::=
71 * only one table (no multiple table operations)
72 * see identifier for valid table names
73
74 col_def_list ::=
75 * a parens delimited, comma-separated list of column names
76 * see identifier for valid column names
77 * column types and column constraints may be included but are ignored
78 e.g. these are all the same:
79 (id,phrase)
80 (id INT, phrase VARCHAR(40))
81 (id INT PRIMARY KEY, phrase VARCHAR(40) NOT NULL)
82 * you are *strongly* advised to put in column types even though
83 they are ignored ... it increases portability
84
85 insert_col_list ::=
86 * a parens delimited, comma-separated list of column names
87 * as in standard SQL, this is optional
88
89 select_col_list ::=
90 * a comma-separated list of column names
91 * or an asterisk denoting all columns
92
93 val_list ::=
94 * a parens delimited, comma-separated list of values which can be:
95 * placeholders (an unquoted question mark)
96 * numbers (unquoted numbers)
97 * column names (unquoted strings)
98 * nulls (unquoted word NULL)
99 * strings (delimited with single quote marks);
100 * note: leading and trailing percent mark (%) and underscore (_)
101 can be used as wildcards in quoted strings for use with
102 the LIKE and CLIKE operators
103 * note: escaped single quote marks within strings are not
104 supported, neither are embedded commas, use placeholders instead
105
106 set_clause ::=
107 * a comma-separated list of column = value pairs
108 * see val_list for acceptable value formats
109
110 where_clause ::=
111 * a single "column/value <op> column/value" predicate, optionally
112 preceded by "NOT"
113 * note: multiple predicates combined with ORs or ANDs are not supported
114 * see val_list for acceptable value formats
115 * op may be one of:
116 < > >= <= = <> LIKE CLIKE IS
117 * CLIKE is a case insensitive LIKE
118
119 order_clause ::= column_name [ASC|DESC]
120 * a single column optional ORDER BY clause is supported
121 * as in standard SQL, if neither ASC (ascending) nor
122 DESC (descending) is specified, ASC becomes the default
123
125 Tim Bunce provided the original idea for this module, helped me out of
126 the tangled trap of namespace, and provided help and advice all along
127 the way. Although I wrote it from the ground up, it is based on Jochen
128 Weidmann's orignal design of SQL::Statement, so much of the credit for
129 the API goes to him.
130
132 This module is written and maintained by
133
134 Jeff Zucker < jzucker AT cpan.org >
135
136 Copyright (C) 2004 by Jeff Zucker, all rights reserved.
137
138 You may freely distribute and/or modify this module under the terms of
139 either the GNU General Public License (GPL) or the Artistic License, as
140 specified in the Perl README file.
141
142
143
144perl v5.10.1 2007-07-16 DBI::SQL::Nano(3)