]> saetta.ns0.it Git - libgdaex/commitdiff
Added GdaExSqlBuilder::from_v.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 26 Jun 2015 10:38:30 +0000 (12:38 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 26 Jun 2015 10:38:30 +0000 (12:38 +0200)
src/sqlbuilder.c
src/sqlbuilder.h
tests/sqlbuilder.c

index 3f558f19e38067c0a878c593f399ce87ace29f39..24a3a7088932963fc48cae84db7d401bb1df6147 100644 (file)
@@ -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,
index d7213c2f66baadfe114bed055d84341432057519..0ab758940bdf4a81fcafdcf15b0389eaa165e085 100644 (file)
@@ -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);
index f11837c4785531773c3fcb6a6bc0d7e77ee997ec..63dcd26532d1385895cf302a1a3918e527ea9b78 100644 (file)
@@ -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,