From 94621e3d54a71d2452de1f1a2bcda2b6f01f545c Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 8 Sep 2019 11:22:14 +0200 Subject: [PATCH] Fixed test getsqlfromhashtable for date and time. Use of zakutils. --- .gitignore | 2 +- tests/Makefile.am | 2 +- tests/{getsql.c => getsqlfromhashtable.c} | 85 +++++++++-------------- 3 files changed, 35 insertions(+), 54 deletions(-) rename tests/{getsql.c => getsqlfromhashtable.c} (62%) diff --git a/.gitignore b/.gitignore index 4bf3eba..9aa7ae2 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ tests/grid tests/fill_liststore tests/*.exe tests/select -tests/getsql +tests/getsqlfromhashtable tests/sqlbuilder tests/metastore *~ diff --git a/tests/Makefile.am b/tests/Makefile.am index 6fe70f6..4634e12 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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/getsqlfromhashtable.c similarity index 62% rename from tests/getsql.c rename to tests/getsqlfromhashtable.c index 083a719..5e6505d 100644 --- a/tests/getsql.c +++ b/tests/getsqlfromhashtable.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Andrea Zagli + * Copyright (C) 2013-2019 Andrea Zagli * * 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 @@ -17,6 +17,9 @@ */ #include + +#include + #include int @@ -30,10 +33,11 @@ main (int argc, char **argv) GValue *gval; GDate *gdate; GDateTime *gdatetime; + GdaTimestamp *gdatimestamp; gtk_init (&argc, &argv); - gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=grid.db", TESTSDIR)); + gdaex = gdaex_new_from_string (argv[1]); if (gdaex == NULL) { g_error ("Unable to connect to the db."); @@ -42,34 +46,22 @@ main (int argc, char **argv) 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"); + gval = zak_utils_gvalue_new_string ("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"); + gval = zak_utils_gvalue_new_string ("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"); + gval = zak_utils_gvalue_new_string ("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"); + gval = zak_utils_gvalue_new_string ("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"); + gval = zak_utils_gvalue_new_string ("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"); + 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)); @@ -82,74 +74,63 @@ main (int argc, char **argv) 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); + gval = zak_utils_gvalue_new_int (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"); + gval = zak_utils_gvalue_new_string ("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 '"); + 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); - g_value_init (gval, G_TYPE_DATE); - gdate = g_date_new_dmy (12, 5, 1966); - g_value_set_boxed (gval, gdate); + 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); - g_value_init (gval, G_TYPE_DATE_TIME); + gdatimestamp = g_new0 (GdaTimestamp, 1); gdatetime = g_date_time_new_now_local (); - g_value_set_boxed (gval, gdatetime); + 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 = g_new0 (GValue, 1); - g_value_init (gval, G_TYPE_STRING); - g_value_set_string (gval, "5th avenue, 44"); + gval = zak_utils_gvalue_new_string ("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); + 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 = g_new0 (GValue, 1); - g_value_init (gval, G_TYPE_STRING); - g_value_set_string (gval, "my new name"); + gval = zak_utils_gvalue_new_string ("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 '"); + gval = zak_utils_gvalue_new_string ("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); + 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 = g_new0 (GValue, 1); - g_value_init (gval, G_TYPE_INT); - g_value_set_int (gval, 55); + 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)); -- 2.49.0