* Copyright (C) 2010-2014 Andrea Zagli <azagli@libero.it>
*
* This file is part of libgdaex.
- *
+ *
* libgdaex_sql_builder is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* libgdaex_sql_builder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with libgdaex; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
}
g_hash_table_insert (table->ht_fields, g_strdup (field_name), f);
}
-
+
return f;
}
gchar *table_name;
gchar *table_alias;
-
+
GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
va_start (ap, sqlb);
gchar *tmp;
GdaSqlOperatorType op;
-
+
GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
if (priv->stmt_type != GDA_SQL_STATEMENT_SELECT) return;
field_table_name_right = NULL;
field_name_right = NULL;
field_alias_right = NULL;
-
+
field_table_name_left = va_arg (ap, gchar *);
if (field_table_name_left != NULL)
{
}
op = va_arg (ap, guint);
-
+
field_table_name_right = va_arg (ap, gchar *);
if (field_table_name_right != NULL)
{
GValue *gval;
GdaExSqlBuilderTable *t;
-
+
GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
va_start (ap, sqlb);
field_name = NULL;
field_alias = NULL;
gval = NULL;
-
+
table_name = va_arg (ap, gchar *);
if (table_name != NULL)
{
if (field_alias != NULL)
{
gval = va_arg (ap, GValue *);
-
+
t = gdaex_sql_builder_get_table (sqlb, table_name, NULL, TRUE);
gdaex_sql_builder_get_field (sqlb, t, field_name, field_alias, gval, TRUE);
}
GdaSqlBuilderId id_expr;
GdaSqlBuilderId id_cond;
-
+
GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
if (priv->stmt_type == GDA_SQL_STATEMENT_INSERT)
{
return;
}
-
+
va_start (ap, op);
do
{
}
op_expr = va_arg (ap, guint);
-
+
gval = va_arg (ap, GValue *);
if (gval != NULL)
{
return priv->id_where;
}
+/**
+ * gdaex_sql_builder_order:
+ * @sqlb:
+ * @...:
+ */
+void
+gdaex_sql_builder_order (GdaExSqlBuilder *sqlb, ...)
+{
+ va_list ap;
+
+ gchar *table_name;
+ gchar *field_name;
+ gchar *field_alias;
+ gboolean asc;
+
+ GdaExSqlBuilderTable *t;
+ GdaExSqlBuilderField *f;
+
+ GdaExSqlBuilderPrivate *priv = GDAEX_SQLBUILDER_GET_PRIVATE (sqlb);
+
+ va_start (ap, sqlb);
+ do
+ {
+ table_name = NULL;
+ field_name = NULL;
+ field_alias = NULL;
+
+ table_name = va_arg (ap, gchar *);
+ if (table_name != NULL)
+ {
+ field_name = va_arg (ap, gchar *);
+ if (field_name != NULL)
+ {
+ field_alias = va_arg (ap, gchar *);
+ if (field_alias != NULL)
+ {
+ asc = va_arg (ap, gboolean);
+
+ t = gdaex_sql_builder_get_table (sqlb, table_name, NULL, TRUE);
+ f = gdaex_sql_builder_get_field (sqlb, t, field_name, field_alias, NULL, TRUE);
+ gda_sql_builder_select_order_by (priv->sqlb, f->id, asc, NULL);
+ }
+ else
+ {
+ break;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ else
+ {
+ break;
+ }
+ } while (TRUE);
+ va_end (ap);
+}
+
/**
* gaex_sql_builder_get_gda_sql_builder:
* @sqlb:
* Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
*
* This file is part of libgdaex.
- *
+ *
* libgdaex is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* libgdaex is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with libgdaex; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
*/
#ifndef __GDAEX_SQL_BUILDER_H__
GdaSqlBuilderId gdaex_sql_builder_where (GdaExSqlBuilder *sqln, GdaSqlOperatorType op,
...);
+void gdaex_sql_builder_order (GdaExSqlBuilder *sqlb, ...);
+
GdaSqlBuilder *gdaex_sql_builder_get_gda_sql_builder (GdaExSqlBuilder *sqlb);
const gchar *gdaex_sql_builder_get_sql (GdaExSqlBuilder *sqlb, GdaConnection *cnc, GdaSet *params);
"pippo", "id", "", NULL,
"pippo", "name", "the_name", NULL,
NULL);
-
+
gdaex_sql_builder_join (sqlb, GDA_SQL_SELECT_JOIN_INNER,
"pippo", "id", "",
GDA_SQL_OPERATOR_TYPE_EQ,
gval,
NULL);
g_value_unset (gval);
-
+
gval = g_new0 (GValue, 1);
g_value_init (gval, G_TYPE_STRING);
g_value_set_string (gval, "ichichc");
NULL);
g_value_unset (gval);
+ 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);
"pippo", "pluto",
"topolino", "",
NULL);
-
+
gval = g_new0 (GValue, 1);
g_value_init (gval, G_TYPE_INT);
g_value_set_int (gval, 1);
g_value_set_string (gval, "il nome di pippo");
gdaex_sql_builder_fields (sqlb,
"pippo", "name", "", gval,
- NULL);
-
+ NULL);
+
gval = g_new0 (GValue, 1);
g_value_init (gval, G_TYPE_INT);
g_value_set_int (gval, 1);
g_value_set_string (gval, "il nome di pippo");
gdaex_sql_builder_fields (sqlb,
"pippo", "name", "", gval,
- NULL);
-
+ NULL);
+
gval = g_new0 (GValue, 1);
g_value_init (gval, G_TYPE_INT);
g_value_set_int (gval, 1);