]> saetta.ns0.it Git - libgdaex/commitdiff
Added functions to get/set tables name prefix property.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 25 Aug 2010 11:23:02 +0000 (13:23 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 25 Aug 2010 11:23:02 +0000 (13:23 +0200)
Preparatory changes to the use of the property.

src/gdaex.c
src/libgdaex.h

index 8baf80c3d5d5177027c88427731f8957f70fd80a..9bd70a53041d354bb23ce8fddf2a6a1b1d2c90c9 100644 (file)
@@ -51,6 +51,8 @@ struct _GdaExPrivate
        {
                GdaConnection *gda_conn;
                GdaSqlParser *gda_parser;
+
+               gchar *tables_name_prefix;
        };
 
 G_DEFINE_TYPE (GdaEx, gdaex, G_TYPE_OBJECT)
@@ -322,6 +324,44 @@ const gchar
        return gda_server_provider_get_name (gda_connection_get_provider (priv->gda_conn));
 }
 
+/**
+ * gdaex_get_tables_name_prefix:
+ * @gdaex: a #GdaEx object.
+ *
+ */
+const gchar
+*gdaex_get_tables_name_prefix (GdaEx *gdaex)
+{
+       g_return_val_if_fail (IS_GDAEX (gdaex), NULL);
+
+       GdaExPrivate *priv = GDAEX_GET_PRIVATE (gdaex);
+
+       return g_strdup (priv->tables_name_prefix);
+}
+
+/**
+ * gdaex_set_tables_name_prefix:
+ * #gdaex: a #GdaEx object.
+ * @tables_name_prefix:
+ *
+ */
+void
+gdaex_set_tables_name_prefix (GdaEx *gdaex, const gchar *tables_name_prefix)
+{
+       g_return_if_fail (IS_GDAEX (gdaex));
+
+       GdaExPrivate *priv = GDAEX_GET_PRIVATE (gdaex);
+
+       if (tables_name_prefix == NULL)
+               {
+                       priv->tables_name_prefix = g_strdup ("");
+               }
+       else
+               {
+                       priv->tables_name_prefix = g_strstrip (g_strdup (tables_name_prefix));
+               }
+}
+
 /**
  * gdaex_query:
  * @gdaex: a #GdaEx object.
@@ -341,12 +381,21 @@ GdaDataModel
        GdaExPrivate *priv = GDAEX_GET_PRIVATE (gdaex);
 
        error = NULL;
-       GdaDataModel *dm = gda_execute_select_command (priv->gda_conn, sql, &error);
+       GdaStatement *stmt;
+       stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error);
+       if (!GDA_IS_STATEMENT (stmt))
+               {
+                       g_warning ("Error parsing query string: %s\n%s\n",
+                                  error != NULL && error->message != NULL ? error->message : "no details", sql);
+                       return NULL;
+               }
 
-       if (error != NULL)
+       error = NULL;
+       GdaDataModel *dm = gda_connection_statement_execute_select (priv->gda_conn, stmt, NULL, &error);
+       if (!GDA_IS_DATA_MODEL (dm))
                {
                        g_warning ("Error executing selection query: %s\n%s\n",
-                                  error->message, sql);
+                                  error != NULL && error->message != NULL ? error->message : "no details", sql);
                        return NULL;
                }
 
@@ -1049,7 +1098,7 @@ gdaex_execute (GdaEx *gdaex, const gchar *sql)
                {
                        g_warning ("Error parsing sql: %s\n%s\n",
                                   error->message, sql);
-                       return -1;                      
+                       return -1;
                }
 
        g_signal_emit (gdaex, klass->before_execute_signal_id, 0, stmt);
index 74848d7b80483ad4f799ecce088593bf7bce0622..7658341344203ae643025a4c06e5520820473a8e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  libgdaex.h
  *
- *  Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ *  Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libgdaex.
  *  
@@ -68,6 +68,9 @@ GdaEx *gdaex_new_from_connection (GdaConnection *conn);
 const GdaConnection *gdaex_get_gdaconnection (GdaEx *gdaex);
 const gchar *gdaex_get_provider (GdaEx *gdaex);
 
+const gchar *gdaex_get_tables_name_prefix (GdaEx *gdaex);
+void gdaex_set_tables_name_prefix (GdaEx *gdaex, const gchar *tables_name_prefix);
+
 GdaDataModel *gdaex_query (GdaEx *gdaex, const gchar *sql);
 
 gchar *gdaex_data_model_get_field_value_stringify_at (GdaDataModel *data_model,