1// -*- C++ -*- //
2
3/* set.h
4 *
5 * Copyright 2006 libgdamm Development Team
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or(at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <libgdamm/batch.h>
23#include <libgdamm/statement.h>
24
25_DEFS(libgdamm,libgda)
26_PINCLUDE(glibmm/private/object_p.h)
27
28namespace Gnome
29{
30
31namespace Gda
32{
33
34_WRAP_ENUM(SqlParserMode, GdaSqlParserMode)
35_WRAP_GERROR(SqlParserError, GdaSqlParserError, GDA_SQL_PARSER_ERROR)
36
37//TODO: Find out how to escape /* so we can actually show the full syntax at the end of this text.
38/** SQL parser.
39 *
40 * The Gda::SqlParser is an object dedicated to creating Gda::Statement and
41 * Gda::Batch objects from SQL strings. The actual contents of the parsed
42 * statements is represented as Gda::SqlStatement structures (which can be
43 * obtained from any Gda::Statement through the "structure" property).
44 *
45 * Gda::SqlParser parsers can be created by calling Gda::ServerProvider::create_parser()
46 * for a provider adapted SQL parser, or using create() for a general purpose SQL parser.
47 *
48 * The Gda::SqlParser can either work in "parse" mode where it will try to parse
49 * the SQL string, or in "delimiter" mode where it will only attempt at delimiting
50 * SQL statements in a string which may contain several SQL statements (usually
51 * separated by a semi column). If operating in "parser" mode, and the parser
52 * can't correctly parse the string, then it will switch to the "delimiter" mode
53 * for the next statement in the string to parse (and create a STATEMENT_UNKNOWN statement).
54 *
55 * The Gda::SqlParser object parses and analyses SQL statements and reports the
56 * following statement types:
57 *
58 * - SELECT (and COMPOUND select), INSERT, UPDATE and DELETE SQL statements should be completely parsed.
59 *
60 * - Transaction related statements (corresponding to the BEGIN, COMMIT,
61 *   ROLLBACK, SAVEPOINT, ROLLBACK SAVEPOINT and DELETE SAVEPOINT) are parsed and a
62 *   minimalist structure is created to extract some information (that structure is not enough per-se to re-create the complete SQL statement).
63 *
64 * Any other type of SQL statement (CREATE TABLE, ...) creates a GdaStatement of
65 * type STATEMENT_UNKNOWN, and it only able to locate place holders (variables)
66 * and end of statement marks.
67 *
68 * NOTE: Any SQL of a type which should be parsed which but which creates a Gda::Statement
69 * of type GDA_SQL_STATEMENT_UNKNOWN (check with Gda::Statement::get_statement_type())
70 * should be reported as a bug.
71 *
72 * The Gda::SqlParser object recognizes place holders (variables), which can later
73 * be queried and valued using Gda::Statement::get_parameters().
74 * See the syntax description for the underlying <a href="http://library.gnome.org/devel/libgda/stable/GdaSqlParser.html#GdaSqlParser.description">GdaSqlParser</a>.
75 *
76 * @ingroup Connection
77 */
78class SqlParser : public Glib::Object
79{
80  _CLASS_GOBJECT(SqlParser, GdaSqlParser, GDA_SQL_PARSER, Glib::Object, GObject)
81protected:
82  _CTOR_DEFAULT()
83public:
84  _WRAP_CREATE()
85
86  //TODO: Should these be const?
87  _WRAP_METHOD_DOCS_ONLY(gda_sql_parser_parse_string)
88  Glib::RefPtr<Statement> parse_string(const Glib::ustring& sql, Glib::ustring& remain);
89
90  Glib::RefPtr<Statement> parse_string(const Glib::ustring& sql);
91
92  _WRAP_METHOD_DOCS_ONLY(gda_sql_parser_parse_string_as_batch)
93  Glib::RefPtr<Batch> parse_string_as_batch(const Glib::ustring& sql, Glib::ustring& remain);
94
95  Glib::RefPtr<Batch> parse_string_as_batch(const Glib::ustring& sql);
96
97  _WRAP_METHOD(Glib::RefPtr<Batch> parse_file_as_batch(const std::string& filename), gda_sql_parser_parse_file_as_batch, errthrow)
98
99  _IGNORE(gda_sql_parser_set_overflow_error, gda_sql_parser_set_syntax_error)
100
101  _WRAP_PROPERTY("column-error", int)
102  _WRAP_PROPERTY("line-error", int)
103  _WRAP_PROPERTY("mode", int)
104  _WRAP_PROPERTY("tokenizer-flavour", int)
105
106};
107
108} // namespace Gda
109} // namespace Gnome
110
111