/*
* 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.
*
GdaSqlOperatorType op_expr;
- GdaSqlBuilderId id_expr;
+ GdaSqlBuilderId id_expr1;
+ GdaSqlBuilderId id_expr2;
GdaSqlBuilderId id_cond;
GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
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);
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,