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

index e37c840d653d0078513ce98837427615131e0799..fb813067f02f06488a9acdf6555195c8080c6a4b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  sql_builder.c
  *
- *  Copyright (C) 2010-2016 Andrea Zagli <azagli@libero.it>
+ *  Copyright (C) 2010-2019 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libgdaex.
  *
@@ -560,6 +560,36 @@ gdaex_sql_builder_where (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op, ...)
        return priv->id_where;
 }
 
+GdaSqlBuilderId
+gdaex_sql_builder_where_int (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
+                             const gchar *table_name,
+                             const gchar *field_name,
+                             const gchar *field_alias,
+                             GdaSqlOperatorType where_op,
+                             gint op1,
+                             gint op2)
+{
+       GValue *val1;
+       GValue *val2;
+
+       GdaSqlBuilderId id;
+
+       val1 = g_new0 (GValue, 1);
+       g_value_init (val1, G_TYPE_INT);
+       g_value_set_int (val1, op1);
+
+       val2 = g_new0 (GValue, 1);
+       g_value_init (val2, G_TYPE_INT);
+       g_value_set_int (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 af3343c93ae6c85f7f13f64e162ba8a3c3f4df44..2645700b1bf070de83fe37a7018d17ce5c694787 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  sqlbuilder.h
  *
- *  Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
+ *  Copyright (C) 2015-2019 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libgdaex.
  *
@@ -70,6 +70,13 @@ void gdaex_sql_builder_fields (GdaExSqlBuilder *sqlb, ...);
 
 GdaSqlBuilderId gdaex_sql_builder_where (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
                                                                                 ...);
+GdaSqlBuilderId gdaex_sql_builder_where_int (GdaExSqlBuilder *sqlb, GdaSqlOperatorType op,
+                                             const gchar *table_name,
+                                             const gchar *field_name,
+                                             const gchar *field_alias,
+                                             GdaSqlOperatorType where_op,
+                                             gint op1,
+                                             gint op2);
 
 void gdaex_sql_builder_order (GdaExSqlBuilder *sqlb, ...);
 
index 2a29520547fffe397d8cc7a86140594d2a334f12..7c2604dc138937a952bcbb738fdcb00e302122df 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2019 Andrea Zagli <azagli@libero.it>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -133,6 +133,27 @@ main (int argc, char **argv)
 
        g_object_unref (sqlb);
 
+       sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
+
+       gdaex_sql_builder_from_v (sqlb,
+                                 "pippo", "pluto",
+                                 "topolino", "",
+                                 NULL);
+
+       gdaex_sql_builder_where_int (sqlb, 0,
+                                    "pippo", "id", "",
+                                    GDA_SQL_OPERATOR_TYPE_EQ,
+                                    1, 0);
+
+       gdaex_sql_builder_where_int (sqlb, GDA_SQL_OPERATOR_TYPE_OR,
+                                    "pippo", "id", "",
+                                    GDA_SQL_OPERATOR_TYPE_BETWEEN,
+                                    1, 99);
+
+       g_message ("sql: %s", gdaex_sql_builder_get_sql (sqlb, NULL, NULL));
+
+       g_object_unref (sqlb);
+
        sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_UPDATE);
 
        gdaex_sql_builder_from_v (sqlb,
@@ -146,6 +167,7 @@ main (int argc, char **argv)
        gdaex_sql_builder_fields (sqlb,
                                                          "pippo", "name", "", gval,
                                                          NULL);
+       g_value_unset (gval);
 
        gval = g_new0 (GValue, 1);
        g_value_init (gval, G_TYPE_INT);