]> saetta.ns0.it Git - libgdaex/commitdiff
Added function GdaExSqlBuilder::where_string.
authorAndrea Zagli <azagli@libero.it>
Wed, 2 Oct 2019 13:33:00 +0000 (15:33 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 3 Oct 2019 13:33:56 +0000 (15:33 +0200)
src/sqlbuilder.c
src/sqlbuilder.h
tests/sqlbuilder.c

index fb813067f02f06488a9acdf6555195c8080c6a4b..0af320f70e432aa980d0144a430769c8f56f0efa 100644 (file)
@@ -590,6 +590,36 @@ gdaex_sql_builder_where_int (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
        return id;
 }
 
+GdaSqlBuilderId
+gdaex_sql_builder_where_string (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
+                                const gchar *table_name,
+                                const gchar *field_name,
+                                const gchar *field_alias,
+                                GdaSqlOperatorType where_op,
+                                gchar *op1,
+                                gchar *op2)
+{
+       GValue *val1;
+       GValue *val2;
+
+       GdaSqlBuilderId id;
+
+       val1 = g_new0 (GValue, 1);
+       g_value_init (val1, G_TYPE_STRING);
+       g_value_set_string (val1, op1);
+
+       val2 = g_new0 (GValue, 1);
+       g_value_init (val2, G_TYPE_STRING);
+       g_value_set_string (val2, op2);
+
+       id = gdaex_sql_builder_where (sqlb, op, table_name, field_name, field_alias, where_op, val1, val2, NULL);
+
+       g_value_unset (val1);
+       g_value_unset (val2);
+
+       return id;
+}
+
 /**
  * gdaex_sql_builder_order:
  * @sqlb:
index 2645700b1bf070de83fe37a7018d17ce5c694787..b21066407f8288d6b5f6ab761bb37547130069b9 100644 (file)
@@ -77,6 +77,13 @@ GdaSqlBuilderId gdaex_sql_builder_where_int (GdaExSqlBuilder *sqlb, GdaSqlOperat
                                              GdaSqlOperatorType where_op,
                                              gint op1,
                                              gint op2);
+GdaSqlBuilderId gdaex_sql_builder_where_string (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
+                                                const gchar *table_name,
+                                                const gchar *field_name,
+                                                const gchar *field_alias,
+                                                GdaSqlOperatorType where_op,
+                                                gchar *op1,
+                                                gchar *op2);
 
 void gdaex_sql_builder_order (GdaExSqlBuilder *sqlb, ...);
 
index 7c2604dc138937a952bcbb738fdcb00e302122df..1e5de7a113a2b5ad8bf814fa112de80819e44e06 100644 (file)
@@ -73,6 +73,43 @@ main (int argc, char **argv)
 
        g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb, NULL, NULL));
 
+       sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
+
+       gdaex_sql_builder_from_v (sqlb,
+                                 "pippo", "pluto",
+                                 "topolino", "",
+                                 NULL);
+
+       gdaex_sql_builder_fields (sqlb,
+                                 "pippo", "id", "", NULL,
+                                 "pippo", "name", "the_name", NULL,
+                                 NULL);
+
+       gdaex_sql_builder_field (sqlb, "pippo", "income", NULL, NULL);
+
+       gdaex_sql_builder_join (sqlb, GDA_SQL_SELECT_JOIN_INNER,
+                               "pippo", "id", "",
+                               GDA_SQL_OPERATOR_TYPE_EQ,
+                               "topolino", "id_pippo", "",
+                               NULL);
+
+       gdaex_sql_builder_where_int (sqlb, 0,
+                                    "pippo", "id", "",
+                                    GDA_SQL_OPERATOR_TYPE_EQ,
+                                    44, 0);
+
+       gdaex_sql_builder_where_string (sqlb, GDA_SQL_OPERATOR_TYPE_OR,
+                                "pippo", "name", "",
+                                GDA_SQL_OPERATOR_TYPE_DIFF,
+                                "ichichc", NULL);
+
+       gdaex_sql_builder_order (sqlb,
+                                "pippo", "name", "", TRUE,
+                                "pippo", "id", "", FALSE,
+                                NULL);
+
+       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb, NULL, NULL));
+
        g_object_unref (sqlb);
 
        sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT);