From 2866dddfc2d418fb9f2ab019dd2e32b33688112e Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 5 Jun 2010 11:08:33 +0200 Subject: [PATCH] Added signals "before-execute" and "after-execute". Added private member gda_parse to GdaEx. --- configure.ac | 2 +- docs/reference/libgdaex-decl.txt | 3 ++ src/gdaex.c | 78 +++++++++++++++++++++++++++++++- src/libgdaex.h | 3 ++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 61aa707..70f4a8b 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/docs/reference/libgdaex-decl.txt b/docs/reference/libgdaex-decl.txt index 1b8a3cd..261e399 100644 --- a/docs/reference/libgdaex-decl.txt +++ b/docs/reference/libgdaex-decl.txt @@ -40,6 +40,9 @@ struct _GdaEx struct _GdaExClass { GObjectClass parent_class; + + guint before_execute_signal_id; + guint after_execute_signal_id; }; diff --git a/src/gdaex.c b/src/gdaex.c index 4d7142e..8baf80c 100644 --- a/src/gdaex.c +++ b/src/gdaex.c @@ -26,12 +26,15 @@ #endif #include +#include #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) { diff --git a/src/libgdaex.h b/src/libgdaex.h index 3e3be89..74848d7 100644 --- a/src/libgdaex.h +++ b/src/libgdaex.h @@ -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; -- 2.49.0