[libgda] GdaSqlBuilder: Add gda_sql_builder_add_field_id(builder, field, table).



commit cd5dd04d7189b8cb1f996f8bca5391a0ee90750c
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jun 14 15:50:41 2010 +0200

    GdaSqlBuilder: Add gda_sql_builder_add_field_id(builder, field, table).
    
    * libgda/gda-sql-builder.[h|c]: Added gda_sql_builder_add_field_id()
    as an easier way to call gda_sql_builder_add_id() when you need to
    specify the field name with a table prefix to avoid ambiguity.
    Note that there was previously a gda_sql_builder_add_field_id()
    which has been renamed to gda_sql_builder_add_field_value_id().
    Luckily it's signature is quite different.
    * doc/C/libgda-sections.txt:
    * libgda/libgda.symbols: Mention the new function here.

 doc/C/libgda-sections.txt |    1 +
 libgda/gda-sql-builder.c  |   44 +++++++++++++++++++++++++++++++++++++++++++-
 libgda/gda-sql-builder.h  |    1 +
 libgda/libgda.symbols     |    1 +
 4 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index a358910..7a8272c 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -1681,6 +1681,7 @@ gda_sql_builder_add_function
 gda_sql_builder_add_function_v
 <SUBSECTION>
 gda_sql_builder_add_id
+gda_sql_builder_add_field_id
 gda_sql_builder_add_expr
 gda_sql_builder_add_expr_value
 gda_sql_builder_add_param
diff --git a/libgda/gda-sql-builder.c b/libgda/gda-sql-builder.c
index 0bd59e1..533e4e5 100644
--- a/libgda/gda-sql-builder.c
+++ b/libgda/gda-sql-builder.c
@@ -488,6 +488,8 @@ gda_sql_builder_set_where (GdaSqlBuilder *builder, GdaSqlBuilderId cond_id)
  *
  * Add a selected selected item to the SELECT statement.
  *
+ * For non-SELECT statements, see gda_sql_builder_add_field_id().
+ *
  * Returns: the ID of the added field, or 0 if there was an error
  *
  * Since: 4.2
@@ -846,7 +848,9 @@ gda_sql_builder_add_expr (GdaSqlBuilder *builder, GdaDataHandler *dh, GType type
  * @string: a string
  *
  * Defines an expression representing an identifier in @builder,
- * which may be reused to build other parts of a statement.
+ * which may be reused to build other parts of a statement,
+ * for instance as a parameter to gda_sql_builder_add_cond() or
+ * gda_sql_builder_add_field_value_id().
  *
  * The new expression will contain the @string literal.
  * For example:
@@ -863,6 +867,8 @@ gda_sql_builder_add_expr (GdaSqlBuilder *builder, GdaDataHandler *dh, GType type
  *
  * because "date" is an SQL reserved keyword.
  *
+ * For fields, see gda_sql_builder_add_field_id().
+ *
  * Returns: the ID of the new expression, or 0 if there was an error
  *
  * Since: 4.2
@@ -885,6 +891,42 @@ gda_sql_builder_add_id (GdaSqlBuilder *builder, const gchar *string)
 }
 
 /**
+ * gda_sql_builder_add_field_id
+ * @builder: a #GdaSqlBuilder object
+ * @field_name: a field name
+ * @table_name: a table name, or %NULL
+ *
+ * Defines an expression representing a field in @builder,
+ * which may be reused to build other parts of a statement,
+ * for instance as a parameter to gda_sql_builder_add_cond() or
+ * gda_sql_builder_add_field_value_id().
+ *
+ * Calling this with a %NULL @table_name is equivalent to calling gda_sql_builder_add_id().
+ *
+ * For SELECT queries, see gda_sql_builder_select_add_field().
+ *
+ * Returns: the ID of the new expression, or 0 if there was an error
+ *
+ * Since: 4.2
+ */
+GdaSqlBuilderId
+gda_sql_builder_add_field_id (GdaSqlBuilder *builder, const gchar *field_name, const gchar *table_name)
+{
+	gchar* tmp = 0;
+	if (table_name && *table_name)
+		tmp = g_strdup_printf ("%s.%s", table_name, field_name);
+	else
+		tmp = (gchar*) field_name;
+
+	guint field_id = gda_sql_builder_add_id (builder, tmp);
+
+	if (table_name)
+		g_free (tmp);
+
+	return field_id;
+}
+
+/**
  * gda_sql_builder_add_param
  * @builder: a #GdaSqlBuilder object
  * @param_name: parameter's name
diff --git a/libgda/gda-sql-builder.h b/libgda/gda-sql-builder.h
index 955d7fe..8c07794 100644
--- a/libgda/gda-sql-builder.h
+++ b/libgda/gda-sql-builder.h
@@ -75,6 +75,7 @@ GdaSqlStatement  *gda_sql_builder_get_sql_statement (GdaSqlBuilder *builder);
 
 /* Expression API */
 GdaSqlBuilderId gda_sql_builder_add_id (GdaSqlBuilder *builder, const gchar *string);
+GdaSqlBuilderId gda_sql_builder_add_field_id (GdaSqlBuilder *builder, const gchar *field_name, const gchar *table_name);
 GdaSqlBuilderId gda_sql_builder_add_expr (GdaSqlBuilder *builder, GdaDataHandler *dh, GType type, ...);
 GdaSqlBuilderId gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, GdaDataHandler *dh, const GValue *value);
 GdaSqlBuilderId gda_sql_builder_add_param (GdaSqlBuilder *builder, const gchar *param_name, GType type, gboolean nullok);
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 34159d1..df247aa 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -579,6 +579,7 @@
 	gda_sql_builder_add_cond_v
 	gda_sql_builder_add_expr
 	gda_sql_builder_add_expr_value
+	gda_sql_builder_add_field_id
 	gda_sql_builder_add_field_value
 	gda_sql_builder_add_field_value_id
 	gda_sql_builder_add_field_value_as_gvalue



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