Fixed test getsqlfromhashtable for date and time.
authorAndrea Zagli <azagli@libero.it>
Sun, 8 Sep 2019 09:22:14 +0000 (11:22 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 8 Sep 2019 09:22:14 +0000 (11:22 +0200)
Use of zakutils.

.gitignore
tests/Makefile.am
tests/getsql.c [deleted file]
tests/getsqlfromhashtable.c [new file with mode: 0644]

index 4bf3eba9cb5fb0fe49e3941eba30c2c840d08a3a..9aa7ae211536e48bbb7c820c2de381068cfa4ffc 100644 (file)
@@ -51,7 +51,7 @@ tests/grid
 tests/fill_liststore
 tests/*.exe
 tests/select
-tests/getsql
+tests/getsqlfromhashtable
 tests/sqlbuilder
 tests/metastore
 *~
index 6fe70f6bb4f684c7aa8cf913cc3c4f1ab6579c34..4634e12458109d8a8fd83535a076d030b9ef585a 100644 (file)
@@ -6,7 +6,7 @@ AM_CPPFLAGS = $(GDAEX_CFLAGS) \
               -DTESTSDIR="\"@abs_builddir@\""
 
 noinst_PROGRAMS = fill_liststore \
-                  getsql \
+                  getsqlfromhashtable \
                   metastore \
                   query_editor \
                   select \
diff --git a/tests/getsql.c b/tests/getsql.c
deleted file mode 100644 (file)
index 083a719..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (C) 2013 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
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <gtk/gtk.h>
-#include <libgdaex.h>
-
-int
-main (int argc, char **argv)
-{
-       GdaEx *gdaex;
-
-       GHashTable *ht_keys;
-       GHashTable *ht_fields;
-
-       GValue *gval;
-       GDate *gdate;
-       GDateTime *gdatetime;
-
-       gtk_init (&argc, &argv);
-
-       gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=grid.db", TESTSDIR));
-       if (gdaex == NULL)
-               {
-                       g_error ("Unable to connect to the db.");
-               }
-
-       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
-       ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "id");
-       g_hash_table_insert (ht_fields, "id", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "name");
-       g_hash_table_insert (ht_fields, "name", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "surname");
-       g_hash_table_insert (ht_fields, "surname", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "birthday");
-       g_hash_table_insert (ht_fields, "birthday", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "address");
-       g_hash_table_insert (ht_fields, "address", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "incoming");
-       g_hash_table_insert (ht_fields, "incoming", gval);
-
-       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_SELECT, "clients", ht_keys, ht_fields));
-
-       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_INSERT, "clients", ht_keys, ht_fields));
-
-       g_hash_table_destroy (ht_keys);
-       g_hash_table_destroy (ht_fields);
-
-       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
-       ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_INT);
-       g_value_set_int (gval, 44);
-       g_hash_table_insert (ht_fields, "id", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "my name is my name");
-       g_hash_table_insert (ht_fields, "name", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "and this is the sur'name with '");
-       g_hash_table_insert (ht_fields, "surname", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_DATE);
-       gdate = g_date_new_dmy (12, 5, 1966);
-       g_value_set_boxed (gval, gdate);
-       g_hash_table_insert (ht_fields, "birthday", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_DATE_TIME);
-       gdatetime = g_date_time_new_now_local ();
-       g_value_set_boxed (gval, gdatetime);
-       g_hash_table_insert (ht_fields, "oggi", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "5th avenue, 44");
-       g_hash_table_insert (ht_fields, "address", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_DOUBLE);
-       g_value_set_double (gval, 1451.22);
-       g_hash_table_insert (ht_fields, "incoming", gval);
-
-       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_INSERT, "clients", ht_keys, ht_fields));
-       g_hash_table_destroy (ht_keys);
-       g_hash_table_destroy (ht_fields);
-
-       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
-       ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "my new name");
-       g_hash_table_insert (ht_fields, "name", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_STRING);
-       g_value_set_string (gval, "and this is the new sur'name with '");
-       g_hash_table_insert (ht_fields, "surname", gval);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_INT);
-       g_value_set_int (gval, 55);
-       g_hash_table_insert (ht_keys, "id", gval);
-
-       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_UPDATE, "clients", ht_keys, ht_fields));
-       g_hash_table_destroy (ht_keys);
-       g_hash_table_destroy (ht_fields);
-
-       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
-
-       gval = g_new0 (GValue, 1);
-       g_value_init (gval, G_TYPE_INT);
-       g_value_set_int (gval, 55);
-       g_hash_table_insert (ht_keys, "id", gval);
-
-       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_DELETE, "clients", ht_keys, ht_fields));
-       g_hash_table_destroy (ht_keys);
-
-       return 0;
-}
diff --git a/tests/getsqlfromhashtable.c b/tests/getsqlfromhashtable.c
new file mode 100644 (file)
index 0000000..5e6505d
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2013-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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+#include <libzakutils/libzakutils.h>
+
+#include <libgdaex.h>
+
+int
+main (int argc, char **argv)
+{
+       GdaEx *gdaex;
+
+       GHashTable *ht_keys;
+       GHashTable *ht_fields;
+
+       GValue *gval;
+       GDate *gdate;
+       GDateTime *gdatetime;
+       GdaTimestamp *gdatimestamp;
+
+       gtk_init (&argc, &argv);
+
+       gdaex = gdaex_new_from_string (argv[1]);
+       if (gdaex == NULL)
+               {
+                       g_error ("Unable to connect to the db.");
+               }
+
+       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
+       ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
+
+       gval = zak_utils_gvalue_new_string ("id");
+       g_hash_table_insert (ht_fields, "id", gval);
+
+       gval = zak_utils_gvalue_new_string ("name");
+       g_hash_table_insert (ht_fields, "name", gval);
+
+       gval = zak_utils_gvalue_new_string ("surname");
+       g_hash_table_insert (ht_fields, "surname", gval);
+
+       gval = zak_utils_gvalue_new_string ("birthday");
+       g_hash_table_insert (ht_fields, "birthday", gval);
+
+       gval = zak_utils_gvalue_new_string ("address");
+       g_hash_table_insert (ht_fields, "address", gval);
+
+       gval = zak_utils_gvalue_new_string ("incoming");
+       g_hash_table_insert (ht_fields, "incoming", gval);
+
+       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_SELECT, "clients", ht_keys, ht_fields));
+
+       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_INSERT, "clients", ht_keys, ht_fields));
+
+       g_hash_table_destroy (ht_keys);
+       g_hash_table_destroy (ht_fields);
+
+       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
+       ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
+
+       gval = zak_utils_gvalue_new_int (44);
+       g_hash_table_insert (ht_fields, "id", gval);
+
+       gval = zak_utils_gvalue_new_string ("my name is my name");
+       g_hash_table_insert (ht_fields, "name", gval);
+
+       gval = zak_utils_gvalue_new_string ("and this is the sur'name with '");
+       g_hash_table_insert (ht_fields, "surname", gval);
+
+       gval = g_new0 (GValue, 1);
+       gdatimestamp = g_new0 (GdaTimestamp, 1);
+       gdatimestamp->year = 1996;
+       gdatimestamp->month = 5;
+       gdatimestamp->day = 12;
+       gda_value_set_timestamp (gval, gdatimestamp);
+       g_hash_table_insert (ht_fields, "birthday", gval);
+
+       gval = g_new0 (GValue, 1);
+       gdatimestamp = g_new0 (GdaTimestamp, 1);
+       gdatetime = g_date_time_new_now_local ();
+       gdatimestamp->year = g_date_time_get_year (gdatetime);
+       gdatimestamp->month = g_date_time_get_month (gdatetime);
+       gdatimestamp->day = g_date_time_get_day_of_month (gdatetime);
+       gda_value_set_timestamp (gval, gdatimestamp);
+       g_hash_table_insert (ht_fields, "oggi", gval);
+
+       gval = zak_utils_gvalue_new_string ("5th avenue, 44");
+       g_hash_table_insert (ht_fields, "address", gval);
+
+       gval = zak_utils_gvalue_new_float (1451.22);
+       g_hash_table_insert (ht_fields, "incoming", gval);
+
+       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_INSERT, "clients", ht_keys, ht_fields));
+
+       g_hash_table_destroy (ht_keys);
+       g_hash_table_destroy (ht_fields);
+
+       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
+       ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
+
+       gval = zak_utils_gvalue_new_string ("my new name");
+       g_hash_table_insert (ht_fields, "name", gval);
+
+       gval = zak_utils_gvalue_new_string ("and this is the new sur'name with '");
+       g_hash_table_insert (ht_fields, "surname", gval);
+
+       gval = zak_utils_gvalue_new_int (55);
+       g_hash_table_insert (ht_keys, "id", gval);
+
+       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_UPDATE, "clients", ht_keys, ht_fields));
+
+       g_hash_table_destroy (ht_keys);
+       g_hash_table_destroy (ht_fields);
+
+       ht_keys = g_hash_table_new (g_str_hash, g_str_equal);
+
+       gval = zak_utils_gvalue_new_int (55);
+       g_hash_table_insert (ht_keys, "id", gval);
+
+       g_message ("%s", gdaex_get_sql_from_hashtable (gdaex, GDAEX_SQL_DELETE, "clients", ht_keys, ht_fields));
+       g_hash_table_destroy (ht_keys);
+
+       return 0;
+}