]> saetta.ns0.it Git - libgdaex/commitdiff
SqlBuilder: enabled number of arguments different from 2.
authorAndrea Zagli <andrea.zagli@email.it>
Sun, 21 Feb 2016 16:20:48 +0000 (17:20 +0100)
committerAndrea Zagli <andrea.zagli@email.it>
Sun, 21 Feb 2016 16:20:48 +0000 (17:20 +0100)
src/sqlbuilder.c
tests/sqlbuilder.c

index 180a4556af4b38e37ba8e2f15b68dda23a623389..939ca36a87086889db2f66cea6fa5ec945a2f009 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  sql_builder.c
  *
- *  Copyright (C) 2010-2014 Andrea Zagli <azagli@libero.it>
+ *  Copyright (C) 2010-2016 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libgdaex.
  *
@@ -445,7 +445,8 @@ gdaex_sql_builder_where (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op, ...)
 
        GdaSqlOperatorType op_expr;
 
-       GdaSqlBuilderId id_expr;
+       GdaSqlBuilderId id_expr1;
+       GdaSqlBuilderId id_expr2;
        GdaSqlBuilderId id_cond;
 
        GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
@@ -487,17 +488,56 @@ gdaex_sql_builder_where (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op, ...)
 
                        op_expr = va_arg (ap, guint);
 
-                       gval = va_arg (ap, GValue *);
-                       if (gval != NULL)
-                               {
-                                       id_expr = gda_sql_builder_add_expr_value (priv->sqlb, NULL, gval);
-                               }
-                       else
+                       id_expr1 = 0;
+                       id_expr2 = 0;
+                       switch (op_expr)
                                {
+                               case GDA_SQL_OPERATOR_TYPE_EQ:
+                               case GDA_SQL_OPERATOR_TYPE_IS:
+                               case GDA_SQL_OPERATOR_TYPE_LIKE:
+                               case GDA_SQL_OPERATOR_TYPE_NOTLIKE:
+                               case GDA_SQL_OPERATOR_TYPE_ILIKE:
+                               case GDA_SQL_OPERATOR_TYPE_NOTILIKE:
+                               case GDA_SQL_OPERATOR_TYPE_GT:
+                               case GDA_SQL_OPERATOR_TYPE_LT:
+                               case GDA_SQL_OPERATOR_TYPE_GEQ:
+                               case GDA_SQL_OPERATOR_TYPE_LEQ:
+                               case GDA_SQL_OPERATOR_TYPE_DIFF:
+                               case GDA_SQL_OPERATOR_TYPE_REGEXP:
+                               case GDA_SQL_OPERATOR_TYPE_REGEXP_CI:
+                               case GDA_SQL_OPERATOR_TYPE_NOT_REGEXP:
+                               case GDA_SQL_OPERATOR_TYPE_NOT_REGEXP_CI:
+                               case GDA_SQL_OPERATOR_TYPE_SIMILAR:
+                               case GDA_SQL_OPERATOR_TYPE_REM:
+                               case GDA_SQL_OPERATOR_TYPE_DIV:
+                               case GDA_SQL_OPERATOR_TYPE_BITAND:
+                               case GDA_SQL_OPERATOR_TYPE_BITOR:
+                                       gval = va_arg (ap, GValue *);
+                                       if (gval != NULL)
+                                               {
+                                                       id_expr1 = gda_sql_builder_add_expr_value (priv->sqlb, NULL, gval);
+                                               }
+                                       break;
+
+                               case GDA_SQL_OPERATOR_TYPE_ISNULL:
+                               case GDA_SQL_OPERATOR_TYPE_ISNOTNULL:
+                                       break;
+
+                               case GDA_SQL_OPERATOR_TYPE_BETWEEN:
+                                       gval = va_arg (ap, GValue *);
+                                       if (gval != NULL)
+                                               {
+                                                       id_expr1 = gda_sql_builder_add_expr_value (priv->sqlb, NULL, gval);
+                                               }
+                                       gval = va_arg (ap, GValue *);
+                                       if (gval != NULL)
+                                               {
+                                                       id_expr2 = gda_sql_builder_add_expr_value (priv->sqlb, NULL, gval);
+                                               }
                                        break;
                                }
 
-                       id_cond = gda_sql_builder_add_cond (priv->sqlb, op_expr, f->id, id_expr, 0);
+                       id_cond = gda_sql_builder_add_cond (priv->sqlb, op_expr, f->id, id_expr1, id_expr2);
                        if (priv->id_where != 0)
                                {
                                        priv->id_where = gda_sql_builder_add_cond (priv->sqlb, op, priv->id_where, id_cond, 0);
index e12c22989e6e5d30c6058f1539d437501e9fed91..2a29520547fffe397d8cc7a86140594d2a334f12 100644 (file)
@@ -75,6 +75,43 @@ main (int argc, char **argv)
 
        g_object_unref (sqlb);
 
+       sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
+
+       gdaex_sql_builder_from (sqlb, "pippo", "");
+
+       gdaex_sql_builder_fields (sqlb,
+                                                         "pippo", "id", "", NULL,
+                                                         "pippo", "name", "the_name", NULL,
+                                                         NULL);
+
+       gval = g_new0 (GValue, 1);
+       g_value_init (gval, G_TYPE_INT);
+       g_value_set_int (gval, 44);
+       gdaex_sql_builder_where (sqlb, 0,
+                                                        "pippo", "id", "",
+                                                        GDA_SQL_OPERATOR_TYPE_ISNULL,
+                                                        gval,
+                                                        NULL);
+       g_value_unset (gval);
+
+       gval = g_new0 (GValue, 1);
+       g_value_init (gval, G_TYPE_INT);
+       g_value_set_int (gval, 44);
+       GValue *gval2 = g_new0 (GValue, 1);
+       g_value_init (gval2, G_TYPE_INT);
+       g_value_set_int (gval2, 8877);
+       gdaex_sql_builder_where (sqlb, 0,
+                                                        "pippo", "id", "",
+                                                        GDA_SQL_OPERATOR_TYPE_BETWEEN,
+                                                        gval, gval2,
+                                                        NULL);
+       g_value_unset (gval);
+       g_value_unset (gval2);
+
+       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb, NULL, NULL));
+
+       g_object_unref (sqlb);
+
        sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
 
        gdaex_sql_builder_from_v (sqlb,