/*
- * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2018 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
GValue *value;
+ gchar *str;
+
+ GString *where;
+
ZakFormGdaexProviderPrivate *priv = ZAK_FORM_GDAEX_PROVIDER_GET_PRIVATE (provider);
sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
"",
NULL);
+ where = g_string_new ("");
+
for (i = 0; i < elements->len; i++)
{
ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
ZakFormGdaExElementExtension *extension = (ZakFormGdaExElementExtension *)g_ptr_array_index (extensions, l);
- table = zak_form_gdaex_element_extension_get_where_table (extension);
- table_alias = zak_form_gdaex_element_extension_get_where_table_alias (extension);
- field = zak_form_gdaex_element_extension_get_where_field (extension);
- field_alias = zak_form_gdaex_element_extension_get_where_field_alias (extension);
- type = zak_form_gdaex_element_extension_get_where_type (extension);
-
- if (table != NULL)
- {
- gdaex_sql_builder_from (sqlb, table, table_alias == NULL ? "" : table_alias);
- }
-
- if (type == GDA_SQL_OPERATOR_TYPE_LIKE
- || type == GDA_SQL_OPERATOR_TYPE_ILIKE
- || type == GDA_SQL_OPERATOR_TYPE_NOTLIKE
- || type == GDA_SQL_OPERATOR_TYPE_NOTILIKE)
+ str = zak_form_gdaex_element_extension_get_str (extension);
+ if (str == NULL)
{
- gchar *str;
- gint like_type;
-
- str = g_value_dup_string (value);
+ table = zak_form_gdaex_element_extension_get_where_table (extension);
+ table_alias = zak_form_gdaex_element_extension_get_where_table_alias (extension);
+ field = zak_form_gdaex_element_extension_get_where_field (extension);
+ field_alias = zak_form_gdaex_element_extension_get_where_field_alias (extension);
+ type = zak_form_gdaex_element_extension_get_where_type (extension);
- like_type = zak_form_gdaex_element_extension_get_where_like_type (extension);
- if (like_type < 0)
+ if (table != NULL)
{
- g_value_set_string (value, g_strdup_printf ("%%%s", str));
+ gdaex_sql_builder_from (sqlb, table, table_alias == NULL ? "" : table_alias);
}
- else if (like_type > 0)
+
+ if (type == GDA_SQL_OPERATOR_TYPE_LIKE
+ || type == GDA_SQL_OPERATOR_TYPE_ILIKE
+ || type == GDA_SQL_OPERATOR_TYPE_NOTLIKE
+ || type == GDA_SQL_OPERATOR_TYPE_NOTILIKE)
{
- g_value_set_string (value, g_strdup_printf ("%s%%", str));
+ gint like_type;
+
+ str = g_value_dup_string (value);
+
+ like_type = zak_form_gdaex_element_extension_get_where_like_type (extension);
+ if (like_type < 0)
+ {
+ g_value_set_string (value, g_strdup_printf ("%%%s", str));
+ }
+ else if (like_type > 0)
+ {
+ g_value_set_string (value, g_strdup_printf ("%s%%", str));
+ }
+ else
+ {
+ g_value_set_string (value, g_strdup_printf ("%%%s%%", str));
+ }
}
- else
+
+ gdaex_sql_builder_where (sqlb,
+ 0,
+ table == NULL ? priv->table : table,
+ field == NULL ? zak_form_element_get_name (element) : field,
+ field_alias == NULL ? "" : field_alias,
+ type,
+ value,
+ NULL);
+ }
+ else
+ {
+ if (g_strcmp0 (str, "") != 0
+ && g_strcmp0 (str, g_value_get_string (value)) == 0)
{
- g_value_set_string (value, g_strdup_printf ("%%%s%%", str));
+ g_string_append_printf (where, "%s%s", where->len > 0 ? " AND " : "", str);
+ g_free (str);
}
}
-
- gdaex_sql_builder_where (sqlb,
- 0,
- table == NULL ? priv->table : table,
- field == NULL ? zak_form_element_get_name (element) : field,
- field_alias == NULL ? "" : field_alias,
- type,
- value,
- NULL);
}
g_value_unset (value);
}
- return gdaex_sql_builder_get_sql_where (sqlb, (GdaConnection *)gdaex_get_gdaconnection (priv->gdaex), NULL);
+ str = gdaex_sql_builder_get_sql_where (sqlb, (GdaConnection *)gdaex_get_gdaconnection (priv->gdaex), NULL);
+ if (str != NULL)
+ {
+ if (where->len > 0)
+ {
+ g_string_prepend (where, " AND ");
+ }
+ g_string_prepend (where, str);
+
+ g_free (str);
+ }
+
+ /* str = g_strconcat (gdaex_sql_builder_get_sql_where (sqlb, (GdaConnection *)gdaex_get_gdaconnection (priv->gdaex), NULL) != NULL ? gdaex_sql_builder_get_sql_where (sqlb, (GdaConnection *)gdaex_get_gdaconnection (priv->gdaex), NULL) : "", */
+ /* gdaex_sql_builder_get_sql_where (sqlb, (GdaConnection *)gdaex_get_gdaconnection (priv->gdaex), NULL) != NULL && g_strcmp0 (gdaex_sql_builder_get_sql_where (sqlb, (GdaConnection *)gdaex_get_gdaconnection (priv->gdaex), NULL), "") != 0 && where->len > 0 ? " AND " : "", */
+ /* where->str, */
+ /* NULL); */
+
+ str = g_strdup (where->str);
+ g_string_free (where, TRUE);
+
+ return str;
}
/* PRIVATE */
/*
- * Copyright (C) 2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2017-2018 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
gchar *field_alias;
GdaSqlOperatorType type;
gint like_type;
+ gchar *str;
} ZakFormGdaExElementExtensionPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (ZakFormGdaExElementExtension, zak_form_gdaex_element_extension, ZAK_FORM_TYPE_ELEMENT_EXTENSION)
priv->field_alias = NULL;
priv->type = 0;
priv->like_type = 0;
+ priv->str = NULL;
}
ZakFormElementExtension
{
if (g_strcmp0 ((gchar *)xnodetmp->name, "where") == 0)
{
- zak_form_gdaex_element_extension_set_where_table ((ZakFormGdaExElementExtension *)extension,
- (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"table"));
- zak_form_gdaex_element_extension_set_where_table_alias ((ZakFormGdaExElementExtension *)extension,
- (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"table_alias"));
-
- zak_form_gdaex_element_extension_set_where_field ((ZakFormGdaExElementExtension *)extension,
- (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"field"));
- zak_form_gdaex_element_extension_set_where_field_alias ((ZakFormGdaExElementExtension *)extension,
- (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"field_alias"));
-
- prop = xmlGetProp (xnodetmp, (const xmlChar *)"type");
- if (g_strcmp0 (prop, "lt") == 0)
+ if (g_strcmp0 ((gchar *)xmlNodeGetContent (xnodetmp), "") == 0)
{
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_LT);
- }
- else if (g_strcmp0 (prop, "let") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_LEQ);
- }
- else if (g_strcmp0 (prop, "e") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_EQ);
- }
- else if (g_strcmp0 (prop, "ne") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_DIFF);
- }
- else if (g_strcmp0 (prop, "gt") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_GT);
- }
- else if (g_strcmp0 (prop, "get") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_GEQ);
- }
- else if (g_strcmp0 (prop, "like") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_LIKE);
- }
- else if (g_strcmp0 (prop, "nlike") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_NOTLIKE);
- }
- else if (g_strcmp0 (prop, "ilike") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_ILIKE);
- }
- else if (g_strcmp0 (prop, "nilike") == 0)
- {
- zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
- GDA_SQL_OPERATOR_TYPE_NOTILIKE);
- }
-
- if (g_strcmp0 (prop, "like") == 0
- || g_strcmp0 (prop, "nlike") == 0
- || g_strcmp0 (prop, "ilike") == 0
- || g_strcmp0 (prop, "nilike") == 0)
- {
- prop = xmlGetProp (xnodetmp, (const xmlChar *)"like");
- if (g_strcmp0 (prop, "start") == 0)
+ zak_form_gdaex_element_extension_set_where_table ((ZakFormGdaExElementExtension *)extension,
+ (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"table"));
+ zak_form_gdaex_element_extension_set_where_table_alias ((ZakFormGdaExElementExtension *)extension,
+ (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"table_alias"));
+
+ zak_form_gdaex_element_extension_set_where_field ((ZakFormGdaExElementExtension *)extension,
+ (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"field"));
+ zak_form_gdaex_element_extension_set_where_field_alias ((ZakFormGdaExElementExtension *)extension,
+ (const gchar *)xmlGetProp (xnodetmp, (const xmlChar *)"field_alias"));
+
+ prop = xmlGetProp (xnodetmp, (const xmlChar *)"type");
+ if (g_strcmp0 (prop, "lt") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_LT);
+ }
+ else if (g_strcmp0 (prop, "let") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_LEQ);
+ }
+ else if (g_strcmp0 (prop, "e") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_EQ);
+ }
+ else if (g_strcmp0 (prop, "ne") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_DIFF);
+ }
+ else if (g_strcmp0 (prop, "gt") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_GT);
+ }
+ else if (g_strcmp0 (prop, "get") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_GEQ);
+ }
+ else if (g_strcmp0 (prop, "like") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_LIKE);
+ }
+ else if (g_strcmp0 (prop, "nlike") == 0)
{
- zak_form_gdaex_element_extension_set_where_like_type ((ZakFormGdaExElementExtension *)extension, -1);
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_NOTLIKE);
}
- else if (g_strcmp0 (prop, "end") == 0)
+ else if (g_strcmp0 (prop, "ilike") == 0)
{
- zak_form_gdaex_element_extension_set_where_like_type ((ZakFormGdaExElementExtension *)extension, 1);
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_ILIKE);
}
- else
+ else if (g_strcmp0 (prop, "nilike") == 0)
{
- zak_form_gdaex_element_extension_set_where_like_type ((ZakFormGdaExElementExtension *)extension, 0);
+ zak_form_gdaex_element_extension_set_where_type ((ZakFormGdaExElementExtension *)extension,
+ GDA_SQL_OPERATOR_TYPE_NOTILIKE);
}
+
+ if (g_strcmp0 (prop, "like") == 0
+ || g_strcmp0 (prop, "nlike") == 0
+ || g_strcmp0 (prop, "ilike") == 0
+ || g_strcmp0 (prop, "nilike") == 0)
+ {
+ prop = xmlGetProp (xnodetmp, (const xmlChar *)"like");
+ if (g_strcmp0 (prop, "start") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_like_type ((ZakFormGdaExElementExtension *)extension, -1);
+ }
+ else if (g_strcmp0 (prop, "end") == 0)
+ {
+ zak_form_gdaex_element_extension_set_where_like_type ((ZakFormGdaExElementExtension *)extension, 1);
+ }
+ else
+ {
+ zak_form_gdaex_element_extension_set_where_like_type ((ZakFormGdaExElementExtension *)extension, 0);
+ }
+ }
+
+ zak_form_gdaex_element_extension_set_str ((ZakFormGdaExElementExtension *)extension, NULL);
+ }
+ else
+ {
+ zak_form_gdaex_element_extension_set_str ((ZakFormGdaExElementExtension *)extension, (gchar *)xmlNodeGetContent (xnodetmp));
}
}
priv->like_type = type;
}
+/**
+ * zak_form_gdaex_element_extension_get_str:
+ * @extension:
+ *
+ * Returns: the where string.
+ */
+gchar
+*zak_form_gdaex_element_extension_get_str (ZakFormGdaExElementExtension *extension)
+{
+ ZakFormGdaExElementExtensionPrivate *priv = zak_form_gdaex_element_extension_get_instance_private (extension);
+
+ if (priv->str != NULL)
+ {
+ return g_strdup (priv->str);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/**
+ * zak_form_gdaex_element_extension_set_str:
+ * @extension:
+ * @str:
+ */
+void
+zak_form_gdaex_element_extension_set_str (ZakFormGdaExElementExtension *extension, const gchar *str)
+{
+ ZakFormGdaExElementExtensionPrivate *priv = zak_form_gdaex_element_extension_get_instance_private (extension);
+
+ if (str == NULL)
+ {
+ if (priv->str != NULL)
+ {
+ g_free (priv->str);
+ }
+ priv->str = NULL;
+ }
+ else
+ {
+ priv->str = g_strdup (str);
+ }
+}
+
/* PRIVATE */
static void
zak_form_gdaex_element_extension_set_property (GObject *object,