From 101b16bffbddb650608c43ff58534bcdb0763348 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Fri, 26 Jun 2015 12:38:30 +0200 Subject: [PATCH] Added GdaExSqlBuilder::from_v. --- src/sqlbuilder.c | 34 ++++++++++++++++++++++++++++++++-- src/sqlbuilder.h | 3 +++ tests/sqlbuilder.c | 8 ++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/sqlbuilder.c b/src/sqlbuilder.c index 3f558f1..24a3a70 100644 --- a/src/sqlbuilder.c +++ b/src/sqlbuilder.c @@ -103,7 +103,7 @@ GdaExSqlBuilder return gdaex_sql_builder; } -GdaExSqlBuilderField +static GdaExSqlBuilderField *gdaex_sql_builder_get_field (GdaExSqlBuilder *sqlb, GdaExSqlBuilderTable *table, const gchar *field_name, const gchar *field_alias, gboolean add) { GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb); @@ -130,7 +130,7 @@ GdaExSqlBuilderField return f; } -GdaExSqlBuilderTable +static GdaExSqlBuilderTable *gdaex_sql_builder_get_table (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *table_alias, gboolean add) { GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb); @@ -168,6 +168,36 @@ gdaex_sql_builder_from (GdaExSqlBuilder *sqlb, const gchar *table_name, const gc t = gdaex_sql_builder_get_table (sqlb, table_name, table_alias, TRUE); } +void +gdaex_sql_builder_from_v (GdaExSqlBuilder *sqlb, ...) +{ + va_list ap; + + GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb); + + va_start (ap, sqlb); + do + { + gchar *table_name = va_arg (ap, gchar *); + if (table_name != NULL) + { + gchar *table_alias = va_arg (ap, gchar *); + if (table_alias != NULL) + { + gdaex_sql_builder_from (sqlb, table_name, table_alias); + } + else + { + break; + } + } + else + { + break; + } + } while (TRUE); +} + void gdaex_sql_builder_join (GdaExSqlBuilder *sqlb, const gchar *table_name, diff --git a/src/sqlbuilder.h b/src/sqlbuilder.h index d7213c2..0ab7589 100644 --- a/src/sqlbuilder.h +++ b/src/sqlbuilder.h @@ -59,11 +59,14 @@ GType gdaex_sql_builder_get_type (void) G_GNUC_CONST; GdaExSqlBuilder *gdaex_sql_builder_new (GdaSqlStatementType stmt_type); void gdaex_sql_builder_from (GdaExSqlBuilder *sqlb, const gchar *table_name, const gchar *table_alias); +void gdaex_sql_builder_from_v (GdaExSqlBuilder *sqlb, ...); + void gdaex_sql_builder_join (GdaExSqlBuilder *sqlb, const gchar *table_name, GdaSqlSelectJoinType join_type, const gchar *table_name_right, ...); + void gdaex_sql_builder_fields (GdaExSqlBuilder *sqlb, ...); GdaSqlBuilder *gdaex_sql_builder_get_gda_sql_builder (GdaExSqlBuilder *sqlb); diff --git a/tests/sqlbuilder.c b/tests/sqlbuilder.c index f11837c..63dcd26 100644 --- a/tests/sqlbuilder.c +++ b/tests/sqlbuilder.c @@ -26,13 +26,17 @@ main (int argc, char **argv) gtk_init (&argc, &argv); sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT); - gdaex_sql_builder_from (sqlb, "pippo", "pluto"); + + gdaex_sql_builder_from_v (sqlb, + "pippo", "pluto", + "topolino", "", + NULL); + gdaex_sql_builder_fields (sqlb, "pippo", "id", "", "pippo", "name", "the_name", NULL); - gdaex_sql_builder_from (sqlb, "topolino", NULL); gdaex_sql_builder_join (sqlb, "pippo", GDA_SQL_SELECT_JOIN_INNER, "topolino", "pippo", "id", "", GDA_SQL_OPERATOR_TYPE_EQ, -- 2.49.0