]> saetta.ns0.it Git - libgdaex/commitdiff
Added signals "before-execute" and "after-execute". 0.2.0
authorAndrea Zagli <azagli@libero.it>
Sat, 5 Jun 2010 09:08:33 +0000 (11:08 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 5 Jun 2010 09:08:33 +0000 (11:08 +0200)
Added private member gda_parse to GdaEx.

configure.ac
docs/reference/libgdaex-decl.txt
src/gdaex.c
src/libgdaex.h

index 61aa707f5dd71d0c40cdd8f5eb1fd0e9c7e312c1..70f4a8b2ca9a755eec341d5b460d42d1f891256c 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libgdaex], [0.1.0], [azagli@libero.it])
+AC_INIT([libgdaex], [0.2.0], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/gdaex.c])
 AM_CONFIG_HEADER([config.h])
 
index 1b8a3cd6e5ce9c8efcaa70f28821d95c9c858e4c..261e399da6defee21ebaecb49053fe70c47144d3 100644 (file)
@@ -40,6 +40,9 @@ struct _GdaEx
 struct _GdaExClass
        {
                GObjectClass parent_class;
+
+               guint before_execute_signal_id;
+               guint after_execute_signal_id;
        };
 </STRUCT>
 <FUNCTION>
index 4d7142ee44413e97f0f6c07954dcfef27e5d9ec7..8baf80c3d5d5177027c88427731f8957f70fd80a 100644 (file)
 #endif
 
 #include <string.h>
+#include <libgda/sql-parser/gda-sql-parser.h>
 
 #include "libgdaex.h"
 
 static void gdaex_class_init (GdaExClass *klass);
 static void gdaex_init (GdaEx *gdaex);
 
+static void gdaex_create_connection_parser (GdaEx *gdaex);
+
 static void gdaex_set_property (GObject *object,
                                guint property_id,
                                const GValue *value,
@@ -47,6 +50,7 @@ typedef struct _GdaExPrivate GdaExPrivate;
 struct _GdaExPrivate
        {
                GdaConnection *gda_conn;
+               GdaSqlParser *gda_parser;
        };
 
 G_DEFINE_TYPE (GdaEx, gdaex, G_TYPE_OBJECT)
@@ -60,6 +64,38 @@ gdaex_class_init (GdaExClass *klass)
 
        object_class->set_property = gdaex_set_property;
        object_class->get_property = gdaex_get_property;
+
+       /**
+        * GdaEx::before-execute:
+        * @gdaex:
+        * @gdastatement:
+        *
+        */
+       klass->before_execute_signal_id = g_signal_new ("before-execute",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__POINTER,
+                                                      G_TYPE_NONE,
+                                                      1, G_TYPE_POINTER);
+
+       /**
+        * GdaEx::after-execute:
+        * @gdaex:
+        * @gdastatement:
+        *
+        */
+       klass->after_execute_signal_id = g_signal_new ("after-execute",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__POINTER,
+                                                      G_TYPE_NONE,
+                                                      1, G_TYPE_POINTER);
 }
 
 static void
@@ -174,6 +210,8 @@ GdaEx
                        return NULL;
                }
 
+       gdaex_create_connection_parser (gdaex);
+
        return gdaex;
 }
 
@@ -220,6 +258,8 @@ GdaEx
                        return NULL;
                }
 
+       gdaex_create_connection_parser (gdaex);
+
        return gdaex;
 }
 
@@ -245,6 +285,8 @@ GdaEx
 
        priv->gda_conn = conn;
 
+       gdaex_create_connection_parser (gdaex);
+
        return gdaex;
 }
 
@@ -985,15 +1027,35 @@ gdaex_begin (GdaEx *gdaex)
 gint
 gdaex_execute (GdaEx *gdaex, const gchar *sql)
 {
+       GdaStatement *stmt;
        GError *error;
+
+       const gchar *remain;
        gint nrecs;
 
        g_return_val_if_fail (IS_GDAEX (gdaex), -1);
 
        GdaExPrivate *priv = GDAEX_GET_PRIVATE (gdaex);
+       GdaExClass *klass = GDAEX_GET_CLASS (gdaex);
 
        error = NULL;
-       nrecs = gda_execute_non_select_command (priv->gda_conn, sql, &error);
+       stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, &remain, &error);
+       if (remain)
+               {
+                       g_warning ("REMAINS:\n%s\nfrom\n%s", remain, sql);
+               }
+
+       if (error != NULL)
+               {
+                       g_warning ("Error parsing sql: %s\n%s\n",
+                                  error->message, sql);
+                       return -1;                      
+               }
+
+       g_signal_emit (gdaex, klass->before_execute_signal_id, 0, stmt);
+
+       error = NULL;
+       nrecs = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
 
        if (error != NULL)
                {
@@ -1002,6 +1064,8 @@ gdaex_execute (GdaEx *gdaex, const gchar *sql)
                        return -1;
                }
 
+       g_signal_emit (gdaex, klass->after_execute_signal_id, 0, stmt);
+
        return nrecs;
 }
 
@@ -1154,6 +1218,18 @@ gdaex_get_chr_quoting (GdaEx *gdaex)
 }
 
 /* PRIVATE */
+static void
+gdaex_create_connection_parser (GdaEx *gdaex)
+{
+       GdaExPrivate *priv = GDAEX_GET_PRIVATE (gdaex);
+
+       priv->gda_parser = gda_connection_create_parser (priv->gda_conn);
+       if (priv->gda_parser == NULL) /* @gda_conn doe snot provide its own parser => use default one */
+               {
+                       priv->gda_parser = gda_sql_parser_new ();
+               }
+}
+
 static void
 gdaex_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
index 3e3be893e5a581b4c659990a8e9f7da19f53e5e1..74848d7b80483ad4f799ecce088593bf7bce0622 100644 (file)
@@ -51,6 +51,9 @@ struct _GdaEx
 struct _GdaExClass
        {
                GObjectClass parent_class;
+
+               guint before_execute_signal_id;
+               guint after_execute_signal_id;
        };
 
 GType gdaex_get_type (void) G_GNUC_CONST;