[libgda] GdaSqlBuilder: Remove steal parameters.



commit 038913c0591fd60e9a2085ed7d5bad15bebfec89
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed May 12 12:33:06 2010 +0200

    GdaSqlBuilder: Remove steal parameters.
    
    * libgda/gda-sql-builder.[h|c]: gda_sql_builder_add_sub_select()
    and gda_sql_builder_compound_add_sub_select(): Remove the steal
    parameter, so these always copy instead.
    * samples/SqlBuilder/example.c: Adapt. Note that nothing ever passed
    FALSE to these functions so we are probably testing a new code path
    now.
    Note also that this causes more copying, but the right way to avoid
    that would be to use reference-counting by using real GObjects
    instead of just boxed type structs.

 libgda/gda-sql-builder.c     |   41 ++++++++++++++++-------------------------
 libgda/gda-sql-builder.h     |    5 ++---
 samples/SqlBuilder/example.c |   10 +++++-----
 3 files changed, 23 insertions(+), 33 deletions(-)
---
diff --git a/libgda/gda-sql-builder.c b/libgda/gda-sql-builder.c
index 4175da2..3391536 100644
--- a/libgda/gda-sql-builder.c
+++ b/libgda/gda-sql-builder.c
@@ -1577,7 +1577,7 @@ gda_sql_builder_add_function_v (GdaSqlBuilder *builder, guint id, const gchar *f
  * 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
+ * @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
  *
  * Adds an expression which is a subselect.
@@ -1587,7 +1587,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, gboolean steal)
+gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, guint id, GdaSqlStatement *sqlst)
 {
 	g_return_val_if_fail (GDA_IS_SQL_BUILDER (builder), 0);
 	g_return_val_if_fail (builder->priv->main_stmt, 0);
@@ -1597,23 +1597,18 @@ gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, guint id, GdaSqlStatemen
 
 	GdaSqlExpr *expr;
 	expr = gda_sql_expr_new (NULL);
-	if (steal) {
-		expr->select = sqlst->contents;
-		sqlst->contents = NULL;
-		gda_sql_statement_free (sqlst);
-	}
-	else {
-		switch (sqlst->stmt_type) {
-		case GDA_SQL_STATEMENT_SELECT:
-			expr->select = _gda_sql_statement_select_copy (sqlst->contents);
-			break;
-		case GDA_SQL_STATEMENT_COMPOUND:
-			expr->select = _gda_sql_statement_compound_copy (sqlst->contents);
-			break;
-		default:
-			g_assert_not_reached ();
-		}
+
+	switch (sqlst->stmt_type) {
+	case GDA_SQL_STATEMENT_SELECT:
+		expr->select = _gda_sql_statement_select_copy (sqlst->contents);
+		break;
+	case GDA_SQL_STATEMENT_COMPOUND:
+		expr->select = _gda_sql_statement_compound_copy (sqlst->contents);
+		break;
+	default:
+		g_assert_not_reached ();
 	}
+
 	GDA_SQL_ANY_PART (expr->select)->parent = GDA_SQL_ANY_PART (expr);
 
 	return add_part (builder, id, (GdaSqlAnyPart *) expr);
@@ -1646,15 +1641,14 @@ gda_sql_builder_compound_set_type (GdaSqlBuilder *builder, GdaSqlStatementCompou
 /**
  * gda_sql_builder_compound_add_sub_select
  * @builder: a #GdaSqlBuilder object
- * @sqlst: a pointer to a #GdaSqlStatement, which has to be a SELECT or compound SELECT
- * @steal: if %TRUE, then @sqlst will be "stolen" by @b and should not be used anymore
+ * @sqlst: a pointer to a #GdaSqlStatement, which has to be a SELECT or compound SELECT. This will be copied.
  *
  * Add a sub select to a COMPOUND statement
  *
  * Since: 4.2
  */
 void
-gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement *sqlst, gboolean steal)
+gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement *sqlst)
 {
 	GdaSqlStatementCompound *cstmt;
 	GdaSqlStatement *sub;
@@ -1670,10 +1664,7 @@ gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement
 			  (sqlst->stmt_type == GDA_SQL_STATEMENT_COMPOUND));
 
 	cstmt = (GdaSqlStatementCompound*) builder->priv->main_stmt->contents;
-	if (steal)
-		sub = sqlst;
-	else
-		sub = gda_sql_statement_copy (sqlst);
+	sub = gda_sql_statement_copy (sqlst);
 
 	cstmt->stmt_list = g_slist_append (cstmt->stmt_list, sub);
 }
diff --git a/libgda/gda-sql-builder.h b/libgda/gda-sql-builder.h
index 3009d4e..0904db1 100644
--- a/libgda/gda-sql-builder.h
+++ b/libgda/gda-sql-builder.h
@@ -84,8 +84,7 @@ guint             gda_sql_builder_add_cond_v (GdaSqlBuilder *builder, guint id,
 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,
 						  const guint *args, gint args_size);
-guint             gda_sql_builder_add_sub_select (GdaSqlBuilder *builder, guint id, GdaSqlStatement *sqlst,
-						  gboolean steal);
+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,
@@ -126,7 +125,7 @@ void              gda_sql_builder_select_group_by (GdaSqlBuilder *builder, guint
 
 /* COMPOUND SELECT Statement API */
 void              gda_sql_builder_compound_set_type (GdaSqlBuilder *builder, GdaSqlStatementCompoundType compound_type);
-void              gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement *sqlst, gboolean steal);
+void              gda_sql_builder_compound_add_sub_select (GdaSqlBuilder *builder, GdaSqlStatement *sqlst);
 
 /* import/Export API */
 GdaSqlExpr       *gda_sql_builder_export_expression (GdaSqlBuilder *builder, guint id);
diff --git a/samples/SqlBuilder/example.c b/samples/SqlBuilder/example.c
index 4bdb3fe..0e4d9f0 100644
--- a/samples/SqlBuilder/example.c
+++ b/samples/SqlBuilder/example.c
@@ -162,7 +162,7 @@ main (int argc, char *argv[])
 					   gda_sql_builder_add_id (b, 0, "master"),
 					   NULL);
 	gda_sql_builder_add_id (b, 1, "id");
-	gda_sql_builder_add_sub_select (b, 2, sub, TRUE);
+	gda_sql_builder_add_sub_select (b, 2, sub);
 	gda_sql_builder_add_cond (b, 3, GDA_SQL_OPERATOR_TYPE_IN, 1, 2, 0);
 	gda_sql_builder_set_where (b, 3);
 	render_as_sql (b);
@@ -188,7 +188,7 @@ main (int argc, char *argv[])
 					   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, TRUE), 0);
+	gda_sql_builder_add_field_id (b, gda_sql_builder_add_sub_select (b, 0, sub), 0);
 
 	render_as_sql (b);
 	g_object_unref (b);
@@ -210,7 +210,7 @@ main (int argc, char *argv[])
 	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_sub_select (b, 0, sub), 0);
 	
 	render_as_sql (b);
 	g_object_unref (b);
@@ -237,8 +237,8 @@ main (int argc, char *argv[])
 	g_object_unref (b);
 
 	b = gda_sql_builder_new (GDA_SQL_STATEMENT_COMPOUND);
-	gda_sql_builder_compound_add_sub_select (b, sub1, TRUE);
-	gda_sql_builder_compound_add_sub_select (b, sub2, TRUE);
+	gda_sql_builder_compound_add_sub_select (b, sub1);
+	gda_sql_builder_compound_add_sub_select (b, sub2);
 	render_as_sql (b);
 	g_object_unref (b);
 



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