[libgda] GdaSqlBuilder: Remove the ability to specify the IDs.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaSqlBuilder: Remove the ability to specify the IDs.
- Date: Wed, 19 May 2010 21:37:43 +0000 (UTC)
commit 61bd78640ae7188ad18fe3810a785c9d193f320c
Author: Murray Cumming <murrayc murrayc com>
Date: Wed May 19 21:21:44 2010 +0200
GdaSqlBuilder: Remove the ability to specify the IDs.
* libgda/gda-sql-builder.[h|c]:
(gda_sql_builder_add_id, gda_sql_builder_add_expr,
gda_sql_builder_add_expr_value, gda_sql_builder_add_param,
gda_sql_builder_add_cond, gda_sql_builder_add_cond_v,
gda_sql_builder_add_function, gda_sql_builder_add_function_v,
gda_sql_builder_add_sub_select, gda_sql_builder_add_case,
gda_sql_builder_add_case_v, gda_sql_builder_select_add_target_id,
gda_sql_builder_select_join_targets, gda_sql_builder_import_expression):
Remove the id parameter which could be 0 (and usually was), so the
caller must always now store the generated returned ID if necessary
instead. This simplifies the API and improves application code.
* providers/web/gda-web-recordset.c
* tools/browser/browser-connection.c
* tools/browser/browser-favorites.c
* tools/browser/data-manager/data-source.c:
* samples/SqlBuilder/example.c
* samples/SqlBuilder/example_cnc.c: Adapted.
* doc/C/howto.xml: Adapt the code in the tutorial-style documentation too.
doc/C/howto.xml | 132 ++++++++--------
libgda/gda-sql-builder.c | 105 +++++--------
libgda/gda-sql-builder.h | 31 ++--
providers/web/gda-web-recordset.c | 6 +-
samples/SqlBuilder/example.c | 262 +++++++++++++++---------------
samples/SqlBuilder/example_cnc.c | 142 ++++++++--------
tools/browser/browser-connection.c | 76 +++++-----
tools/browser/browser-favorites.c | 216 ++++++++++++------------
tools/browser/data-manager/data-source.c | 12 +-
9 files changed, 477 insertions(+), 505 deletions(-)
---
diff --git a/doc/C/howto.xml b/doc/C/howto.xml
index 55300d7..77602e7 100644
--- a/doc/C/howto.xml
+++ b/doc/C/howto.xml
@@ -85,8 +85,8 @@ GdaSqlBuilder *b;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
gda_sql_builder_set_table (b, "customers");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "e"),
-gda_sql_builder_add_param (b, 0, "p1", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (b, "e"),
+gda_sql_builder_add_param (b, "p1", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field (b, "f", G_TYPE_INT, 15);
gda_sql_builder_add_field (b, "g", G_TYPE_STRING, "joe")
[...]
@@ -104,8 +104,8 @@ gda_sql_builder_select_add_field (b, "firstname", "people", "person");
gda_sql_builder_select_add_field (b, "lastname", "people", NULL);
gda_sql_builder_select_add_field (b, "date", NULL, "birthdate");
gda_sql_builder_select_add_field (b, "age", NULL, NULL);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "people"),
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "people"),
NULL);
[...]
g_object_unref (b);
@@ -118,20 +118,20 @@ g_object_unref (b);
<programlisting>
GdaSqlBuilder *b;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_id (b, 1, "select"); /* SELECT is an SQL reserved keyword */
-gda_sql_builder_select_add_target_id (b, 1, 1, "c");
-gda_sql_builder_select_add_target_id (b, 2,
- gda_sql_builder_add_id (b, 0, "orders"),
+guint id_table = gda_sql_builder_add_id (b, "select"); /* SELECT is an SQL reserved keyword */
+guint id_target1 = gda_sql_builder_select_add_target_id (b, id_table, "c");
+guint id_target2 = gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "orders"),
NULL);
-gda_sql_builder_select_join_targets (b, 5, 1, 2, GDA_SQL_SELECT_JOIN_INNER, 0);
+guint id_join = gda_sql_builder_select_join_targets (b, id_target1, id_target2, GDA_SQL_SELECT_JOIN_INNER, 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "c.date"), 0); /* DATE is an SQL reserved keyword */
+ gda_sql_builder_add_id (b, "c.date"), 0); /* DATE is an SQL reserved keyword */
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "name"),
- gda_sql_builder_add_id (b, 0, "person"));
+ gda_sql_builder_add_id (b, "name"),
+ gda_sql_builder_add_id (b, "person"));
-gda_sql_builder_join_add_field (b, 5, "id");
+gda_sql_builder_join_add_field (b, id_join, "id");
[...]
g_object_unref (b);
</programlisting>
@@ -145,10 +145,10 @@ GdaSqlBuilder *b;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
gda_sql_builder_set_table (b, "products");
gda_sql_builder_add_field (b, "ref", G_TYPE_STRING, "A0E'FESP");
-gda_sql_builder_add_id (b, 1, "id");
-gda_sql_builder_add_expr (b, 2, NULL, G_TYPE_INT, 14);
-gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
-gda_sql_builder_set_where (b, 3);
+guint id_field = gda_sql_builder_add_id (b, "id");
+guint id_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 14);
+guint id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0);
+gda_sql_builder_set_where (b, id_cond);
[...]
g_object_unref (b);
</programlisting>
@@ -161,10 +161,10 @@ g_object_unref (b);
GdaSqlBuilder *b;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, "items");
-gda_sql_builder_add_id (b, 1, "id");
-gda_sql_builder_add_param (b, 2, "theid", G_TYPE_INT, FALSE);
-gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
-gda_sql_builder_set_where (b, 3);
+guint id_field = gda_sql_builder_add_id (b, "id");
+guint id_param = gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE);
+guint id_cond = gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_param, 0);
+gda_sql_builder_set_where (b, id_cond);
[...]
g_object_unref (b);
</programlisting>
@@ -176,15 +176,15 @@ g_object_unref (b);
<programlisting>
GdaSqlBuilder *b;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "mytable"),
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "mytable"),
NULL);
-gda_sql_builder_add_function (b, 1, "myfunc",
- gda_sql_builder_add_id (b, 0, "a"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 5),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Joe"),
+guint id_function = gda_sql_builder_add_function (b, "myfunc",
+ gda_sql_builder_add_id (b, "a"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 5),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Joe"),
0);
-gda_sql_builder_add_field_id (b, 1, 0);
+gda_sql_builder_add_field_id (b, id_function, 0);
[...]
g_object_unref (b);
</programlisting>
@@ -197,22 +197,22 @@ g_object_unref (b);
GdaSqlBuilder *b;
GdaSqlStatement *sub;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata"),
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata"),
NULL);
sub = gda_sql_builder_get_sql_statement (b, FALSE);
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "master"),
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "master"),
NULL);
-gda_sql_builder_add_id (b, 1, "id");
-gda_sql_builder_add_sub_select (b, 2, sub, TRUE);
-gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_IN, 1, 2, 0);
-gda_sql_builder_set_where (b, 3);
+guint id_field = gda_sql_builder_add_id (b, "id");
+guint id_subselect = gda_sql_builder_add_sub_select (b, sub, TRUE);
+guint id_cond = gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_IN, id_field, id_subselect, 0);
+gda_sql_builder_set_where (b, id_cond);
[...]
g_object_unref (b);
</programlisting>
@@ -225,21 +225,21 @@ g_object_unref (b);
GdaSqlBuilder *b;
GdaSqlStatement *sub;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "location"), 0);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdate"),
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "location"), 0);
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdate"),
NULL);
sub = gda_sql_builder_get_sql_statement (b, FALSE);
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
gda_sql_builder_set_table (b, "customers");
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "e"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "f"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "g"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, 0, sub, TRUE), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "e"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "f"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "g"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, sub, TRUE), 0);
[...]
g_object_unref (b);
</programlisting>
@@ -252,19 +252,19 @@ g_object_unref (b);
GdaSqlBuilder *b;
GdaSqlStatement *sub1, *sub2;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata1"),
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata1"),
NULL);
sub1 = gda_sql_builder_get_sql_statement (b, FALSE);
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "ident"), 0);
-gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "lastname"), 0);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata2"),
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "ident"), 0);
+gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "lastname"), 0);
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata2"),
NULL);
sub2 = gda_sql_builder_get_sql_statement (b, FALSE);
g_object_unref (b);
@@ -283,19 +283,19 @@ g_object_unref (b);
<programlisting>
GdaSqlBuilder *b;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
-gda_sql_builder_add_case (b, 10,
- gda_sql_builder_add_id (b, 0, "tag"),
+guint id_case = gda_sql_builder_add_case (b,
+ gda_sql_builder_add_id (b, "tag"),
0,
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Alpha"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 1),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Bravo"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 2),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Charlie"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 3),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Alpha"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 1),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Bravo"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 2),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Charlie"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 3),
0);
-gda_sql_builder_add_field_id (b, 10, 0);
-gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "data"),
+gda_sql_builder_add_field_id (b, id_case, 0);
+gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "data"),
NULL);
[...]
g_object_unref (b);
diff --git a/libgda/gda-sql-builder.c b/libgda/gda-sql-builder.c
index 136f75c..822f5ef 100644
--- a/libgda/gda-sql-builder.c
+++ b/libgda/gda-sql-builder.c
@@ -270,12 +270,11 @@ gda_sql_builder_get_property (GObject *object,
}
static guint
-add_part (GdaSqlBuilder *builder, guint id, GdaSqlAnyPart *part)
+add_part (GdaSqlBuilder *builder, GdaSqlAnyPart *part)
{
SqlPart *p;
guint *realid = g_new0 (guint, 1);
- if (id == 0)
- id = builder->priv->next_assigned_id --;
+ const guint id = builder->priv->next_assigned_id --;
*realid = id;
p = g_new0 (SqlPart, 1);
p->part = part;
@@ -510,11 +509,11 @@ gda_sql_builder_select_add_field (GdaSqlBuilder *builder, const gchar *field_nam
else
tmp = (gchar*) field_name;
- const guint field_id = gda_sql_builder_add_id (builder, 0, tmp);
+ const guint field_id = gda_sql_builder_add_id (builder, tmp);
if (alias && *alias)
gda_sql_builder_add_field_id (builder,
field_id,
- gda_sql_builder_add_id (builder, 0, alias));
+ gda_sql_builder_add_id (builder, alias));
else
gda_sql_builder_add_field_id (builder,
field_id,
@@ -577,8 +576,8 @@ gda_sql_builder_add_field (GdaSqlBuilder *builder, const gchar *field_name, GTyp
if (!value)
return;
- id1 = gda_sql_builder_add_id (builder, 0, field_name);
- id2 = gda_sql_builder_add_expr_value (builder, 0, NULL, value);
+ id1 = gda_sql_builder_add_id (builder, field_name);
+ id2 = gda_sql_builder_add_expr_value (builder, NULL, value);
gda_value_free (value);
gda_sql_builder_add_field_id (builder, id1, id2);
}
@@ -610,8 +609,8 @@ gda_sql_builder_add_field_value (GdaSqlBuilder *builder, const gchar *field_name
}
guint id1, id2;
- id1 = gda_sql_builder_add_id (builder, 0, field_name);
- id2 = gda_sql_builder_add_expr_value (builder, 0, NULL, value);
+ id1 = gda_sql_builder_add_id (builder, field_name);
+ id2 = gda_sql_builder_add_expr_value (builder, NULL, value);
gda_sql_builder_add_field_id (builder, id1, id2);
}
@@ -732,7 +731,6 @@ gda_sql_builder_add_field_id (GdaSqlBuilder *builder, guint field_id, guint valu
/**
* gda_sql_builder_add_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
* @value: value to set the expression to, or %NULL or a GDA_TYPE_NULL value to represent an SQL NULL
*
@@ -746,7 +744,7 @@ gda_sql_builder_add_field_id (GdaSqlBuilder *builder, guint field_id, guint valu
* Since: 4.2
*/
guint
-gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, const GValue *value)
+gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, GdaDataHandler *dh, const GValue *value)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -777,7 +775,7 @@ gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler
expr = gda_sql_expr_new (NULL);
expr->value = gda_value_new (G_TYPE_STRING);
g_value_take_string (expr->value, str);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
else {
g_warning (_("Could not convert value to type '%s'"),
@@ -789,7 +787,6 @@ gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler
/**
* gda_sql_builder_add_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
@@ -816,7 +813,7 @@ gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler
* Since: 4.2
*/
guint
-gda_sql_builder_add_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GType type, ...)
+gda_sql_builder_add_expr (GdaSqlBuilder *builder, 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);
@@ -831,7 +828,7 @@ gda_sql_builder_add_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh,
if (!value)
return 0;
- retval = gda_sql_builder_add_expr_value (builder, id, dh, value);
+ retval = gda_sql_builder_add_expr_value (builder, dh, value);
gda_value_free (value);
@@ -841,7 +838,6 @@ gda_sql_builder_add_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh,
/**
* gda_sql_builder_add_id
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @string: a string
*
* Defines an expression representing an identifier in @builder,
@@ -850,8 +846,8 @@ gda_sql_builder_add_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh,
* The new expression will contain the @string literal.
* For example:
* <programlisting>
- * gda_sql_builder_add_id (b, 0, "name")
- * gda_sql_builder_add_id (b, 0, "date")
+ * gda_sql_builder_add_id (b, "name")
+ * gda_sql_builder_add_id (b, "date")
* </programlisting>
*
* will be rendered as SQL as:
@@ -867,7 +863,7 @@ gda_sql_builder_add_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh,
* Since: 4.2
*/
guint
-gda_sql_builder_add_id (GdaSqlBuilder *builder, guint id, const gchar *string)
+gda_sql_builder_add_id (GdaSqlBuilder *builder, const gchar *string)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -880,13 +876,12 @@ gda_sql_builder_add_id (GdaSqlBuilder *builder, guint id, const gchar *string)
expr->value_is_ident = (gpointer) 0x1;
}
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
/**
* gda_sql_builder_add_param
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @param_name: parameter's name
* @type: parameter's type
* @nullok: TRUE if the parameter can be set to %NULL
@@ -910,7 +905,7 @@ gda_sql_builder_add_id (GdaSqlBuilder *builder, guint id, const gchar *string)
* Since: 4.2
*/
guint
-gda_sql_builder_add_param (GdaSqlBuilder *builder, guint id, const gchar *param_name, GType type, gboolean nullok)
+gda_sql_builder_add_param (GdaSqlBuilder *builder, const gchar *param_name, GType type, gboolean nullok)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -924,13 +919,12 @@ gda_sql_builder_add_param (GdaSqlBuilder *builder, guint id, const gchar *param_
expr->param_spec->nullok = nullok;
expr->param_spec->g_type = type;
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
/**
* gda_sql_builder_add_cond
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @op: type of condition
* @op1: the ID of the 1st argument (not 0)
* @op2: the ID of the 2nd argument (may be %0 if @op needs only one operand)
@@ -943,7 +937,7 @@ gda_sql_builder_add_param (GdaSqlBuilder *builder, guint id, const gchar *param_
* Since: 4.2
*/
guint
-gda_sql_builder_add_cond (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op, guint op1, guint op2, guint op3)
+gda_sql_builder_add_cond (GdaSqlBuilder *builder, GdaSqlOperatorType op, guint op1, guint op2, guint op3)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -969,13 +963,12 @@ gda_sql_builder_add_cond (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType o
use_part (p3, GDA_SQL_ANY_PART (expr->cond)));
}
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
/**
* gda_sql_builder_add_cond_v
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @op: type of condition
* @op_ids: an array of ID for the arguments (not %0)
* @ops_ids_size: size of @ops_ids
@@ -991,7 +984,7 @@ gda_sql_builder_add_cond (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType o
* Since: 4.2
*/
guint
-gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op,
+gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, GdaSqlOperatorType op,
const guint *op_ids, gint op_ids_size)
{
gint i;
@@ -1014,10 +1007,7 @@ gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType
if (op_ids_size == 1) {
SqlPart *part = parts [0];
g_free (parts);
- if (id)
- return add_part (builder, id, use_part (part, NULL));
- else
- return op_ids [0]; /* return the same ID as none was specified */
+ return op_ids [0];
}
GdaSqlExpr *expr;
@@ -1031,7 +1021,7 @@ gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType
GDA_SQL_ANY_PART (expr->cond)));
g_free (parts);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
@@ -1043,7 +1033,6 @@ typedef struct {
/**
* gda_sql_builder_select_add_target_id
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @table_id: the ID of the expression holding a table reference (not %0)
* @alias: the alias to give to the target, or %NULL
*
@@ -1054,7 +1043,7 @@ typedef struct {
* Since: 4.2
*/
guint
-gda_sql_builder_select_add_target_id (GdaSqlBuilder *builder, guint id, guint table_id, const gchar *alias)
+gda_sql_builder_select_add_target_id (GdaSqlBuilder *builder, guint table_id, const gchar *alias)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -1075,10 +1064,7 @@ gda_sql_builder_select_add_target_id (GdaSqlBuilder *builder, guint id, guint ta
btarget = g_new0 (BuildTarget, 1);
GDA_SQL_ANY_PART (btarget)->type = GDA_SQL_ANY_SQL_SELECT_TARGET;
GDA_SQL_ANY_PART (btarget)->parent = GDA_SQL_ANY_PART (sel->from);
- if (id)
- btarget->part_id = id;
- else
- btarget->part_id = builder->priv->next_assigned_id --;
+ btarget->part_id = builder->priv->next_assigned_id --;
target = (GdaSqlSelectTarget*) btarget;
target->expr = (GdaSqlExpr*) use_part (p, GDA_SQL_ANY_PART (btarget));
@@ -1123,8 +1109,7 @@ gda_sql_builder_select_add_target (GdaSqlBuilder *builder, const gchar *table_na
g_return_val_if_fail (table_name && *table_name, 0);
id = gda_sql_builder_select_add_target_id (builder,
- 0,
- gda_sql_builder_add_id (builder, 0, table_name),
+ gda_sql_builder_add_id (builder, table_name),
alias);
return id;
}
@@ -1138,7 +1123,6 @@ typedef struct {
/**
* gda_sql_builder_select_join_targets
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @left_target_id: the ID of the left target to use (not %0)
* @right_target_id: the ID of the right target to use (not %0)
* @join_type: the type of join
@@ -1151,7 +1135,7 @@ typedef struct {
* Since: 4.2
*/
guint
-gda_sql_builder_select_join_targets (GdaSqlBuilder *builder, guint id,
+gda_sql_builder_select_join_targets (GdaSqlBuilder *builder,
guint left_target_id, guint right_target_id,
GdaSqlSelectJoinType join_type,
guint join_expr)
@@ -1196,10 +1180,7 @@ gda_sql_builder_select_join_targets (GdaSqlBuilder *builder, guint id,
bjoin = g_new0 (BuilderJoin, 1);
GDA_SQL_ANY_PART (bjoin)->type = GDA_SQL_ANY_SQL_SELECT_JOIN;
GDA_SQL_ANY_PART (bjoin)->parent = GDA_SQL_ANY_PART (sel->from);
- if (id)
- bjoin->part_id = id;
- else
- bjoin->part_id = builder->priv->next_assigned_id --;
+ bjoin->part_id = builder->priv->next_assigned_id --;
join = (GdaSqlSelectJoin*) bjoin;
join->type = join_type;
join->position = right_pos;
@@ -1486,7 +1467,6 @@ gda_sql_builder_select_group_by (GdaSqlBuilder *builder, guint expr_id)
/**
* gda_sql_builder_add_function
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @function_id: the ID of the functions's name
* @...: a list, terminated with %0, of each function's argument's ID
*
@@ -1497,7 +1477,7 @@ gda_sql_builder_select_group_by (GdaSqlBuilder *builder, guint expr_id)
* Since: 4.2
*/
guint
-gda_sql_builder_add_function (GdaSqlBuilder *builder, guint id, const gchar *func_name, ...)
+gda_sql_builder_add_function (GdaSqlBuilder *builder, const gchar *func_name, ...)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -1525,13 +1505,12 @@ gda_sql_builder_add_function (GdaSqlBuilder *builder, guint id, const gchar *fun
va_end (ap);
expr->func->args_list = g_slist_reverse (list);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
/**
* gda_sql_builder_add_function_v
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @function_id: the ID of the functions's name
* @args: an array of IDs representing the function's arguments
* @args_size: @args's size
@@ -1543,7 +1522,7 @@ gda_sql_builder_add_function (GdaSqlBuilder *builder, guint id, const gchar *fun
* Since: 4.2
*/
guint
-gda_sql_builder_add_function_v (GdaSqlBuilder *builder, guint id, const gchar *func_name,
+gda_sql_builder_add_function_v (GdaSqlBuilder *builder, const gchar *func_name,
const guint *args, gint args_size)
{
gint i;
@@ -1569,13 +1548,12 @@ gda_sql_builder_add_function_v (GdaSqlBuilder *builder, guint id, const gchar *f
}
expr->func->args_list = g_slist_reverse (list);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
/**
* gda_sql_builder_add_sub_select
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @sqlst: a pointer to a #GdaSqlStatement, which has to be a SELECT or compound SELECT. This will be copied.
* @steal: if %TRUE, then @sqlst will be "stolen" by @b and should not be used anymore
*
@@ -1586,7 +1564,7 @@ gda_sql_builder_add_function_v (GdaSqlBuilder *builder, guint id, const gchar *f
* Since: 4.2
*/
guint
-gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, guint id, GdaSqlStatement *sqlst)
+gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement *sqlst)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -1610,7 +1588,7 @@ gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, guint id, GdaSqlStatemen
GDA_SQL_ANY_PART (expr->select)->parent = GDA_SQL_ANY_PART (expr);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
}
/**
@@ -1671,7 +1649,6 @@ gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement
/**
* gda_sql_builder_add_case
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @test_expr: the expression ID representing the test of the CASE, or %0
* @else_expr: the expression ID representing the ELSE expression, or %0
* @...: a list, terminated by a %0, of (WHEN expression ID, THEN expression ID) representing
@@ -1684,7 +1661,7 @@ gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement
* Since: 4.2
*/
guint
-gda_sql_builder_add_case (GdaSqlBuilder *builder, guint id,
+gda_sql_builder_add_case (GdaSqlBuilder *builder,
guint test_expr, guint else_expr, ...)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
@@ -1726,7 +1703,7 @@ gda_sql_builder_add_case (GdaSqlBuilder *builder, guint id,
va_end (ap);
expr->case_s->when_expr_list = g_slist_reverse (expr->case_s->when_expr_list);
expr->case_s->then_expr_list = g_slist_reverse (expr->case_s->then_expr_list);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
cleanups:
gda_sql_expr_free (expr);
@@ -1736,7 +1713,6 @@ gda_sql_builder_add_case (GdaSqlBuilder *builder, guint id,
/**
* gda_sql_builder_add_case_v
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @test_expr: the expression ID representing the test of the CASE, or %0
* @else_expr: the expression ID representing the ELSE expression, or %0
* @when_array: an array containing each WHEN expression ID, having at least @args_size elements
@@ -1752,7 +1728,7 @@ gda_sql_builder_add_case (GdaSqlBuilder *builder, guint id,
* Since: 4.2
*/
guint
-gda_sql_builder_add_case_v (GdaSqlBuilder *builder, guint id,
+gda_sql_builder_add_case_v (GdaSqlBuilder *builder,
guint test_expr, guint else_expr,
const guint *when_array, const guint *then_array, gint args_size)
{
@@ -1788,7 +1764,7 @@ gda_sql_builder_add_case_v (GdaSqlBuilder *builder, guint id,
}
expr->case_s->when_expr_list = g_slist_reverse (expr->case_s->when_expr_list);
expr->case_s->then_expr_list = g_slist_reverse (expr->case_s->then_expr_list);
- return add_part (builder, id, (GdaSqlAnyPart *) expr);
+ return add_part (builder, (GdaSqlAnyPart *) expr);
cleanups:
gda_sql_expr_free (expr);
@@ -1825,7 +1801,6 @@ gda_sql_builder_export_expression (GdaSqlBuilder *builder, guint id)
/**
* gda_sql_builder_import_expression
* @builder: a #GdaSqlBuilder object
- * @id: the requested ID, or 0 if to be determined by @builder
* @expr: a #GdaSqlExpr obtained using gda_sql_builder_export_expression()
*
* Imports the @expr into @builder.
@@ -1835,12 +1810,12 @@ gda_sql_builder_export_expression (GdaSqlBuilder *builder, guint id)
* Since: 4.2
*/
guint
-gda_sql_builder_import_expression (GdaSqlBuilder *builder, guint id, GdaSqlExpr *expr)
+gda_sql_builder_import_expression (GdaSqlBuilder *builder, GdaSqlExpr *expr)
{
g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
g_return_val_if_fail (builder->priv->main_stmt, 0);
g_return_val_if_fail (expr, 0);
g_return_val_if_fail (GDA_SQL_ANY_PART (expr)->type == GDA_SQL_ANY_EXPR, 0);
- return add_part (builder, id, (GdaSqlAnyPart *) gda_sql_expr_copy (expr));
+ return add_part (builder, (GdaSqlAnyPart *) gda_sql_expr_copy (expr));
}
diff --git a/libgda/gda-sql-builder.h b/libgda/gda-sql-builder.h
index 0904db1..086751c 100644
--- a/libgda/gda-sql-builder.h
+++ b/libgda/gda-sql-builder.h
@@ -72,23 +72,21 @@ GdaStatement *gda_sql_builder_get_statement (GdaSqlBuilder *builder, GError
GdaSqlStatement *gda_sql_builder_get_sql_statement (GdaSqlBuilder *builder);
/* Expression API */
-guint gda_sql_builder_add_id (GdaSqlBuilder *builder, guint id, const gchar *string);
-guint gda_sql_builder_add_expr (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, GType type, ...);
-guint gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, guint id, GdaDataHandler *dh, const GValue *value);
-guint gda_sql_builder_add_param (GdaSqlBuilder *builder, guint id, const gchar *param_name, GType type, gboolean nullok);
+guint gda_sql_builder_add_id (GdaSqlBuilder *builder, const gchar *string);
+guint gda_sql_builder_add_expr (GdaSqlBuilder *builder, GdaDataHandler *dh, GType type, ...);
+guint gda_sql_builder_add_expr_value (GdaSqlBuilder *builder, GdaDataHandler *dh, const GValue *value);
+guint gda_sql_builder_add_param (GdaSqlBuilder *builder, const gchar *param_name, GType type, gboolean nullok);
-guint gda_sql_builder_add_cond (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op,
+guint gda_sql_builder_add_cond (GdaSqlBuilder *builder, GdaSqlOperatorType op,
guint op1, guint op2, guint op3);
-guint gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, guint id, GdaSqlOperatorType op,
+guint gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, GdaSqlOperatorType op,
const guint *op_ids, gint op_ids_size);
-guint gda_sql_builder_add_function (GdaSqlBuilder *builder, guint id, const gchar *func_name, ...);
-guint gda_sql_builder_add_function_v (GdaSqlBuilder *builder, guint id, const gchar *func_name,
+guint gda_sql_builder_add_function (GdaSqlBuilder *builder, const gchar *func_name, ...);
+guint gda_sql_builder_add_function_v (GdaSqlBuilder *builder, const gchar *func_name,
const guint *args, gint args_size);
-guint gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, guint id, GdaSqlStatement *sqlst);
-guint gda_sql_builder_add_case (GdaSqlBuilder *builder, guint id,
- guint test_expr, guint else_expr, ...);
-guint gda_sql_builder_add_case_v (GdaSqlBuilder *builder, guint id,
- guint test_expr, guint else_expr,
+guint gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement *sqlst);
+guint gda_sql_builder_add_case (GdaSqlBuilder *builder, guint test_expr, guint else_expr, ...);
+guint gda_sql_builder_add_case_v (GdaSqlBuilder *builder, guint test_expr, guint else_expr,
const guint *when_array, const guint *then_array, gint args_size);
@@ -106,9 +104,8 @@ void gda_sql_builder_add_field_id (GdaSqlBuilder *builder, guint fi
guint gda_sql_builder_select_add_field (GdaSqlBuilder *builder, const gchar *field_name,
const gchar *table_name, const gchar *alias);
guint gda_sql_builder_select_add_target (GdaSqlBuilder *builder, const gchar *table_name, const gchar *alias);
-guint gda_sql_builder_select_add_target_id (GdaSqlBuilder *builder, guint id,
- guint table_id, const gchar *alias);
-guint gda_sql_builder_select_join_targets (GdaSqlBuilder *builder, guint id,
+guint gda_sql_builder_select_add_target_id (GdaSqlBuilder *builder, guint table_id, const gchar *alias);
+guint gda_sql_builder_select_join_targets (GdaSqlBuilder *builder,
guint left_target_id, guint right_target_id,
GdaSqlSelectJoinType join_type,
guint join_expr);
@@ -129,7 +126,7 @@ void gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builde
/* import/Export API */
GdaSqlExpr *gda_sql_builder_export_expression (GdaSqlBuilder *builder, guint id);
-guint gda_sql_builder_import_expression (GdaSqlBuilder *builder, guint id, GdaSqlExpr *expr);
+guint gda_sql_builder_import_expression (GdaSqlBuilder *builder, GdaSqlExpr *expr);
G_END_DECLS
diff --git a/providers/web/gda-web-recordset.c b/providers/web/gda-web-recordset.c
index a685644..cd7313e 100644
--- a/providers/web/gda-web-recordset.c
+++ b/providers/web/gda-web-recordset.c
@@ -343,10 +343,10 @@ create_table (GdaWebRecordset *rs, GError **error)
g_string_append_printf (string, "%s %s", colname,
gda_g_type_to_string (gda_column_get_g_type (column)));
- gda_sql_builder_add_field_id (ib, gda_sql_builder_add_id (ib, 0, colname),
- gda_sql_builder_add_param (ib, 0, colname,
+ gda_sql_builder_add_field_id (ib, gda_sql_builder_add_id (ib, colname),
+ gda_sql_builder_add_param (ib, colname,
gda_column_get_g_type (column), TRUE));
- gda_sql_builder_add_field_id (sb, gda_sql_builder_add_id (sb, 0, colname), 0);
+ gda_sql_builder_add_field_id (sb, gda_sql_builder_add_id (sb, colname), 0);
g_free (colname);
}
diff --git a/samples/SqlBuilder/example.c b/samples/SqlBuilder/example.c
index ecdccab..3fb5f0c 100644
--- a/samples/SqlBuilder/example.c
+++ b/samples/SqlBuilder/example.c
@@ -15,13 +15,13 @@ main (int argc, char *argv[])
gda_sql_builder_set_table (b, "customers");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "e"),
- gda_sql_builder_add_param (b, 0, "p1", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (b, "e"),
+ gda_sql_builder_add_param (b, "p1", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "f"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 15));
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "g"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "joe"));
+ gda_sql_builder_add_id (b, "f"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 15));
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "g"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "joe"));
render_as_sql (b);
g_object_unref (b);
@@ -32,18 +32,18 @@ main (int argc, char *argv[])
gda_sql_builder_set_table (b, "products");
gda_sql_builder_add_field (b, "ref", G_TYPE_STRING, "A0E'FESP");
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_expr (b, 2, NULL, G_TYPE_INT, 14);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ guint id_field = gda_sql_builder_add_id (b, "id");
+ guint id_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 14);
+ guint id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
/* reuse the same GdaSqlBuilder object to change the WHERE condition to: WHERE id = ##theid::int */
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
1,
- gda_sql_builder_add_param (b, 0, "theid", G_TYPE_INT, FALSE),
+ gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE),
0));
render_as_sql (b);
g_object_unref (b);
@@ -52,10 +52,10 @@ main (int argc, char *argv[])
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, "items");
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_param (b, 2, "theid", G_TYPE_INT, FALSE);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ id_field = gda_sql_builder_add_id (b, "id");
+ guint id_param = gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_param, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
g_object_unref (b);
@@ -67,48 +67,48 @@ main (int argc, char *argv[])
*/
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_id (b, 1, "select"); /* SELECT is an SQL reserved keyword */
- gda_sql_builder_select_add_target_id (b, 1, 1, "c");
- gda_sql_builder_select_add_target_id (b, 2,
- gda_sql_builder_add_id (b, 0, "orders"),
+ guint id_table = gda_sql_builder_add_id (b, "select"); /* SELECT is an SQL reserved keyword */
+ guint id_target1 = gda_sql_builder_select_add_target_id (b, id_table, "c");
+ guint id_target2 = gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "orders"),
NULL);
- gda_sql_builder_select_join_targets (b, 5, 1, 2, GDA_SQL_SELECT_JOIN_INNER, 0);
+ guint id_join = gda_sql_builder_select_join_targets (b, id_target1, id_target2, GDA_SQL_SELECT_JOIN_INNER, 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "c.date"), 0); /* DATE is an SQL reserved keyword */
+ gda_sql_builder_add_id (b, "c.date"), 0); /* DATE is an SQL reserved keyword */
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "name"),
- gda_sql_builder_add_id (b, 0, "person"));
+ gda_sql_builder_add_id (b, "name"),
+ gda_sql_builder_add_id (b, "person"));
render_as_sql (b);
/* reuse the same GdaSqlBuilder object to change the INNER join's condition */
- gda_sql_builder_join_add_field (b, 5, "id");
+ gda_sql_builder_join_add_field (b, id_join, "id");
render_as_sql (b);
g_object_unref (b);
/* SELECT myfunc (a, 5, 'Joe') FROM mytable */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "mytable"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "mytable"),
NULL);
- gda_sql_builder_add_function (b, 1, "myfunc",
- gda_sql_builder_add_id (b, 0, "a"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 5),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Joe"),
+ guint id_function_myfunc = gda_sql_builder_add_function (b, "myfunc",
+ gda_sql_builder_add_id (b, "a"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 5),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Joe"),
0);
- gda_sql_builder_add_field_id (b, 1, 0);
+ gda_sql_builder_add_field_id (b, id_function_myfunc, 0);
render_as_sql (b);
/* reuse the same GdaSqlBuilder object to have:
* SELECT myfunc (a, 5, 'Joe'), MAX (myfunc (a, 5, 'Joe'), b, 10) FROM mytable */
- guint args[] = {1, 3, 4};
- gda_sql_builder_add_id (b, 3, "b");
- gda_sql_builder_add_expr (b, 4, NULL, G_TYPE_INT, 10);
+ guint id_b = gda_sql_builder_add_id (b, "b");
+ guint id_b_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 10);
- gda_sql_builder_add_function_v (b, 5, "MAX", args, 3);
- gda_sql_builder_add_field_id (b, 5, 0);
+ guint args[] = {id_function_myfunc, id_b, id_b_value};
+ guint id_function_max = gda_sql_builder_add_function_v (b, "MAX", args, 3);
+ gda_sql_builder_add_field_id (b, id_function_max, 0);
render_as_sql (b);
g_object_unref (b);
@@ -118,77 +118,77 @@ main (int argc, char *argv[])
gda_sql_builder_set_table (b, "select");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "date"),
- gda_sql_builder_add_expr (b, 10, NULL, G_TYPE_STRING, "2009-05-27"));
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_expr (b, 2, NULL, G_TYPE_INT, 14);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ gda_sql_builder_add_id (b, "date"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "2009-05-27"));
+ id_field = gda_sql_builder_add_id (b, "id");
+ id_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 14);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
g_object_unref (b);
/* testing identifiers which are SQL reserved keywords */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (b, 1,
- gda_sql_builder_add_id (b, 0, "date"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "date"),
NULL);
- gda_sql_builder_select_add_target_id (b, 2,
- gda_sql_builder_add_id (b, 0, "MyTable"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "MyTable"),
NULL);
- gda_sql_builder_add_function (b, 1, "date",
- gda_sql_builder_add_id (b, 0, "a"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 5),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Joe"),
+ guint id_function = gda_sql_builder_add_function (b, "date",
+ gda_sql_builder_add_id (b, "a"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 5),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Joe"),
0);
- gda_sql_builder_add_field_id (b, 1, 0);
+ gda_sql_builder_add_field_id (b, id_function, 0);
render_as_sql (b);
g_object_unref (b);
/* Subselect: SELECT name FROM master WHERE id IN (SELECT id FROM subdata) */
GdaSqlStatement *sub;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata"),
NULL);
sub = gda_sql_statement_copy (gda_sql_builder_get_sql_statement (b));
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "master"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "master"),
NULL);
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_sub_select (b, 2, sub);
+ id_field = gda_sql_builder_add_id (b, "id");
+ guint id_subselect = gda_sql_builder_add_sub_select (b, sub);
gda_sql_statement_free (sub);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_IN, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_IN, id_field, id_subselect, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
g_object_unref (b);
/* SELECT id, name, (SELECT MAX (ts) FROM documents AS d WHERE t.id = d.topic) FROM topics AS t */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "documents"), "d");
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "documents"), "d");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_function (b, 0, "MAX",
- gda_sql_builder_add_id (b, 0, "ts"),
+ gda_sql_builder_add_function (b, "MAX",
+ gda_sql_builder_add_id (b, "ts"),
0), 0);
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "t.id"),
- gda_sql_builder_add_id (b, 0, "d.topic"), 0));
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "t.id"),
+ gda_sql_builder_add_id (b, "d.topic"), 0));
sub = gda_sql_statement_copy (gda_sql_builder_get_sql_statement (b));
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "topics"), "t");
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, 0, sub), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "topics"), "t");
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, sub), 0);
gda_sql_statement_free (sub);
render_as_sql (b);
@@ -196,11 +196,11 @@ main (int argc, char *argv[])
/* Subselect in INSERT: INSERT INTO customers (e, f, g) SELECT id, name, location FROM subdate */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "location"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdate"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "location"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdate"),
NULL);
sub = gda_sql_statement_copy (gda_sql_builder_get_sql_statement (b));
g_object_unref (b);
@@ -208,10 +208,10 @@ main (int argc, char *argv[])
b = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
gda_sql_builder_set_table (b, "customers");
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "e"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "f"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "g"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, 0, sub), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "e"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "f"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "g"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, sub), 0);
gda_sql_statement_free (sub);
render_as_sql (b);
@@ -221,19 +221,19 @@ main (int argc, char *argv[])
/* compound: SELECT id, name FROM subdata1 UNION SELECT ident, lastname FROM subdata2 */
GdaSqlStatement *sub1, *sub2;
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata1"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata1"),
NULL);
sub1 = gda_sql_statement_copy (gda_sql_builder_get_sql_statement (b));
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "ident"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "lastname"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata2"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "ident"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "lastname"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata2"),
NULL);
sub2 = gda_sql_statement_copy (gda_sql_builder_get_sql_statement (b));
g_object_unref (b);
@@ -248,18 +248,18 @@ main (int argc, char *argv[])
/* SELECT CASE WHEN price < 1.200000 THEN 2 ELSE 1 END FROM data */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_cond (b, 1, GDA_SQL_OPERATOR_TYPE_LT,
- gda_sql_builder_add_id (b, 0, "price"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_FLOAT, 1.2), 0);
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_LT,
+ gda_sql_builder_add_id (b, "price"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_FLOAT, 1.2), 0);
- gda_sql_builder_add_case (b, 10,
+ guint id_case = gda_sql_builder_add_case (b,
0,
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 1),
- 1, gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 2),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 1),
+ 1, gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 2),
0);
- gda_sql_builder_add_field_id (b, 10, 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "data"),
+ gda_sql_builder_add_field_id (b, id_case, 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "data"),
NULL);
render_as_sql (b);
g_object_unref (b);
@@ -267,18 +267,18 @@ main (int argc, char *argv[])
/* SELECT CASE tag WHEN 'Alpha' THEN 1 WHEN 'Bravo' THEN 2 WHEN 'Charlie' THEN 3 ELSE 0 END FROM data */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
gda_sql_builder_add_case (b, 10,
- gda_sql_builder_add_id (b, 0, "tag"),
+ gda_sql_builder_add_id (b, "tag"),
0,
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Alpha"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 1),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Bravo"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 2),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Charlie"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 3),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Alpha"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 1),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Bravo"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 2),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Charlie"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 3),
0);
gda_sql_builder_add_field_id (b, 10, 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "data"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "data"),
NULL);
render_as_sql (b);
g_object_unref (b);
@@ -292,8 +292,8 @@ main (int argc, char *argv[])
gda_sql_builder_select_add_field (b, "lastname", "people", NULL);
gda_sql_builder_select_add_field (b, "date", NULL, "birthdate");
gda_sql_builder_select_add_field (b, "age", NULL, NULL);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "people"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "people"),
NULL);
render_as_sql (b);
@@ -319,27 +319,27 @@ main (int argc, char *argv[])
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, "items");
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_param (b, 2, "theid", G_TYPE_INT, FALSE);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ id_field = gda_sql_builder_add_id (b, "id");
+ id_param = gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field , id_param, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
- expr = gda_sql_builder_export_expression (b, 3);
+ expr = gda_sql_builder_export_expression (b, id_cond);
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "mytable"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "mytable"),
NULL);
- gda_sql_builder_add_id (b, 1, "name");
- gda_sql_builder_add_param (b, 2, "thename", G_TYPE_STRING, FALSE);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
+ id_field = gda_sql_builder_add_id (b, "name");
+ id_param = gda_sql_builder_add_param (b, "thename", G_TYPE_STRING, FALSE);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_param, 0);
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_AND, 3,
- gda_sql_builder_import_expression (b, 0, expr),
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_AND, id_cond,
+ gda_sql_builder_import_expression (b, expr),
0));
gda_sql_expr_free (expr);
render_as_sql (b);
@@ -347,18 +347,18 @@ main (int argc, char *argv[])
/* Subselect: SELECT name FROM (SELECT id FROM subdata) as sub */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "subdata"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "subdata"),
NULL);
sub = gda_sql_statement_copy (gda_sql_builder_get_sql_statement (b));
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "name"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_sub_select (b, 0, sub), "sub");
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "name"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_sub_select (b, sub), "sub");
gda_sql_statement_free (sub);
render_as_sql (b);
diff --git a/samples/SqlBuilder/example_cnc.c b/samples/SqlBuilder/example_cnc.c
index 51555cf..3cffadf 100644
--- a/samples/SqlBuilder/example_cnc.c
+++ b/samples/SqlBuilder/example_cnc.c
@@ -15,13 +15,13 @@ main (int argc, char *argv[])
gda_sql_builder_set_table (b, "customers");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "e"),
- gda_sql_builder_add_param (b, 0, "p1", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (b, "e"),
+ gda_sql_builder_add_param (b, "p1", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "f"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 15));
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "g"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "joe"));
+ gda_sql_builder_add_id (b, "f"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 15));
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "g"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "joe"));
render_as_sql (b);
g_object_unref (b);
@@ -32,20 +32,20 @@ main (int argc, char *argv[])
gda_sql_builder_set_table (b, "products");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "ref"),
- gda_sql_builder_add_expr (b, 10, NULL, G_TYPE_STRING, "A0E'FESP"));
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_expr (b, 2, NULL, G_TYPE_INT, 14);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ gda_sql_builder_add_id (b, "ref"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "A0E'FESP"));
+ guint id_field = gda_sql_builder_add_id (b, "id");
+ guint id_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 14);
+ guint id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
/* reuse the same GdaSqlBuilder object to change the WHERE condition to: WHERE id = ##theid::int */
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- 1,
- gda_sql_builder_add_param (b, 0, "theid", G_TYPE_INT, FALSE),
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ id_field,
+ gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE),
0));
render_as_sql (b);
g_object_unref (b);
@@ -54,10 +54,10 @@ main (int argc, char *argv[])
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, "items");
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_param (b, 2, "theid", G_TYPE_INT, FALSE);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ id_field = gda_sql_builder_add_id (b, "id");
+ guint id_param = gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
g_object_unref (b);
@@ -69,48 +69,48 @@ main (int argc, char *argv[])
*/
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_id (b, 1, "select"); /* SELECT is an SQL reserved keyword */
- gda_sql_builder_select_add_target_id (b, 1, 1, "c");
- gda_sql_builder_select_add_target_id (b, 2,
- gda_sql_builder_add_id (b, 0, "orders"),
+ guint id_table = gda_sql_builder_add_id (b, "select"); /* SELECT is an SQL reserved keyword */
+ guint id_target1 = gda_sql_builder_select_add_target_id (b, id_table, "c");
+ guint id_target2 = gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "orders"),
NULL);
- gda_sql_builder_select_join_targets (b, 5, 1, 2, GDA_SQL_SELECT_JOIN_INNER, 0);
+ guint id_join = gda_sql_builder_select_join_targets (b, id_target1, id_target2, GDA_SQL_SELECT_JOIN_INNER, 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "c.date"), 0); /* DATE is an SQL reserved keyword */
+ gda_sql_builder_add_id (b, "c.date"), 0); /* DATE is an SQL reserved keyword */
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "name"),
- gda_sql_builder_add_id (b, 0, "person"));
+ gda_sql_builder_add_id (b, "name"),
+ gda_sql_builder_add_id (b, "person"));
render_as_sql (b);
/* reuse the same GdaSqlBuilder object to change the INNER join's condition */
- gda_sql_builder_join_add_field (b, 5, "id");
+ gda_sql_builder_join_add_field (b, id_join, "id");
render_as_sql (b);
g_object_unref (b);
/* SELECT myfunc (a, 5, 'Joe') FROM mytable */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "mytable"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "mytable"),
NULL);
- gda_sql_builder_add_function (b, 1, "myfunc",
- gda_sql_builder_add_id (b, 0, "a"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 5),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Joe"),
+ guint id_function_myfunc = gda_sql_builder_add_function (b, "myfunc",
+ gda_sql_builder_add_id (b, "a"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 5),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Joe"),
0);
- gda_sql_builder_add_field_id (b, 1, 0);
+ gda_sql_builder_add_field_id (b, id_function_myfunc, 0);
render_as_sql (b);
/* reuse the same GdaSqlBuilder object to have:
* SELECT myfunc (a, 5, 'Joe'), MAX (myfunc (a, 5, 'Joe'), b, 10) FROM mytable */
- guint args[] = {1, 3, 4};
- gda_sql_builder_add_id (b, 3, "b");
- gda_sql_builder_add_expr (b, 4, NULL, G_TYPE_INT, 10);
+ guint id_b = gda_sql_builder_add_id (b, "b");
+ guint id_b_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 10);
- gda_sql_builder_add_function_v (b, 5, "MAX", args, 3);
- gda_sql_builder_add_field_id (b, 5, 0);
+ guint args[] = {id_function_myfunc, id_b, id_b_value};
+ guint id_function_max = gda_sql_builder_add_function_v (b, "MAX", args, 3);
+ gda_sql_builder_add_field_id (b, id_function_max, 0);
render_as_sql (b);
g_object_unref (b);
@@ -120,32 +120,32 @@ main (int argc, char *argv[])
gda_sql_builder_set_table (b, "select");
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "date"),
- gda_sql_builder_add_expr (b, 10, NULL, G_TYPE_STRING, "2009-05-27"));
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_expr (b, 2, NULL, G_TYPE_INT, 14);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ gda_sql_builder_add_id (b, "date"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "2009-05-27"));
+ id_field = gda_sql_builder_add_id (b, "id");
+ id_value = gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 14);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_value, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
g_object_unref (b);
/* testing identifiers which are SQL reserved keywords */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (b, 1,
- gda_sql_builder_add_id (b, 0, "date"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "date"),
NULL);
- gda_sql_builder_select_add_target_id (b, 2,
- gda_sql_builder_add_id (b, 0, "MyTable"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "MyTable"),
NULL);
-
- gda_sql_builder_add_function (b, 1, "date",
- gda_sql_builder_add_id (b, 0, "a"),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_INT, 5),
- gda_sql_builder_add_expr (b, 0, NULL, G_TYPE_STRING, "Joe"),
+ guint id_function = gda_sql_builder_add_function (b, "date",
+ gda_sql_builder_add_id (b, "a"),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_INT, 5),
+ gda_sql_builder_add_expr (b, NULL, G_TYPE_STRING, "Joe"),
0);
- gda_sql_builder_add_field_id (b, 1, 0);
+ gda_sql_builder_add_field_id (b, id_function, 0);
render_as_sql (b);
+ g_object_unref (b);
/*
* SELECT people.firstname AS person, people.lastname, "date" AS birthdate, age FROM people
@@ -156,8 +156,8 @@ main (int argc, char *argv[])
gda_sql_builder_select_add_field (b, "lastname", "people", NULL);
gda_sql_builder_select_add_field (b, "date", NULL, "birthdate");
gda_sql_builder_select_add_field (b, "age", NULL, NULL);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "people"),
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "people"),
NULL);
render_as_sql (b);
@@ -183,27 +183,27 @@ main (int argc, char *argv[])
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, "items");
- gda_sql_builder_add_id (b, 1, "id");
- gda_sql_builder_add_param (b, 2, "theid", G_TYPE_INT, FALSE);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ id_field = gda_sql_builder_add_id (b, "id");
+ id_param = gda_sql_builder_add_param (b, "theid", G_TYPE_INT, FALSE);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_param, 0);
+ gda_sql_builder_set_where (b, id_cond);
render_as_sql (b);
- expr = gda_sql_builder_export_expression (b, 3);
+ expr = gda_sql_builder_export_expression (b, id_cond);
g_object_unref (b);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "id"), 0);
- gda_sql_builder_select_add_target_id (b, 0,
- gda_sql_builder_add_id (b, 0, "mytable"),
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "id"), 0);
+ gda_sql_builder_select_add_target_id (b,
+ gda_sql_builder_add_id (b, "mytable"),
NULL);
- gda_sql_builder_add_id (b, 1, "name");
- gda_sql_builder_add_param (b, 2, "thename", G_TYPE_STRING, FALSE);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
+ id_field = gda_sql_builder_add_id (b, "name");
+ id_param = gda_sql_builder_add_param (b, "thename", G_TYPE_STRING, FALSE);
+ id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id_field, id_param, 0);
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_AND, 3,
- gda_sql_builder_import_expression (b, 0, expr),
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_AND, id_cond,
+ gda_sql_builder_import_expression (b, expr),
0));
gda_sql_expr_free (expr);
render_as_sql (b);
diff --git a/tools/browser/browser-connection.c b/tools/browser/browser-connection.c
index bbe5ff3..62e43a3 100644
--- a/tools/browser/browser-connection.c
+++ b/tools/browser/browser-connection.c
@@ -1216,24 +1216,24 @@ browser_connection_set_table_column_attribute (BrowserConnection *bcnc,
builder = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (builder, DBTABLE_PREFERENCES_TABLE_NAME);
- op_ids[0] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "table_schema"),
- gda_sql_builder_add_param (builder, 0, "schema", G_TYPE_STRING,
+ op_ids[0] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_schema"),
+ gda_sql_builder_add_param (builder, "schema", G_TYPE_STRING,
FALSE), 0);
- op_ids[1] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "table_name"),
- gda_sql_builder_add_param (builder, 0, "name", G_TYPE_STRING,
+ op_ids[1] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING,
FALSE), 0);
- op_ids[2] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "table_column"),
- gda_sql_builder_add_param (builder, 0, "column", G_TYPE_STRING,
+ op_ids[2] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_column"),
+ gda_sql_builder_add_param (builder, "column", G_TYPE_STRING,
FALSE), 0);
- op_ids[3] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "att_name"),
- gda_sql_builder_add_param (builder, 0, "attname", G_TYPE_STRING,
+ op_ids[3] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "att_name"),
+ gda_sql_builder_add_param (builder, "attname", G_TYPE_STRING,
FALSE), 0);
gda_sql_builder_set_where (builder,
- gda_sql_builder_add_cond_v (builder, 0, GDA_SQL_OPERATOR_TYPE_AND,
+ gda_sql_builder_add_cond_v (builder, GDA_SQL_OPERATOR_TYPE_AND,
op_ids, 4));
stmt = gda_sql_builder_get_statement (builder, error);
g_object_unref (G_OBJECT (builder));
@@ -1250,20 +1250,20 @@ browser_connection_set_table_column_attribute (BrowserConnection *bcnc,
builder = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
gda_sql_builder_set_table (builder, DBTABLE_PREFERENCES_TABLE_NAME);
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "table_schema"),
- gda_sql_builder_add_param (builder, 0, "schema", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "table_schema"),
+ gda_sql_builder_add_param (builder, "schema", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "table_name"),
- gda_sql_builder_add_param (builder, 0, "name", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "table_name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "table_column"),
- gda_sql_builder_add_param (builder, 0, "column", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "table_column"),
+ gda_sql_builder_add_param (builder, "column", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "att_name"),
- gda_sql_builder_add_param (builder, 0, "attname", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "att_name"),
+ gda_sql_builder_add_param (builder, "attname", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "att_value"),
- gda_sql_builder_add_param (builder, 0, "attvalue", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "att_value"),
+ gda_sql_builder_add_param (builder, "attvalue", G_TYPE_STRING, FALSE));
stmt = gda_sql_builder_get_statement (builder, error);
g_object_unref (G_OBJECT (builder));
if (!stmt)
@@ -1351,28 +1351,28 @@ browser_connection_get_table_column_attribute (BrowserConnection *bcnc,
"attname", G_TYPE_STRING, attr_name);
builder = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_select_add_target_id (builder, 0,
- gda_sql_builder_add_id (builder, 0, DBTABLE_PREFERENCES_TABLE_NAME),
+ gda_sql_builder_select_add_target_id (builder,
+ gda_sql_builder_add_id (builder, DBTABLE_PREFERENCES_TABLE_NAME),
NULL);
gda_sql_builder_select_add_field (builder, "att_value", NULL, NULL);
- op_ids[0] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "table_schema"),
- gda_sql_builder_add_param (builder, 0, "schema", G_TYPE_STRING,
+ op_ids[0] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_schema"),
+ gda_sql_builder_add_param (builder, "schema", G_TYPE_STRING,
FALSE), 0);
- op_ids[1] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "table_name"),
- gda_sql_builder_add_param (builder, 0, "name", G_TYPE_STRING,
+ op_ids[1] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING,
FALSE), 0);
- op_ids[2] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "table_column"),
- gda_sql_builder_add_param (builder, 0, "column", G_TYPE_STRING,
+ op_ids[2] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_column"),
+ gda_sql_builder_add_param (builder, "column", G_TYPE_STRING,
FALSE), 0);
- op_ids[3] = gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "att_name"),
- gda_sql_builder_add_param (builder, 0, "attname", G_TYPE_STRING,
+ op_ids[3] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "att_name"),
+ gda_sql_builder_add_param (builder, "attname", G_TYPE_STRING,
FALSE), 0);
gda_sql_builder_set_where (builder,
- gda_sql_builder_add_cond_v (builder, 0, GDA_SQL_OPERATOR_TYPE_AND,
+ gda_sql_builder_add_cond_v (builder, GDA_SQL_OPERATOR_TYPE_AND,
op_ids, 4));
stmt = gda_sql_builder_get_statement (builder, error);
g_object_unref (G_OBJECT (builder));
diff --git a/tools/browser/browser-favorites.c b/tools/browser/browser-favorites.c
index 698bc86..26cd560 100644
--- a/tools/browser/browser-favorites.c
+++ b/tools/browser/browser-favorites.c
@@ -249,16 +249,16 @@ find_favorite_position (BrowserFavorites *bfav, gint fav_id, gint order_key)
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "rank"), 0);
+ gda_sql_builder_add_id (b, "rank"), 0);
gda_sql_builder_select_add_target (b, FAVORDER_TABLE_NAME, NULL);
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_AND,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "fav_id"),
- gda_sql_builder_add_param (b, 0, "favid", G_TYPE_INT, FALSE), 0),
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "order_key"),
- gda_sql_builder_add_param (b, 0, "okey", G_TYPE_INT, FALSE), 0),
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_AND,
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "fav_id"),
+ gda_sql_builder_add_param (b, "favid", G_TYPE_INT, FALSE), 0),
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "order_key"),
+ gda_sql_builder_add_param (b, "okey", G_TYPE_INT, FALSE), 0),
0));
stmt = gda_sql_builder_get_statement (b, NULL);
@@ -312,34 +312,34 @@ find_favorite (BrowserFavorites *bfav, guint session_id, gint id, const gchar *c
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "id"), 0);
+ gda_sql_builder_add_id (b, "id"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "type"), 0);
+ gda_sql_builder_add_id (b, "type"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "name"), 0);
+ gda_sql_builder_add_id (b, "name"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "descr"), 0);
+ gda_sql_builder_add_id (b, "descr"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "contents"), 0);
+ gda_sql_builder_add_id (b, "contents"), 0);
gda_sql_builder_select_add_target (b, FAVORITES_TABLE_NAME, NULL);
if (id >= 0) {
/* lookup from ID */
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "id"),
- gda_sql_builder_add_param (b, 0, "id", G_TYPE_INT, FALSE), 0));
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "id"),
+ gda_sql_builder_add_param (b, "id", G_TYPE_INT, FALSE), 0));
}
else {
/* lookup using session and contents */
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_AND,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "session"),
- gda_sql_builder_add_param (b, 0, "session", G_TYPE_INT, FALSE), 0),
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "contents"),
- gda_sql_builder_add_param (b, 0, "contents", G_TYPE_INT, FALSE), 0), 0));
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_AND,
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "session"),
+ gda_sql_builder_add_param (b, "session", G_TYPE_INT, FALSE), 0),
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "contents"),
+ gda_sql_builder_add_param (b, "contents", G_TYPE_INT, FALSE), 0), 0));
}
stmt = gda_sql_builder_get_statement (b, error);
g_object_unref (G_OBJECT (b));
@@ -399,15 +399,15 @@ favorites_reorder (BrowserFavorites *bfav, gint order_key, gint id, gint new_pos
g_assert (order_key >= 0);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
- gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, 0, "fav_id"), 0);
+ gda_sql_builder_add_field_id (b, gda_sql_builder_add_id (b, "fav_id"), 0);
gda_sql_builder_select_add_target (b, FAVORDER_TABLE_NAME, NULL);
- gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, 1, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "order_key"),
- gda_sql_builder_add_param (b, 0, "orderkey", G_TYPE_INT, FALSE), 0));
+ gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "order_key"),
+ gda_sql_builder_add_param (b, "orderkey", G_TYPE_INT, FALSE), 0));
gda_sql_builder_select_order_by (b,
- gda_sql_builder_add_id (b, 0, "rank"), TRUE, NULL);
+ gda_sql_builder_add_id (b, "rank"), TRUE, NULL);
stmt = gda_sql_builder_get_statement (b, error);
g_object_unref (G_OBJECT (b));
if (!stmt)
@@ -434,17 +434,17 @@ favorites_reorder (BrowserFavorites *bfav, gint order_key, gint id, gint new_pos
b = gda_sql_builder_new (GDA_SQL_STATEMENT_UPDATE);
gda_sql_builder_set_table (b, FAVORDER_TABLE_NAME);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "rank"),
- gda_sql_builder_add_param (b, 0, "rank", G_TYPE_INT, FALSE));
- gda_sql_builder_add_cond (b, 1, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "fav_id"),
- gda_sql_builder_add_param (b, 0, "id", G_TYPE_INT, FALSE),
+ gda_sql_builder_add_id (b, "rank"),
+ gda_sql_builder_add_param (b, "rank", G_TYPE_INT, FALSE));
+ const guint id_cond1 = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "fav_id"),
+ gda_sql_builder_add_param (b, "id", G_TYPE_INT, FALSE),
0);
- gda_sql_builder_add_cond (b, 2, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "order_key"),
- gda_sql_builder_add_param (b, 0, "orderkey", G_TYPE_INT, FALSE),
+ const guint id_cond2 = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "order_key"),
+ gda_sql_builder_add_param (b, "orderkey", G_TYPE_INT, FALSE),
0);
- gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_AND, 1, 2, 0));
+ gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_AND, id_cond1, id_cond2, 0));
stmt = gda_sql_builder_get_statement (b, error);
if (!stmt) {
retval = FALSE;
@@ -560,20 +560,20 @@ browser_favorites_add (BrowserFavorites *bfav, guint session_id,
gda_sql_builder_set_table (builder, FAVORITES_TABLE_NAME);
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "session"),
- gda_sql_builder_add_param (builder, 0, "session", G_TYPE_INT, FALSE));
+ gda_sql_builder_add_id (builder, "session"),
+ gda_sql_builder_add_param (builder, "session", G_TYPE_INT, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "type"),
- gda_sql_builder_add_param (builder, 0, "type", G_TYPE_INT, FALSE));
+ gda_sql_builder_add_id (builder, "type"),
+ gda_sql_builder_add_param (builder, "type", G_TYPE_INT, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "name"),
- gda_sql_builder_add_param (builder, 0, "name", G_TYPE_STRING, TRUE));
+ gda_sql_builder_add_id (builder, "name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING, TRUE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "contents"),
- gda_sql_builder_add_param (builder, 0, "contents", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "contents"),
+ gda_sql_builder_add_param (builder, "contents", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "descr"),
- gda_sql_builder_add_param (builder, 0, "descr", G_TYPE_STRING, TRUE));
+ gda_sql_builder_add_id (builder, "descr"),
+ gda_sql_builder_add_param (builder, "descr", G_TYPE_STRING, TRUE));
stmt = gda_sql_builder_get_statement (builder, error);
g_object_unref (G_OBJECT (builder));
if (!stmt)
@@ -597,29 +597,29 @@ browser_favorites_add (BrowserFavorites *bfav, guint session_id,
gda_sql_builder_set_table (builder, FAVORITES_TABLE_NAME);
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "name"),
- gda_sql_builder_add_param (builder, 0, "name", G_TYPE_STRING, TRUE));
+ gda_sql_builder_add_id (builder, "name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING, TRUE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "contents"),
- gda_sql_builder_add_param (builder, 0, "contents", G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_id (builder, "contents"),
+ gda_sql_builder_add_param (builder, "contents", G_TYPE_STRING, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "descr"),
- gda_sql_builder_add_param (builder, 0, "descr", G_TYPE_STRING, TRUE));
+ gda_sql_builder_add_id (builder, "descr"),
+ gda_sql_builder_add_param (builder, "descr", G_TYPE_STRING, TRUE));
gda_sql_builder_set_where (builder,
- gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "id"),
- gda_sql_builder_add_param (builder, 0, "id", G_TYPE_INT, FALSE),
+ gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "id"),
+ gda_sql_builder_add_param (builder, "id", G_TYPE_INT, FALSE),
0));
if (fav->id == favid) {
/* alter name and description only if fav->id was OK */
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "name"),
- gda_sql_builder_add_param (builder, 0, "name", G_TYPE_STRING,
+ gda_sql_builder_add_id (builder, "name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING,
TRUE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "descr"),
- gda_sql_builder_add_param (builder, 0, "descr", G_TYPE_STRING,
+ gda_sql_builder_add_id (builder, "descr"),
+ gda_sql_builder_add_param (builder, "descr", G_TYPE_STRING,
TRUE));
}
@@ -652,14 +652,14 @@ browser_favorites_add (BrowserFavorites *bfav, guint session_id,
builder = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (builder, FAVORDER_TABLE_NAME);
gda_sql_builder_set_where (builder,
- gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_AND,
- gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "fav_id"),
- gda_sql_builder_add_param (builder, 0, "id", G_TYPE_INT, FALSE),
+ gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_AND,
+ gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "fav_id"),
+ gda_sql_builder_add_param (builder, "id", G_TYPE_INT, FALSE),
0),
- gda_sql_builder_add_cond (builder, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (builder, 0, "order_key"),
- gda_sql_builder_add_param (builder, 0, "orderkey", G_TYPE_INT, FALSE),
+ gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "order_key"),
+ gda_sql_builder_add_param (builder, "orderkey", G_TYPE_INT, FALSE),
0), 0));
stmt = gda_sql_builder_get_statement (builder, error);
g_object_unref (G_OBJECT (builder));
@@ -674,14 +674,14 @@ browser_favorites_add (BrowserFavorites *bfav, guint session_id,
builder = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
gda_sql_builder_set_table (builder, FAVORDER_TABLE_NAME);
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "fav_id"),
- gda_sql_builder_add_param (builder, 0, "id", G_TYPE_INT, FALSE));
+ gda_sql_builder_add_id (builder, "fav_id"),
+ gda_sql_builder_add_param (builder, "id", G_TYPE_INT, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "rank"),
- gda_sql_builder_add_param (builder, 0, "rank", G_TYPE_INT, FALSE));
+ gda_sql_builder_add_id (builder, "rank"),
+ gda_sql_builder_add_param (builder, "rank", G_TYPE_INT, FALSE));
gda_sql_builder_add_field_id (builder,
- gda_sql_builder_add_id (builder, 0, "order_key"),
- gda_sql_builder_add_param (builder, 0, "orderkey", G_TYPE_STRING, TRUE));
+ gda_sql_builder_add_id (builder, "order_key"),
+ gda_sql_builder_add_param (builder, "orderkey", G_TYPE_STRING, TRUE));
stmt = gda_sql_builder_get_statement (builder, error);
g_object_unref (G_OBJECT (builder));
if (!stmt)
@@ -792,37 +792,37 @@ browser_favorites_list (BrowserFavorites *bfav, guint session_id, BrowserFavorit
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "fav.contents"), 0);
+ gda_sql_builder_add_id (b, "fav.contents"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "fav.descr"), 0);
+ gda_sql_builder_add_id (b, "fav.descr"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "fav.name"), 0);
+ gda_sql_builder_add_id (b, "fav.name"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "fav.type"), 0);
+ gda_sql_builder_add_id (b, "fav.type"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "fav.id"), 0);
+ gda_sql_builder_add_id (b, "fav.id"), 0);
t1 = gda_sql_builder_select_add_target (b, FAVORITES_TABLE_NAME, "fav");
if (order_key > 0) {
t2 = gda_sql_builder_select_add_target (b, FAVORDER_TABLE_NAME, "o");
- gda_sql_builder_select_join_targets (b, 0, t1, t2, GDA_SQL_SELECT_JOIN_LEFT,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "fav.id"),
- gda_sql_builder_add_id (b, 0, "o.fav_id"),
+ gda_sql_builder_select_join_targets (b, t1, t2, GDA_SQL_SELECT_JOIN_LEFT,
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "fav.id"),
+ gda_sql_builder_add_id (b, "o.fav_id"),
0));
gda_sql_builder_select_order_by (b,
- gda_sql_builder_add_id (b, 0, "o.rank"), TRUE, NULL);
+ gda_sql_builder_add_id (b, "o.rank"), TRUE, NULL);
- and_cond_ids [and_cond_size] = gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "o.order_key"),
- gda_sql_builder_add_param (b, 0, "okey", G_TYPE_INT, FALSE),
+ and_cond_ids [and_cond_size] = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "o.order_key"),
+ gda_sql_builder_add_param (b, "okey", G_TYPE_INT, FALSE),
0);
and_cond_size++;
}
- and_cond_ids [and_cond_size] = gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "fav.session"),
- gda_sql_builder_add_param (b, 0, "session", G_TYPE_INT, FALSE), 0);
+ and_cond_ids [and_cond_size] = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "fav.session"),
+ gda_sql_builder_add_param (b, "session", G_TYPE_INT, FALSE), 0);
and_cond_size++;
gint i;
@@ -831,22 +831,22 @@ browser_favorites_list (BrowserFavorites *bfav, guint session_id, BrowserFavorit
if (type & flag) {
gchar *str;
str = g_strdup_printf ("'%s'", favorite_type_to_string (flag));
- or_cond_ids [or_cond_size] = gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "fav.type"),
- gda_sql_builder_add_id (b, 0, str),
+ or_cond_ids [or_cond_size] = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "fav.type"),
+ gda_sql_builder_add_id (b, str),
0);
g_free (str);
or_cond_size++;
}
}
if (or_cond_size >= 1) {
- and_cond_ids [and_cond_size] = gda_sql_builder_add_cond_v (b, 0, GDA_SQL_OPERATOR_TYPE_OR,
+ and_cond_ids [and_cond_size] = gda_sql_builder_add_cond_v (b, GDA_SQL_OPERATOR_TYPE_OR,
or_cond_ids, or_cond_size);
and_cond_size++;
}
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond_v (b, 0, GDA_SQL_OPERATOR_TYPE_AND, and_cond_ids, and_cond_size));
+ gda_sql_builder_add_cond_v (b, GDA_SQL_OPERATOR_TYPE_AND, and_cond_ids, and_cond_size));
#ifdef GDA_DEBUG_NO
{
GdaSqlStatement *sqlst;
@@ -974,9 +974,9 @@ browser_favorites_delete (BrowserFavorites *bfav, guint session_id,
/* remove entry from favorites' list */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, FAVORITES_TABLE_NAME);
- gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "id"),
- gda_sql_builder_add_param (b, 0, "id", G_TYPE_INT, FALSE),
+ gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "id"),
+ gda_sql_builder_add_param (b, "id", G_TYPE_INT, FALSE),
0));
stmt = gda_sql_builder_get_statement (b, error);
@@ -996,9 +996,9 @@ browser_favorites_delete (BrowserFavorites *bfav, guint session_id,
/* remove entry from favorites' order */
b = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
gda_sql_builder_set_table (b, FAVORDER_TABLE_NAME);
- gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "fav_id"),
- gda_sql_builder_add_param (b, 0, "id", G_TYPE_INT, FALSE),
+ gda_sql_builder_set_where (b, gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "fav_id"),
+ gda_sql_builder_add_param (b, "id", G_TYPE_INT, FALSE),
0));
stmt = gda_sql_builder_get_statement (b, error);
@@ -1086,21 +1086,21 @@ browser_favorites_get (BrowserFavorites *bfav, gint fav_id,
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "id"), 0);
+ gda_sql_builder_add_id (b, "id"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "type"), 0);
+ gda_sql_builder_add_id (b, "type"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "name"), 0);
+ gda_sql_builder_add_id (b, "name"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "descr"), 0);
+ gda_sql_builder_add_id (b, "descr"), 0);
gda_sql_builder_add_field_id (b,
- gda_sql_builder_add_id (b, 0, "contents"), 0);
+ gda_sql_builder_add_id (b, "contents"), 0);
gda_sql_builder_select_add_target (b, FAVORITES_TABLE_NAME, NULL);
gda_sql_builder_set_where (b,
- gda_sql_builder_add_cond (b, 0, GDA_SQL_OPERATOR_TYPE_EQ,
- gda_sql_builder_add_id (b, 0, "id"),
- gda_sql_builder_add_param (b, 0, "id", G_TYPE_INT, FALSE), 0));
+ gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (b, "id"),
+ gda_sql_builder_add_param (b, "id", G_TYPE_INT, FALSE), 0));
stmt = gda_sql_builder_get_statement (b, error);
g_object_unref (G_OBJECT (b));
if (!stmt)
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index ae04b34..62227b8 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -401,7 +401,7 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
return FALSE;
}
gda_sql_builder_select_set_limit (b,
- gda_sql_builder_add_expr (b, 0, NULL,
+ gda_sql_builder_add_expr (b, NULL,
G_TYPE_INT, DEFAULT_DATA_SELECT_LIMIT),
0);
@@ -413,7 +413,7 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
if (mcol->pkey) {
/* ORDER BY */
gda_sql_builder_select_order_by (b,
- gda_sql_builder_add_id (b, 0,
+ gda_sql_builder_add_id (b,
mcol->column_name),
FALSE, NULL);
}
@@ -493,13 +493,13 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
GdaMetaTableColumn *col;
col = GDA_META_TABLE_COLUMN (g_slist_nth_data (mlinked->columns, fk->fk_cols_array [0]));
g_assert (col);
- gda_sql_builder_add_id (b, 1, fk->fk_names_array [0]);
+ const guint id1 = gda_sql_builder_add_id (b, fk->fk_names_array [0]);
tmp = g_strdup_printf ("%s %s", id ? (gchar*) id : (gchar*) fk_table,
fk->ref_pk_names_array [0]);
- gda_sql_builder_add_param (b, 2, tmp, col->gtype, FALSE);
+ const guint id2 = gda_sql_builder_add_param (b, tmp, col->gtype, FALSE);
g_free (tmp);
- gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_EQ, 1, 2, 0);
- gda_sql_builder_set_where (b, 3);
+ const guint id_cond = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ, id1, id2, 0);
+ gda_sql_builder_set_where (b, id_cond);
}
else {
TO_IMPLEMENT;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]