1 // -*- c++ -*-
2 // Generated by gmmproc 2.46.1 -- DO NOT MODIFY!
3 #ifndef _LIBGDAMM_STATEMENT_H
4 #define _LIBGDAMM_STATEMENT_H
5 
6 
7 #include <glibmm/ustring.h>
8 #include <sigc++/sigc++.h>
9 
10 // -*- C++ -*- //
11 
12 /* statement.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/set.h>
32 #include <libgdamm/holder.h>
33 #include <libgdamm/sqlstatement.h>
34 
35 
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 typedef struct _GdaStatement GdaStatement;
38 typedef struct _GdaStatementClass GdaStatementClass;
39 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
40 
41 
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 namespace Gnome
44 {
45 
46 namespace Gda
47 { class Statement_Class; } // namespace Gda
48 
49 } // namespace Gnome
50 #endif //DOXYGEN_SHOULD_SKIP_THIS
51 
52 namespace Gnome
53 {
54 
55 namespace Gda
56 {
57 
58 class Connection;
59 
60 /** @addtogroup libgdammEnums libgdamm Enums and Flags */
61 
62 /**
63  *
64  * @ingroup libgdammEnums
65  * @par Bitwise operators:
66  * <tt>%StatementModelUsage operator|(StatementModelUsage, StatementModelUsage)</tt><br>
67  * <tt>%StatementModelUsage operator&(StatementModelUsage, StatementModelUsage)</tt><br>
68  * <tt>%StatementModelUsage operator^(StatementModelUsage, StatementModelUsage)</tt><br>
69  * <tt>%StatementModelUsage operator~(StatementModelUsage)</tt><br>
70  * <tt>%StatementModelUsage& operator|=(StatementModelUsage&, StatementModelUsage)</tt><br>
71  * <tt>%StatementModelUsage& operator&=(StatementModelUsage&, StatementModelUsage)</tt><br>
72  * <tt>%StatementModelUsage& operator^=(StatementModelUsage&, StatementModelUsage)</tt><br>
73  */
74 enum StatementModelUsage
75 {
76   STATEMENT_MODEL_RANDOM_ACCESS = 1 << 0,
77   STATEMENT_MODEL_CURSOR_FORWARD = 1 << 1,
78   STATEMENT_MODEL_CURSOR_BACKWARD = 1 << 2,
79   STATEMENT_MODEL_CURSOR = 0x6,
80   STATEMENT_MODEL_ALLOW_NOPARAM = 1 << 3
81 };
82 
83 /** @ingroup libgdammEnums */
84 inline StatementModelUsage operator|(StatementModelUsage lhs, StatementModelUsage rhs)
85   { return static_cast<StatementModelUsage>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
86 
87 /** @ingroup libgdammEnums */
88 inline StatementModelUsage operator&(StatementModelUsage lhs, StatementModelUsage rhs)
89   { return static_cast<StatementModelUsage>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
90 
91 /** @ingroup libgdammEnums */
92 inline StatementModelUsage operator^(StatementModelUsage lhs, StatementModelUsage rhs)
93   { return static_cast<StatementModelUsage>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
94 
95 /** @ingroup libgdammEnums */
96 inline StatementModelUsage operator~(StatementModelUsage flags)
97   { return static_cast<StatementModelUsage>(~static_cast<unsigned>(flags)); }
98 
99 /** @ingroup libgdammEnums */
100 inline StatementModelUsage& operator|=(StatementModelUsage& lhs, StatementModelUsage rhs)
101   { return (lhs = static_cast<StatementModelUsage>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
102 
103 /** @ingroup libgdammEnums */
104 inline StatementModelUsage& operator&=(StatementModelUsage& lhs, StatementModelUsage rhs)
105   { return (lhs = static_cast<StatementModelUsage>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
106 
107 /** @ingroup libgdammEnums */
108 inline StatementModelUsage& operator^=(StatementModelUsage& lhs, StatementModelUsage rhs)
109   { return (lhs = static_cast<StatementModelUsage>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
110 
111 } // namespace Gda
112 
113 } // namespace Gnome
114 
115 
116 #ifndef DOXYGEN_SHOULD_SKIP_THIS
117 namespace Glib
118 {
119 
120 template <>
121 class Value<Gnome::Gda::StatementModelUsage> : public Glib::Value_Flags<Gnome::Gda::StatementModelUsage>
122 {
123 public:
124   static GType value_type() G_GNUC_CONST;
125 };
126 
127 } // namespace Glib
128 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
129 
130 
131 namespace Gnome
132 {
133 
134 namespace Gda
135 {
136 
137 /**
138  *
139  * @ingroup libgdammEnums
140  * @par Bitwise operators:
141  * <tt>%StatementSqlFlag operator|(StatementSqlFlag, StatementSqlFlag)</tt><br>
142  * <tt>%StatementSqlFlag operator&(StatementSqlFlag, StatementSqlFlag)</tt><br>
143  * <tt>%StatementSqlFlag operator^(StatementSqlFlag, StatementSqlFlag)</tt><br>
144  * <tt>%StatementSqlFlag operator~(StatementSqlFlag)</tt><br>
145  * <tt>%StatementSqlFlag& operator|=(StatementSqlFlag&, StatementSqlFlag)</tt><br>
146  * <tt>%StatementSqlFlag& operator&=(StatementSqlFlag&, StatementSqlFlag)</tt><br>
147  * <tt>%StatementSqlFlag& operator^=(StatementSqlFlag&, StatementSqlFlag)</tt><br>
148  */
149 enum StatementSqlFlag
150 {
151   STATEMENT_SQL_PARAMS_AS_VALUES = 0x0,
152   STATEMENT_SQL_PRETTY = 1 << 0,
153   STATEMENT_SQL_PARAMS_LONG = 1 << 1,
154   STATEMENT_SQL_PARAMS_SHORT = 1 << 2,
155   STATEMENT_SQL_PARAMS_AS_COLON = 1 << 3,
156   STATEMENT_SQL_PARAMS_AS_DOLLAR = 1 << 4,
157   STATEMENT_SQL_PARAMS_AS_QMARK = 1 << 5,
158   STATEMENT_SQL_PARAMS_AS_UQMARK = 1 << 6
159 };
160 
161 /** @ingroup libgdammEnums */
162 inline StatementSqlFlag operator|(StatementSqlFlag lhs, StatementSqlFlag rhs)
163   { return static_cast<StatementSqlFlag>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
164 
165 /** @ingroup libgdammEnums */
166 inline StatementSqlFlag operator&(StatementSqlFlag lhs, StatementSqlFlag rhs)
167   { return static_cast<StatementSqlFlag>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
168 
169 /** @ingroup libgdammEnums */
170 inline StatementSqlFlag operator^(StatementSqlFlag lhs, StatementSqlFlag rhs)
171   { return static_cast<StatementSqlFlag>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
172 
173 /** @ingroup libgdammEnums */
174 inline StatementSqlFlag operator~(StatementSqlFlag flags)
175   { return static_cast<StatementSqlFlag>(~static_cast<unsigned>(flags)); }
176 
177 /** @ingroup libgdammEnums */
178 inline StatementSqlFlag& operator|=(StatementSqlFlag& lhs, StatementSqlFlag rhs)
179   { return (lhs = static_cast<StatementSqlFlag>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
180 
181 /** @ingroup libgdammEnums */
182 inline StatementSqlFlag& operator&=(StatementSqlFlag& lhs, StatementSqlFlag rhs)
183   { return (lhs = static_cast<StatementSqlFlag>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
184 
185 /** @ingroup libgdammEnums */
186 inline StatementSqlFlag& operator^=(StatementSqlFlag& lhs, StatementSqlFlag rhs)
187   { return (lhs = static_cast<StatementSqlFlag>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
188 
189 } // namespace Gda
190 
191 } // namespace Gnome
192 
193 
194 #ifndef DOXYGEN_SHOULD_SKIP_THIS
195 namespace Glib
196 {
197 
198 template <>
199 class Value<Gnome::Gda::StatementSqlFlag> : public Glib::Value_Flags<Gnome::Gda::StatementSqlFlag>
200 {
201 public:
202   static GType value_type() G_GNUC_CONST;
203 };
204 
205 } // namespace Glib
206 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
207 
208 
209 namespace Gnome
210 {
211 
212 namespace Gda
213 {
214 
215 
216 class StatementError : public Glib::Error
217 {
218 public:
219   /**
220    */
221   enum Code
222   {
223     STATEMENT_PARSE_ERROR,
224     STATEMENT_SYNTAX_ERROR,
225     STATEMENT_NO_CNC_ERROR,
226     STATEMENT_CNC_CLOSED_ERROR,
227     STATEMENT_EXEC_ERROR,
228     STATEMENT_PARAM_TYPE_ERROR,
229     STATEMENT_PARAM_ERROR
230   };
231 
232   StatementError(Code error_code, const Glib::ustring& error_message);
233   explicit StatementError(GError* gobject);
234   Code code() const;
235 
236 #ifndef DOXYGEN_SHOULD_SKIP_THIS
237 private:
238 
239   static void throw_func(GError* gobject);
240 
241   friend void wrap_init(); // uses throw_func()
242 
243   #endif //DOXYGEN_SHOULD_SKIP_THIS
244 };
245 
246 } // namespace Gda
247 
248 } // namespace Gnome
249 
250 #ifndef DOXYGEN_SHOULD_SKIP_THIS
251 namespace Glib
252 {
253 
254 template <>
255 class Value<Gnome::Gda::StatementError::Code> : public Glib::Value_Enum<Gnome::Gda::StatementError::Code>
256 {
257 public:
258   static GType value_type() G_GNUC_CONST;
259 };
260 
261 } // namespace Glib
262 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
263 
264 
265 namespace Gnome
266 {
267 
268 namespace Gda
269 {
270 
271 
272 /** Single SQL statement.
273  *
274  * The Gda::Statement represents a single SQL statement (multiple statements
275  * can be grouped in a Batch object).
276  *
277  * A Gda::Statement can either be built "manually" by building a Gda::SqlStatement
278  * structure, or from an SQL statement using a Gda::SqlParser object.
279  * A GdaConnection can use a GdaStatement to:
280  *
281  *  - prepare it for a future execution, the preparation step involves converting the
282  *     GdaStatement object into a structure used by the database's own API, see
283  *     Gda::Connection::statement_prepare()
284  *  - execute it using Gda::Connection::statement_execute_select() if it is known
285  *     that the statement is a selection statement, Gda::Connection::statement_execute_non_select()
286  *     if it is not a selection statement, or Gda::Connection::statement_execute()
287  *     when the type of expected result is unknown.
288  * Note that it is possible to use the same Gda::Statement object at the same time
289  * with several Gda::Connection objects.
290  *
291  * @ingroup Connection
292  */
293 
294 class Statement : public Glib::Object
295 {
296 
297 #ifndef DOXYGEN_SHOULD_SKIP_THIS
298 
299 public:
300   typedef Statement CppObjectType;
301   typedef Statement_Class CppClassType;
302   typedef GdaStatement BaseObjectType;
303   typedef GdaStatementClass BaseClassType;
304 
305   // noncopyable
306   Statement(const Statement&) = delete;
307   Statement& operator=(const Statement&) = delete;
308 
309 private:  friend class Statement_Class;
310   static CppClassType statement_class_;
311 
312 protected:
313   explicit Statement(const Glib::ConstructParams& construct_params);
314   explicit Statement(GdaStatement* castitem);
315 
316 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
317 
318 public:
319 
320   Statement(Statement&& src) noexcept;
321   Statement& operator=(Statement&& src) noexcept;
322 
323   virtual ~Statement() noexcept;
324 
325   /** Get the GType for this class, for use with the underlying GObject type system.
326    */
327   static GType get_type()      G_GNUC_CONST;
328 
329 #ifndef DOXYGEN_SHOULD_SKIP_THIS
330 
331 
332   static GType get_base_type() G_GNUC_CONST;
333 #endif
334 
335   ///Provides access to the underlying C GObject.
gobj()336   GdaStatement*       gobj()       { return reinterpret_cast<GdaStatement*>(gobject_); }
337 
338   ///Provides access to the underlying C GObject.
gobj()339   const GdaStatement* gobj() const { return reinterpret_cast<GdaStatement*>(gobject_); }
340 
341   ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
342   GdaStatement* gobj_copy();
343 
344 private:
345 
346 protected:
347   Statement();
348 
349 public:
350 
351   static Glib::RefPtr<Statement> create();
352 
353 
354   /** Copy constructor
355    *
356    * @return A the new copy of @a orig.
357    */
358   Glib::RefPtr<Statement> copy() const;
359 
360 
361   /** Creates a string representing the contents of @a stmt.
362    *
363    * @return A string containing the serialized version of @a stmt.
364    */
365   Glib::ustring serialize() const;
366 
367   //TODO: Should this be const? Probably not, because the caller could change Set. murrayc.
368 
369   /** Get a new Gda::Set object which groups all the execution parameters
370    * which @a stmt needs. This new object is returned though @a out_params.
371    *
372    * Note that if @a stmt does not need any parameter, then @a out_params is set to <tt>0</tt>.
373    *
374    * @param out_params A place to store a new Gda::Set object, or <tt>0</tt>.
375    * @return <tt>true</tt> if no error occurred.
376    */
377 
378   bool get_parameters(Glib::RefPtr<Set>& out_params);
379 
380 
381   //TODO: Documentation:
382   Glib::ustring to_sql() const;
383 
384   //TODO: Documentation:
385   Glib::ustring to_sql(const Glib::RefPtr<const Set>& params) const;
386   //gtkmmproc error: gda_statement_to_sql : ignored method defs lookup failed
387 
388   typedef std::vector< const Glib::RefPtr<Holder> > HolderVector;
389 
390   //TODO: Add an overload without the params?
391 
392   /** Renders @a stmt as an SQL statement, with some control on how it is rendered.
393    *
394    * If @a cnc is not <tt>0</tt>, then the rendered SQL will better be suited to be used by @a cnc (in particular
395    * it may include some SQL tweaks and/or proprietary extensions specific to the database engine used by @a cnc):
396    * in this case the result is similar to calling Gda::Connection::statement_to_sql().
397    *
398    * @param cnc A Gda::Connection object, or <tt>0</tt>.
399    * @param params Parameters contained in a single Gda::Set object.
400    * @param flags A set of flags to control the rendering.
401    * @param params_used A place to store the list of actual Gda::Holder objects in @a params used to do the rendering, or <tt>0</tt>.
402    * @return A new string if no error occurred.
403    */
404 
405   Glib::ustring to_sql(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<const Set>& params,
406                                 StatementSqlFlag flags, const HolderVector& params_used) const;
407 
408 
409   /** Get the type of statement held by @a stmt. It returns GDA_SQL_STATEMENT_NONE if
410    *  @a stmt does not hold any statement
411    *
412    * @return The statement type.
413    */
414   SqlStatementType get_statement_type() const;
415 
416   /** Tells if @a stmt is composed only of spaces (that is it has no real SQL code), and is completely
417    * useless as such.
418    *
419    * @return <tt>true</tt> if executing @a stmt does nothing.
420    */
421   bool is_useless() const;
422 
423   /** Checks that @a stmt's structure is correct.
424    *
425    * @return <tt>true</tt> if @a stmt's structure is correct.
426    */
427   bool check_structure() const;
428 
429   /** If @a cnc is not <tt>0</tt> then checks that every object (table, field, function) used in @a stmt
430    * actually exists in @a cnc's database
431    *
432    * If @a cnc is <tt>0</tt>, then cleans anything related to @a cnc in @a stmt.
433    *
434    * See gda_sql_statement_check_validity() for more information.
435    *
436    * @param cnc A Gda::Connection object, or <tt>0</tt>.
437    * @return <tt>true</tt> if every object actually exists in @a cnc's database.
438    */
439   bool check_validity(const Glib::RefPtr<Connection>& cnc) const;
440 
441   /** "Normalizes" some parts of @a stmt, see gda_sql_statement_normalize() for more
442    * information.
443    *
444    * @param cnc A Gda::Connection object.
445    * @return <tt>true</tt> if no error occurred.
446    */
447   bool normalize(const Glib::RefPtr<Connection>& cnc);
448 
449   //TODO: Use a real GType in libgda?
450   /**
451    *
452    * @return A PropertyProxy that allows you to get or set the value of the property,
453    * or receive notification when the value of the property changes.
454    */
455   Glib::PropertyProxy< gpointer > property_structure() ;
456 
457 /**
458    *
459    * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
460    * or receive notification when the value of the property changes.
461    */
462   Glib::PropertyProxy_ReadOnly< gpointer > property_structure() const;
463 
464 
465   //The m4 conversion is here because it is only for signals:
466 
467 
468   /**
469    * @par Slot Prototype:
470    * <tt>void on_my_%checked(const Glib::RefPtr<Connection>& cnc, bool valid)</tt>
471    *
472    */
473 
474   Glib::SignalProxy2< void,const Glib::RefPtr<Connection>&,bool > signal_checked();
475 
476 
477   /**
478    * @par Slot Prototype:
479    * <tt>void on_my_%reset()</tt>
480    *
481    */
482 
483   Glib::SignalProxy0< void > signal_reset();
484 
485 
486 public:
487 
488 public:
489   //C++ methods used to invoke GTK+ virtual functions:
490 
491 protected:
492   //GTK+ Virtual Functions (override these to change behaviour):
493 
494   //Default Signal Handlers::
495   /// This is a default handler for the signal signal_checked().
496   virtual void on_checked(const Glib::RefPtr<Connection>& cnc, bool valid);
497   /// This is a default handler for the signal signal_reset().
498   virtual void on_reset();
499 
500 
501 };
502 
503 } // namespace Gda
504 } // namespace Gnome
505 
506 
507 namespace Glib
508 {
509   /** A Glib::wrap() method for this object.
510    *
511    * @param object The C instance.
512    * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
513    * @result A C++ instance that wraps this C instance.
514    *
515    * @relates Gnome::Gda::Statement
516    */
517   Glib::RefPtr<Gnome::Gda::Statement> wrap(GdaStatement* object, bool take_copy = false);
518 }
519 
520 
521 #endif /* _LIBGDAMM_STATEMENT_H */
522 
523