1 // -*- c++ -*-
2 // Generated by gmmproc 2.46.1 -- DO NOT MODIFY!
3 #ifndef _LIBGDAMM_SQLPARSER_H
4 #define _LIBGDAMM_SQLPARSER_H
5 
6 
7 #include <glibmm/ustring.h>
8 #include <sigc++/sigc++.h>
9 
10 // -*- C++ -*- //
11 
12 /* set.h
13  *
14  * Copyright 2006 libgdamm Development Team
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or(at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free
28  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29  */
30 
31 #include <libgdamm/batch.h>
32 #include <libgdamm/statement.h>
33 
34 
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 typedef struct _GdaSqlParser GdaSqlParser;
37 typedef struct _GdaSqlParserClass GdaSqlParserClass;
38 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
39 
40 
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 namespace Gnome
43 {
44 
45 namespace Gda
46 { class SqlParser_Class; } // namespace Gda
47 
48 } // namespace Gnome
49 #endif //DOXYGEN_SHOULD_SKIP_THIS
50 
51 namespace Gnome
52 {
53 
54 namespace Gda
55 {
56 
57 /** @addtogroup libgdammEnums libgdamm Enums and Flags */
58 
59 /**
60  *
61  * @ingroup libgdammEnums
62  */
63 enum SqlParserMode
64 {
65   SQL_PARSER_MODE_PARSE,
66   SQL_PARSER_MODE_DELIMIT
67 };
68 
69 } // namespace Gda
70 
71 } // namespace Gnome
72 
73 
74 #ifndef DOXYGEN_SHOULD_SKIP_THIS
75 namespace Glib
76 {
77 
78 template <>
79 class Value<Gnome::Gda::SqlParserMode> : public Glib::Value_Enum<Gnome::Gda::SqlParserMode>
80 {
81 public:
82   static GType value_type() G_GNUC_CONST;
83 };
84 
85 } // namespace Glib
86 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
87 
88 
89 namespace Gnome
90 {
91 
92 namespace Gda
93 {
94 
95 class SqlParserError : public Glib::Error
96 {
97 public:
98   /**
99    */
100   enum Code
101   {
102     SQL_PARSER_SYNTAX_ERROR,
103     SQL_PARSER_OVERFLOW_ERROR,
104     SQL_PARSER_EMPTY_SQL_ERROR
105   };
106 
107   SqlParserError(Code error_code, const Glib::ustring& error_message);
108   explicit SqlParserError(GError* gobject);
109   Code code() const;
110 
111 #ifndef DOXYGEN_SHOULD_SKIP_THIS
112 private:
113 
114   static void throw_func(GError* gobject);
115 
116   friend void wrap_init(); // uses throw_func()
117 
118   #endif //DOXYGEN_SHOULD_SKIP_THIS
119 };
120 
121 } // namespace Gda
122 
123 } // namespace Gnome
124 
125 #ifndef DOXYGEN_SHOULD_SKIP_THIS
126 namespace Glib
127 {
128 
129 template <>
130 class Value<Gnome::Gda::SqlParserError::Code> : public Glib::Value_Enum<Gnome::Gda::SqlParserError::Code>
131 {
132 public:
133   static GType value_type() G_GNUC_CONST;
134 };
135 
136 } // namespace Glib
137 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
138 
139 
140 namespace Gnome
141 {
142 
143 namespace Gda
144 {
145 
146 
147 //TODO: Find out how to escape /* so we can actually show the full syntax at the end of this text.
148 /** SQL parser.
149  *
150  * The Gda::SqlParser is an object dedicated to creating Gda::Statement and
151  * Gda::Batch objects from SQL strings. The actual contents of the parsed
152  * statements is represented as Gda::SqlStatement structures (which can be
153  * obtained from any Gda::Statement through the "structure" property).
154  *
155  * Gda::SqlParser parsers can be created by calling Gda::ServerProvider::create_parser()
156  * for a provider adapted SQL parser, or using create() for a general purpose SQL parser.
157  *
158  * The Gda::SqlParser can either work in "parse" mode where it will try to parse
159  * the SQL string, or in "delimiter" mode where it will only attempt at delimiting
160  * SQL statements in a string which may contain several SQL statements (usually
161  * separated by a semi column). If operating in "parser" mode, and the parser
162  * can't correctly parse the string, then it will switch to the "delimiter" mode
163  * for the next statement in the string to parse (and create a STATEMENT_UNKNOWN statement).
164  *
165  * The Gda::SqlParser object parses and analyses SQL statements and reports the
166  * following statement types:
167  *
168  * - SELECT (and COMPOUND select), INSERT, UPDATE and DELETE SQL statements should be completely parsed.
169  *
170  * - Transaction related statements (corresponding to the BEGIN, COMMIT,
171  *   ROLLBACK, SAVEPOINT, ROLLBACK SAVEPOINT and DELETE SAVEPOINT) are parsed and a
172  *   minimalist structure is created to extract some information (that structure is not enough per-se to re-create the complete SQL statement).
173  *
174  * Any other type of SQL statement (CREATE TABLE, ...) creates a GdaStatement of
175  * type STATEMENT_UNKNOWN, and it only able to locate place holders (variables)
176  * and end of statement marks.
177  *
178  * NOTE: Any SQL of a type which should be parsed which but which creates a Gda::Statement
179  * of type GDA_SQL_STATEMENT_UNKNOWN (check with Gda::Statement::get_statement_type())
180  * should be reported as a bug.
181  *
182  * The Gda::SqlParser object recognizes place holders (variables), which can later
183  * be queried and valued using Gda::Statement::get_parameters().
184  * See the syntax description for the underlying <a href="http://library.gnome.org/devel/libgda/stable/GdaSqlParser.html#GdaSqlParser.description">GdaSqlParser</a>.
185  *
186  * @ingroup Connection
187  */
188 
189 class SqlParser : public Glib::Object
190 {
191 
192 #ifndef DOXYGEN_SHOULD_SKIP_THIS
193 
194 public:
195   typedef SqlParser CppObjectType;
196   typedef SqlParser_Class CppClassType;
197   typedef GdaSqlParser BaseObjectType;
198   typedef GdaSqlParserClass BaseClassType;
199 
200   // noncopyable
201   SqlParser(const SqlParser&) = delete;
202   SqlParser& operator=(const SqlParser&) = delete;
203 
204 private:  friend class SqlParser_Class;
205   static CppClassType sqlparser_class_;
206 
207 protected:
208   explicit SqlParser(const Glib::ConstructParams& construct_params);
209   explicit SqlParser(GdaSqlParser* castitem);
210 
211 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
212 
213 public:
214 
215   SqlParser(SqlParser&& src) noexcept;
216   SqlParser& operator=(SqlParser&& src) noexcept;
217 
218   virtual ~SqlParser() noexcept;
219 
220   /** Get the GType for this class, for use with the underlying GObject type system.
221    */
222   static GType get_type()      G_GNUC_CONST;
223 
224 #ifndef DOXYGEN_SHOULD_SKIP_THIS
225 
226 
227   static GType get_base_type() G_GNUC_CONST;
228 #endif
229 
230   ///Provides access to the underlying C GObject.
231   GdaSqlParser*       gobj()       { return reinterpret_cast<GdaSqlParser*>(gobject_); }
232 
233   ///Provides access to the underlying C GObject.
234   const GdaSqlParser* gobj() const { return reinterpret_cast<GdaSqlParser*>(gobject_); }
235 
236   ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
237   GdaSqlParser* gobj_copy();
238 
239 private:
240 
241 protected:
242   SqlParser();
243 public:
244 
245   static Glib::RefPtr<SqlParser> create();
246 
247 
248   //TODO: Should these be const?
249 
250   /** Parses @a sql and creates a Gda::Statement statement from the first SQL statement contained in @a sql: if @a sql
251    * contains more than one statement, then the remaining part of the string is not parsed at all, and @a remain (if
252    * not <tt>0</tt>) will point at the first non parsed character.
253    *
254    * To include variables in the @a sql string, see the
255    * GdaSqlParser's object description.
256    *
257    * @param sql The SQL string to parse.
258    * @param remain Location to store a pointer to remaining part of @a sql in case @a sql has multiple statement, or <tt>0</tt>.
259    * @return A new Gda::Statement object, or <tt>0</tt> if an error occurred.
260    */
261 
262   Glib::RefPtr<Statement> parse_string(const Glib::ustring& sql, Glib::ustring& remain);
263 
264   Glib::RefPtr<Statement> parse_string(const Glib::ustring& sql);
265 
266 
267   /** Parse @a sql and creates a Gda::Batch object which contains all the Gda::Statement objects created while parsing (one object
268    * per SQL statement). Empty statements (composed of spaces only) do not appear in the resulting object.
269    *
270    *  @a sql is parsed and Gda::Statement objects are created as long as no error is found in @a sql. If an error is found
271    * at some point, then the parsing stops and @a remain may contain a non <tt>0</tt> pointer, @a error may be set, and <tt>0</tt>
272    * is returned.
273    *
274    * if @a sql is <tt>0</tt>, then the returned Gda::Batch object will contain no statement.
275    *
276    * To include variables in the @a sql string, see the
277    * GdaSqlParser's object description.
278    *
279    * @param sql The SQL string to parse.
280    * @param remain Location to store a pointer to remaining part of @a sql in case an error occurred while parsing @a sql, or <tt>0</tt>.
281    * @return A new Gda::Batch object, or <tt>0</tt> if an error occurred.
282    */
283 
284   Glib::RefPtr<Batch> parse_string_as_batch(const Glib::ustring& sql, Glib::ustring& remain);
285 
286   Glib::RefPtr<Batch> parse_string_as_batch(const Glib::ustring& sql);
287 
288 
289   /** Parse @a filename's contents and creates a Gda::Batch object which contains all the
290    * Gda::Statement objects created while parsing (one object per SQL statement).
291    *
292    *  @a filename's contents are parsed and Gda::Statement objects are created as long as no error is found. If an error is found
293    * at some point, then the parsing stops, @a error may be set and <tt>0</tt> is returned
294    *
295    * if @a sql is <tt>0</tt>, then the returned Gda::Batch object will contain no statement.
296    *
297    * @param filename Name of the file to parse.
298    * @return A new Gda::Batch object, or <tt>0</tt> if an error occurred.
299    */
300   Glib::RefPtr<Batch> parse_file_as_batch(const std::string& filename);
301 
302 
303   /**
304    *
305    * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
306    * or receive notification when the value of the property changes.
307    */
308   Glib::PropertyProxy_ReadOnly< int > property_column_error() const;
309 
310 
311   /**
312    *
313    * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
314    * or receive notification when the value of the property changes.
315    */
316   Glib::PropertyProxy_ReadOnly< int > property_line_error() const;
317 
318 
319   /**
320    *
321    * @return A PropertyProxy that allows you to get or set the value of the property,
322    * or receive notification when the value of the property changes.
323    */
324   Glib::PropertyProxy< int > property_mode() ;
325 
326 /**
327    *
328    * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
329    * or receive notification when the value of the property changes.
330    */
331   Glib::PropertyProxy_ReadOnly< int > property_mode() const;
332 
333   /**
334    *
335    * @return A PropertyProxy that allows you to get or set the value of the property,
336    * or receive notification when the value of the property changes.
337    */
338   Glib::PropertyProxy< int > property_tokenizer_flavour() ;
339 
340 /**
341    *
342    * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
343    * or receive notification when the value of the property changes.
344    */
345   Glib::PropertyProxy_ReadOnly< int > property_tokenizer_flavour() const;
346 
347 
348 public:
349 
350 public:
351   //C++ methods used to invoke GTK+ virtual functions:
352 
353 protected:
354   //GTK+ Virtual Functions (override these to change behaviour):
355 
356   //Default Signal Handlers::
357 
358 
359 };
360 
361 } // namespace Gda
362 } // namespace Gnome
363 
364 
365 namespace Glib
366 {
367   /** A Glib::wrap() method for this object.
368    *
369    * @param object The C instance.
370    * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
371    * @result A C++ instance that wraps this C instance.
372    *
373    * @relates Gnome::Gda::SqlParser
374    */
375   Glib::RefPtr<Gnome::Gda::SqlParser> wrap(GdaSqlParser* object, bool take_copy = false);
376 }
377 
378 
379 #endif /* _LIBGDAMM_SQLPARSER_H */
380 
381