[libgdamm] Wrap SqlBuilder::get_sql_statement().



commit e8ae8c54b166e6a7b58532ae87a33c964e1e669b
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue May 11 16:10:58 2010 +0200

    Wrap SqlBuilder::get_sql_statement().
    
    * libgda/src/sqlstatement.[hg|ccg]: Added SqlStatement, wrapping
        GdaSqlStatement.
        * libgda/src/sqlbuilder.hg: Wrap get_sql_statement().

 ChangeLog                    |   12 ++++++-
 libgda/src/filelist.am       |    1 +
 libgda/src/sqlbuilder.hg     |    6 ++-
 libgda/src/sqlstatement.ccg  |   45 ++++++++++++++++++++++++++++
 libgda/src/sqlstatement.hg   |   66 ++++++++++++++++++++++++++++++++++++++++++
 libgda/src/statement.hg      |   35 +++++++++++-----------
 tools/m4/convert_libgdamm.m4 |    4 ++
 7 files changed, 147 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0b098c5..e837bb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,17 @@
-2010-05-07  Murray Cumming  <murrayc murrayc-x61>
+2010-05-11  Murray Cumming  <murrayc murrayc com>
+
+    Wrap SqlBuilder::get_sql_statement().
+
+	* libgda/src/sqlstatement.[hg|ccg]: Added SqlStatement, wrapping
+    GdaSqlStatement.
+    * libgda/src/sqlbuilder.hg: Wrap get_sql_statement().
+
+2010-05-07  Murray Cumming  <murrayc murrayc com>
 
 	SqlBuilder: import_expression(): Remove the id parameter.
 
 	* libgda/src/sqlbuilder.hg: import_expression(): Remove the id parameter.
-	We generally don't let the caller specify an ID, though the C API does, 
+	We generally don't let the caller specify an ID, though the C API does,
 	for no good reason.
 	export_expression(): Make this const.
 
diff --git a/libgda/src/filelist.am b/libgda/src/filelist.am
index 7cc68dd..db3875f 100644
--- a/libgda/src/filelist.am
+++ b/libgda/src/filelist.am
@@ -43,6 +43,7 @@ files_hg =			\
 	sqlexpr.hg   \
 	sqlparser.hg		\
 	sqlbuilder.hg   \
+	sqlstatement.hg   \
 	statement.hg		\
 	transactionstatus.hg	\
 	xatransaction.hg
diff --git a/libgda/src/sqlbuilder.hg b/libgda/src/sqlbuilder.hg
index f364e7a..07857ae 100644
--- a/libgda/src/sqlbuilder.hg
+++ b/libgda/src/sqlbuilder.hg
@@ -21,6 +21,7 @@
 
 #include <libgdamm/statement.h>
 #include <libgdamm/sqlexpr.h>
+#include <libgdamm/sqlstatement.h>
 
 _DEFS(libgdamm,libgda)
 _PINCLUDE(glibmm/private/object_p.h)
@@ -48,8 +49,9 @@ public:
   _WRAP_CREATE(SqlStatementType type)
 
   _WRAP_METHOD(Glib::RefPtr<Statement> get_statement() const, gda_sql_builder_get_statement, errthrow)
-  // TODO: Wrap SqlStatement
-  //_WRAP_METHOD(Glib::RefPtr<SqlStatement> get_sql_statement(bool copy_it), gda_sql_builder_get_sql_statement, errthrow)
+
+  //TODO: Remove the stupid copy_it parameter from the C API.
+  _WRAP_METHOD(SqlStatement get_sql_statement(bool copy_it), gda_sql_builder_get_sql_statement, errthrow)
 
   _IGNORE(gda_sql_builder_add_expr, gda_sql_builder_add_param, gda_sql_builder_add_cond)
   _IGNORE(gda_sql_builder_add_cond_v, gda_sql_builder_add_id)
diff --git a/libgda/src/sqlstatement.ccg b/libgda/src/sqlstatement.ccg
new file mode 100644
index 0000000..241129e
--- /dev/null
+++ b/libgda/src/sqlstatement.ccg
@@ -0,0 +1,45 @@
+// -*- C++ -*- //
+
+/* quarklist.ccg
+ *
+ * Copyright 2001      Free Software Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <libgdamm/connection.h>
+#include <libgda/sql-parser/gda-statement-struct.h>
+#include <sql-parser/gda-sql-parser-enum-types.h>
+
+namespace Gnome
+{
+
+namespace Gda
+{
+
+SqlStatement::SqlStatement(SqlStatementType type)
+: gobject_(gda_sql_statement_new((GdaSqlStatementType)type))
+{
+}
+
+
+bool SqlStatement::empty() const
+{
+  return !gobject_;
+}
+
+} // namespace Gda
+
+} // namesoace Gnome
diff --git a/libgda/src/sqlstatement.hg b/libgda/src/sqlstatement.hg
new file mode 100644
index 0000000..cb81cbf
--- /dev/null
+++ b/libgda/src/sqlstatement.hg
@@ -0,0 +1,66 @@
+// -*- C++ -*- //
+
+/* Copyright 2010 libgdamm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+_DEFS(libgdamm,libgda)
+
+//#include <libgdamm/connection.h>
+#include <libgda/sql-parser/gda-statement-struct.h>
+
+namespace Gnome
+{
+
+namespace Gda
+{
+
+_WRAP_ENUM(SqlStatementType, GdaSqlStatementType)
+
+class Connection;
+
+/** TODO
+ */
+class SqlStatement
+{
+  _CLASS_BOXEDTYPE(SqlStatement, GdaSqlStatement, NONE, gda_sql_statement_copy, gda_sql_statement_free)
+  _IGNORE(gda_sql_statement_get_type, gda_sql_statement_copy, gda_sql_statement_free)
+
+public:
+
+  explicit SqlStatement(SqlStatementType type = SQL_STATEMENT_SELECT);
+  _IGNORE(gda_sql_statement_new)
+
+  bool empty() const;
+
+  _WRAP_METHOD(Glib::ustring serialize() const, gda_sql_statement_serialize)
+
+  //_WRAP_METHOD(static Glib::ustring type_to_string(SqlStatementType type), gda_sql_statement_type_to_string)
+  //_WRAP_METHOD(static SqlStatementType string_to_type (const Glib::ustring& type), gda_sql_statement_string_to_type)
+
+  _WRAP_METHOD(bool check_structure() const, gda_sql_statement_check_structure, errthrow)
+  _WRAP_METHOD(bool check_validity(const Glib::RefPtr<Connection>& cnc), gda_sql_statement_check_validity, errthrow)
+  _WRAP_METHOD(void check_clean(), gda_sql_statement_check_clean)
+  _WRAP_METHOD(bool normalize(const Glib::RefPtr<Connection>& cnc), gda_sql_statement_normalize, errthrow)
+
+  //_WRAP_METHOD(static GdaSqlStatementContentsInfo* get_contents_infos(SqlStatementType type), gda_sql_statement_get_contents_infos)
+
+
+};
+
+} // namespace Gda
+
+} // namespace Gnome
diff --git a/libgda/src/statement.hg b/libgda/src/statement.hg
index c6ab4f1..b3af345 100644
--- a/libgda/src/statement.hg
+++ b/libgda/src/statement.hg
@@ -21,6 +21,7 @@
 
 #include <libgdamm/set.h>
 #include <libgdamm/holder.h>
+#include <libgdamm/sqlstatement.h>
 
 _DEFS(libgdamm,libgda)
 _PINCLUDE(glibmm/private/object_p.h)
@@ -34,30 +35,29 @@ namespace Gda
 
 class Connection;
 
-_WRAP_ENUM(SqlStatementType, GdaSqlStatementType)
 _WRAP_ENUM(StatementModelUsage, GdaStatementModelUsage)
 _WRAP_ENUM(StatementSqlFlag, GdaStatementSqlFlag)
 
-_WRAP_GERROR(StatementError, GdaStatementError, GDA_STATEMENT_ERROR) 
-    
+_WRAP_GERROR(StatementError, GdaStatementError, GDA_STATEMENT_ERROR)
+
 /** Single SQL statement.
  *
- * The Gda::Statement represents a single SQL statement (multiple statements 
+ * The Gda::Statement represents a single SQL statement (multiple statements
  * can be grouped in a Batch object).
  *
  * A Gda::Statement can either be built "manually" by building a Gda::SqlStatement
  * structure, or from an SQL statement using a Gda::SqlParser object.
  * A GdaConnection can use a GdaStatement to:
  *
- *  - prepare it for a future execution, the preparation step involves converting the 
- *     GdaStatement object into a structure used by the database's own API, see 
+ *  - prepare it for a future execution, the preparation step involves converting the
+ *     GdaStatement object into a structure used by the database's own API, see
  *     Gda::Connection::statement_prepare()
  *  - execute it using Gda::Connection::statement_execute_select() if it is known
- *     that the statement is a selection statement, Gda::Connection::statement_execute_non_select() 
+ *     that the statement is a selection statement, Gda::Connection::statement_execute_non_select()
  *     if it is not a selection statement, or Gda::Connection::statement_execute()
  *     when the type of expected result is unknown.
- * Note that it is possible to use the same Gda::Statement object at the same time 
- * with several Gda::Connection objects. 
+ * Note that it is possible to use the same Gda::Statement object at the same time
+ * with several Gda::Connection objects.
  *
  * @ingroup Connection
  */
@@ -70,9 +70,9 @@ protected:
 public:
   _WRAP_CREATE()
   _WRAP_METHOD(Glib::RefPtr<Statement> copy() const, gda_statement_copy)
-  
+
   _WRAP_METHOD(Glib::ustring serialize() const, gda_statement_serialize)
-  
+
   //TODO: Should this be const? Probably not, because the caller could change Set. murrayc.
   _WRAP_METHOD_DOCS_ONLY(gda_statement_get_parameters)
   #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -81,7 +81,7 @@ public:
   bool get_parameters(Glib::RefPtr<Set>& out_params, std::auto_ptr<Glib::Error>& error);
   #endif //GLIBMM_EXCEPTIONS_ENABLED
   _IGNORE(gda_statement_get_parameters)
-  
+
   //TODO: Documentation:
   #ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ustring to_sql() const;
@@ -100,12 +100,12 @@ public:
   typedef Glib::ListHandle< const Glib::RefPtr<Holder> > HolderSList;
 
   //TODO: Add an overload without the params?
-  _WRAP_METHOD_DOCS_ONLY(gda_statement_to_sql_extended)  
+  _WRAP_METHOD_DOCS_ONLY(gda_statement_to_sql_extended)
   #ifdef GLIBMM_EXCEPTIONS_ENABLED
-  Glib::ustring to_sql(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<const Set>& params, 
+  Glib::ustring to_sql(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<const Set>& params,
                                 StatementSqlFlag flags, const HolderSList& params_used) const;
   #else
-  Glib::ustring to_sql(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<const Set>& params, 
+  Glib::ustring to_sql(const Glib::RefPtr<Connection>& cnc, const Glib::RefPtr<const Set>& params,
                                 StatementSqlFlag flags, const HolderSList& params_used,
                                 std::auto_ptr<Glib::Error>& error) const;
   #endif //GLIBMM_EXCEPTIONS_ENABLED
@@ -115,9 +115,9 @@ public:
   _WRAP_METHOD(bool check_structure() const, gda_statement_check_structure, errthrow)
   _WRAP_METHOD(bool check_validity(const Glib::RefPtr<Connection>& cnc) const, gda_statement_check_validity, errthrow)
   _WRAP_METHOD(bool normalize(const Glib::RefPtr<Connection>& cnc), gda_statement_normalize, errthrow)
-  
+
   //TODO: gda_statement_to_sql_real() : See http://bugzilla.gnome.org/show_bug.cgi?id=574738
-  
+
   //TODO: Use a real GType in libgda?
   _WRAP_PROPERTY("structure", gpointer)
 
@@ -130,4 +130,3 @@ public:
 
 } // namespace Gda
 } // namespace Gnome
-
diff --git a/tools/m4/convert_libgdamm.m4 b/tools/m4/convert_libgdamm.m4
index 0c176b1..c389d1f 100644
--- a/tools/m4/convert_libgdamm.m4
+++ b/tools/m4/convert_libgdamm.m4
@@ -129,6 +129,7 @@ _CONV_ENUM(Gda,StatementSqlFlag)
 _CONV_ENUM(Gda,SqlParserError)
 _CONV_ENUM(Gda,SqlOperatorType)
 _CONV_ENUM(Gda,SqlSelectJoinType)
+_CONV_ENUM(Gda,SqlStatementType)
 
 # structs
 _CONVERSION(`Blob&',`GdaBlob*',__FR2P)
@@ -155,3 +156,6 @@ _CONVERSION(`const GValue*', `Value', `$2($3)')
 
 _CONVERSION(`const SqlExpr&', `GdaSqlExpr*', `const_cast<GdaSqlExpr*>(($3).gobj())')
 _CONVERSION(`GdaSqlExpr*', `SqlExpr', `Glib::wrap($3)')
+
+_CONVERSION(`const SqlStatement&', `GdaSqlStatement*', `const_cast<GdaSqlStatement*>(($3).gobj())')
+_CONVERSION(`GdaSqlStatement*', `SqlStatement', `Glib::wrap($3)')



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]