[libgda] Fix for bug #596178, thanks to Johannes Schmid
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] Fix for bug #596178, thanks to Johannes Schmid
- Date: Thu, 24 Sep 2009 18:45:39 +0000 (UTC)
commit c6ae41c5941ac3b1bf84d0508b20a29b0a9c64ff
Author: Vivien Malerba <malerba gnome-db org>
Date: Thu Sep 24 20:44:27 2009 +0200
Fix for bug #596178, thanks to Johannes Schmid
doc/C/libgda-sections.txt | 1 +
doc/C/tmpl/gda-sql-builder.sgml | 12 +++++
libgda/gda-sql-builder.c | 100 +++++++++++++++++++++++++-------------
libgda/gda-sql-builder.h | 3 +-
4 files changed, 81 insertions(+), 35 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index 8a7a215..cda871f 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -1665,6 +1665,7 @@ gda_sql_builder_add_field
<SUBSECTION>
gda_sql_builder_ident
gda_sql_builder_expr
+gda_sql_builder_expr_value
gda_sql_builder_param
<SUBSECTION>
gda_sql_builder_cond
diff --git a/doc/C/tmpl/gda-sql-builder.sgml b/doc/C/tmpl/gda-sql-builder.sgml
index 84b178f..3021a34 100644
--- a/doc/C/tmpl/gda-sql-builder.sgml
+++ b/doc/C/tmpl/gda-sql-builder.sgml
@@ -123,6 +123,18 @@ gda_sql_builder_cond2 (b, 5, GDA_SQL_OPERATOR_TYPE_AND, 3, 4); // whole expressi
@Returns:
+<!-- ##### FUNCTION gda_sql_builder_expr_value ##### -->
+<para>
+
+</para>
+
+ builder:
+ id:
+ dh:
+ value:
+ Returns:
+
+
<!-- ##### FUNCTION gda_sql_builder_param ##### -->
<para>
diff --git a/libgda/gda-sql-builder.c b/libgda/gda-sql-builder.c
index dbcb956..5c2b07c 100644
--- a/libgda/gda-sql-builder.c
+++ b/libgda/gda-sql-builder.c
@@ -556,43 +556,30 @@ gda_sql_builder_add_field (GdaSqlBuilder *builder, guint field_id, guint value_i
}
/**
- * gda_sql_builder_expr
+ * gda_sql_builder_expr_value
* @builder: a #GdaSqlBuilder object
* @id: the requested ID, or 0 if to be determined by @builder
* @dh: a #GdaDataHandler to use, or %NULL
- * @type: the GType of the following argument
- * @...: value to set the expression to, of the type specified by @type
+ * @value: value to set the expression to, of the type specified by @type
*
* Defines an expression in @builder which may be reused to build other parts of a statement.
*
- * The new expression will contain the value passed as the @... argument. It is possible to
+ * The new expression will contain the value passed as the @value argument. It is possible to
* customize how the value has to be interpreted by passing a specific #GdaDataHandler object as @dh.
*
- * For example:
- * <programlisting>
- * gda_sql_builder_expr (b, 0, G_TYPE_INT, 15);
- * gda_sql_builder_expr (b, 5, G_TYPE_STRING, "joe")
- * </programlisting>
- *
- * will be rendered as SQL as:
- * <programlisting>
- * 15
- * 'joe'
- * </programlisting>
- *
* Returns: the ID of the new expression, or 0 if there was an error
*
* Since: 4.2
*/
guint
-gda_sql_builder_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GType type, ...)
+gda_sql_builder_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GValue *value)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
-
- va_list ap;
+ g_return_val_if_fail (value != NULL, 0);
+
+ GType type = G_VALUE_TYPE(value);
gchar *str;
- GValue *v = NULL;
if (!dh)
dh = gda_get_default_handler (type);
@@ -607,19 +594,7 @@ gda_sql_builder_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GTyp
return 0;
}
- va_start (ap, type);
- if (type == G_TYPE_STRING) {
- g_value_set_string ((v = gda_value_new (G_TYPE_STRING)), va_arg (ap, gchar*));
- str = gda_data_handler_get_sql_from_value (dh, v);
- }
- else if (type == G_TYPE_INT) {
- g_value_set_int ((v = gda_value_new (G_TYPE_INT)), va_arg (ap, gint));
- str = gda_data_handler_get_sql_from_value (dh, v);
- }
- va_end (ap);
-
- if (v)
- gda_value_free (v);
+ str = gda_data_handler_get_sql_from_value (dh, value);
if (str) {
GdaSqlExpr *expr;
@@ -635,6 +610,63 @@ gda_sql_builder_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GTyp
}
/**
+ * gda_sql_builder_expr
+ * @builder: a #GdaSqlBuilder object
+ * @id: the requested ID, or 0 if to be determined by @builder
+ * @dh: a #GdaDataHandler to use, or %NULL
+ * @type: the GType of the following argument
+ * @...: value to set the expression to, of the type specified by @type
+ *
+ * Defines an expression in @builder which may be reused to build other parts of a statement.
+ *
+ * The new expression will contain the value passed as the @v argument. It is possible to
+ * customize how the value has to be interpreted by passing a specific #GdaDataHandler object as @dh.
+ *
+ * For example:
+ * <programlisting>
+ * gda_sql_builder_expr (b, 0, G_TYPE_INT, 15);
+ * gda_sql_builder_expr (b, 5, G_TYPE_STRING, "joe")
+ * </programlisting>
+ *
+ * will be rendered as SQL as:
+ * <programlisting>
+ * 15
+ * 'joe'
+ * </programlisting>
+ *
+ * Returns: the ID of the new expression, or 0 if there was an error
+ *
+ * Since: 4.2
+ */
+guint
+gda_sql_builder_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GType type, ...)
+{
+ g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
+ g_return_val_if_fail (builder->priv->main_stmt, 0);
+
+ va_list ap;
+ GValue *v = NULL;
+ guint retval;
+
+ va_start (ap, type);
+ if (type == G_TYPE_STRING)
+ g_value_set_string ((v = gda_value_new (G_TYPE_STRING)), va_arg (ap, gchar*));
+ else if (type == G_TYPE_INT)
+ g_value_set_int ((v = gda_value_new (G_TYPE_INT)), va_arg (ap, gint));
+ else
+ g_warning (_("Could not convert value to type '%s'"), g_type_name (type));
+ va_end (ap);
+
+ if (!v)
+ return 0;
+ retval = gda_sql_builder_expr_value (builder, id, dh, v);
+
+ gda_value_free (v);
+
+ return retval;
+}
+
+/**
* gda_sql_builder_ident
* @builder: a #GdaSqlBuilder object
* @id: the requested ID, or 0 if to be determined by @builder
@@ -783,7 +815,7 @@ gda_sql_builder_cond (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op, g
*/
guint
gda_sql_builder_cond_v (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op,
- guint *op_ids, gint op_ids_size)
+ const guint *op_ids, gint op_ids_size)
{
gint i;
SqlPart **parts;
diff --git a/libgda/gda-sql-builder.h b/libgda/gda-sql-builder.h
index b76d0f0..72f17a5 100644
--- a/libgda/gda-sql-builder.h
+++ b/libgda/gda-sql-builder.h
@@ -72,12 +72,13 @@ GdaSqlStatement *gda_sql_builder_get_sql_statement (GdaSqlBuilder *builder, gbo
/* Expression API */
guint gda_sql_builder_ident (GdaSqlBuilder *builder, guint id, const gchar *string);
guint gda_sql_builder_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GType type, ...);
+guint gda_sql_builder_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GValue* value);
guint gda_sql_builder_param (GdaSqlBuilder *builder, guint id, const gchar *param_name, GType type, gboolean nullok);
guint gda_sql_builder_cond (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op,
guint op1, guint op2, guint op3);
guint gda_sql_builder_cond_v (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op,
- guint *op_ids, gint op_ids_size);
+ const guint *op_ids, gint op_ids_size);
/* SELECT Statement API */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]