From: Andrea Zagli Date: Sun, 8 Sep 2019 09:22:14 +0000 (+0200) Subject: Fixed test getsqlfromhashtable for date and time. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=94621e3d54a71d2452de1f1a2bcda2b6f01f545c;p=libgdaex Fixed test getsqlfromhashtable for date and time. Use of zakutils. --- 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/getsql.c deleted file mode 100644 index 083a719..0000000 --- a/tests/getsql.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2013 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 - * 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 -#include - -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 index 0000000..5e6505d --- /dev/null +++ b/tests/getsqlfromhashtable.c @@ -0,0 +1,140 @@ +/* + * 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 + * 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 + +#include + +#include + +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; +}