From 19767887d2ccdded21a7c774790a85df536010f0 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 16 Sep 2012 11:12:32 +0200 Subject: [PATCH] Comparing tables list. --- .anjuta_sym_db.db | Bin 34816 -> 36864 bytes src/main.c | 80 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index 47502246193c39b910552aac7b492894091fdb2f..4966033fcbef8e4b68722743916d1060c36bc1dd 100644 GIT binary patch delta 3315 zcmai1eQaA-6~FhM_gp`J#h$9_peV>^qT ziY_9q5u#}7rdschRDz&U{uoRuY8t6XFwy-%CNgcX(Me+i6~wBJ0@I{vADsqzoco^b zJSUs5laqVzIrn`2&b>Eh&a*R5u=7zHjS@oon|=2(8eRM5MQ7v!kzkp?+i(kBg%{y5 zxC+08pThE5qX=JgOOTMNr%Snfp`cc)k_cg1EmY=J7iw|hFaP-LFhFy;T4_GFpq479 z)S}mA1BLQ^Cuhq=(Xk6;KAWn{rPp8V$q4p+V~6fKaA@q{mEZ@vcI`W~4}bPw>lS=v7GWmf^ z3`>-LZdRQuW>P*efs<)I$(8dZbs+8)6qa^>{Qaj^fhdd@)~Bb0xKwuhuFH>bUF?W4NxCYYVe#btu9ep_E%nq}`&7 zV^e1|0M|{+g-U5Yzc5>#DfgS6KFBSkl76wyjm{MFxk9B}MqiZBZgJSUgg)YOZ!jRH zXqS8XgfAkF;@Woq^g(Zr7(+(OK|Rr9Znl`w6;D_kMwug>MbnVp%L~v>v`3Ut#*9Xf zy8L1Sr=}oJnl3x9925kP2-i47Z^ED8dAPRj6D~p8DGDTJubrM(i|VvP5QuCqsii4( z!2vjys+hB)o0bV=BxhDs+N87dt;kg_6A48rJ+vI^^WPD-u=WRrx*3MDJ#GI<3qv7bPe zzD7QPudvU<8Ma723AbsO{h59bHrdm_=u_sm*~rx+wy+dy8E+-ma3s}Y7{0U^#yCmu zC!Tf(5|XgRCB+iT^k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u}Ir1ZH@3Z{6z8q diff --git a/src/main.c b/src/main.c index 621cd1d..88f149c 100644 --- a/src/main.c +++ b/src/main.c @@ -25,8 +25,19 @@ static gchar *ref_db_cnc = NULL; static gchar *db_cnc = NULL; -GdaConnection *gda_conn_ref_db; -GdaConnection *gda_conn_db; +static GdaConnection *gda_conn_ref_db; +static GdaConnection *gda_conn_db; + +typedef struct +{ + gchar *name; + GHashTable *ht_fields; +} Table; + +typedef struct +{ + gchar *field_name; +} Field; static GOptionEntry entries[] = { @@ -60,7 +71,7 @@ update_metastore () } static void -read_tables (GdaConnection *gdacon) +read_tables (GdaConnection *gdacon, GHashTable *ht) { GError *error; @@ -69,7 +80,7 @@ read_tables (GdaConnection *gdacon) guint rows; guint row; - gchar *table_name; + Table *table; error = NULL; dm_tables = gda_connection_get_meta_store_data (gdacon, @@ -81,10 +92,44 @@ read_tables (GdaConnection *gdacon) rows = gda_data_model_get_n_rows (dm_tables); for (row = 0; row < rows; row++) { - table_name = gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL)); - g_message ("Table: %s", table_name); + table = g_new0 (Table, 1); + + table->name = gda_value_stringify (gda_data_model_get_value_at (dm_tables, 0, row, NULL)); + g_message ("\tTable: %s", table->name); + + g_hash_table_insert (ht, table->name, table); + } + } + if (dm_tables != NULL) + { + g_object_unref (dm_tables); + } +} + +static gboolean +comparing (GHashTable *ht_ref_db_tables, GHashTable *ht_db_tables) +{ + GHashTableIter iter; + gpointer key, value; + + Table *table; + + gboolean ret; + + ret = TRUE; + + g_hash_table_iter_init (&iter, ht_ref_db_tables); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + table = (Table *)value; + if (!g_hash_table_lookup (ht_db_tables, table->name)) + { + g_message ("Table «%s» missing.", table->name); + ret = FALSE; } } + + return ret; } int @@ -93,6 +138,9 @@ main (int argc, char *argv[]) GError *error; GOptionContext *context; + GHashTable *ht_ref_db_tables; + GHashTable *ht_db_tables; + g_type_init (); error = NULL; @@ -141,11 +189,23 @@ main (int argc, char *argv[]) update_metastore (); - g_message ("Reading tables of reference database."); - read_tables (gda_conn_ref_db); + g_message ("Reading tables of reference database (%s).", ref_db_cnc); + ht_ref_db_tables = g_hash_table_new (g_str_hash, g_str_equal); + read_tables (gda_conn_ref_db, ht_ref_db_tables); + + g_message ("Reading tables of database (%s).", db_cnc); + ht_db_tables = g_hash_table_new (g_str_hash, g_str_equal); + read_tables (gda_conn_db, ht_db_tables); - g_message ("Reading tables of database."); - read_tables (gda_conn_db); + g_message ("Comparing databases."); + if (comparing (ht_ref_db_tables, ht_db_tables)) + { + g_message ("Databases are equals."); + } + else + { + g_message ("Databases have one or more differences."); + } g_object_unref (gda_conn_ref_db); g_object_unref (gda_conn_db); -- 2.49.0