From dcefdc78c796f94b56593d2f02e14877f280b0ad Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 16 Sep 2012 11:42:06 +0200 Subject: [PATCH] Reading tables fields. --- .anjuta_sym_db.db | Bin 36864 -> 36864 bytes src/main.c | 64 +++++++++++++++++++++++++++++++++++++++++++++- tests/db.db | Bin 2048 -> 2048 bytes 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index 4966033fcbef8e4b68722743916d1060c36bc1dd..a563dbd9affdb16c7eb542b859f2d79ab90710d2 100644 GIT binary patch delta 1300 zcmZuwZA@EL7=F+Dw9q>WrLY!S+woCI%Qoi*3rypWF%nG{m&J^PA0(@#Ezm(*1V%s| zQU@bbC^kpK{wx8F(U_4?>b5K{&L3kDjdALXnZ}uDVm9YuvKXCl2G4DSfrNW=pL_3n z-jDM<=Y7ZKcx;Yee?&~DTrFZc{oGpx<mduV6K2+Un4F{%I8x2FmrIQvjYWSr5b_TOI(owcG~p~!Hj%S+M#8T`n%P*UmY>pBd>-b1^fe)3foQm@w$SKM-=PkFFcx%{T8&lNM4kSe#ZiK<$(&O{ zX`wMzfLi;6&=EZJOUx!BcOl#hAB6|5kQ2bj+kcc0iS z)B?|XNs2P*o+IYHcA6D5ON;a^7I+>F;ybkQA&l{Hu?u%Z88?cf{Jj{*3SS0`_w_rK z@XOiZdZxeSXT!S;;xM^W%?@cFd9vO@;$PaG+iq>1M{{qe*?Bw`9E`+c>j-$|_{d9J z9$zE4JC)d3X3w)}jfn$!PwptUi)A7H!0-GF4saOlJj#!N|VjW5tPDmN&_HkB!Ss+DP5s@Z8RHYjn{3nRs(b7}Ge z7S}T8PakGi0j-p9Az$LVv?4Bv6!&6A+!l5GG#!(bQwI&=Rr042?G;Cz#iV&yYqtrL zTOS$IhB=bIC7WICUfoA%Z5w^E?I(XtI`?E-zH)nZ`09q@kxC`9w09 ztdlF#kI9~yTDd*hD%x?e-1SMx15jx3-3_YJp_(V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edef struct { - gchar *field_name; + gchar *name; } Field; static GOptionEntry entries[] = @@ -70,6 +70,65 @@ update_metastore () } } +static void +read_fields (GdaConnection *gdacon, Table *table) +{ + GError *error; + + GdaMetaContext mcontext = {"_columns", 1, NULL, NULL}; + + GValue *gval; + + GdaDataModel *dm_fields; + + guint rows; + guint row; + + Field *field; + + error = NULL; + + mcontext.column_names = g_new (gchar *, 1); + mcontext.column_names[0] = "table_name"; + mcontext.column_values = g_new (GValue *, 1); + mcontext.column_values[0] = gda_value_new (G_TYPE_STRING); + + g_value_take_string (mcontext.column_values[0], + gda_sql_identifier_quote (table->name, gdacon, NULL, FALSE, FALSE)); + + if (!gda_connection_update_meta_store (gdacon, &mcontext, &error)) + { + g_warning ("Unable to update database metastore: %s", + (error != NULL && error->message != NULL ? error->message : "no details.")); + return; + } + + error = NULL; + gval = gda_value_new (G_TYPE_STRING); + g_value_take_string (gval, table->name); + dm_fields = gda_connection_get_meta_store_data (gdacon, + GDA_CONNECTION_META_FIELDS, + &error, + 1, + "name", gval); + if (dm_fields != NULL && error == NULL) + { + rows = gda_data_model_get_n_rows (dm_fields); + for (row = 0; row < rows; row++) + { + field = g_new0 (Field, 1); + field->name = gda_value_stringify (gda_data_model_get_value_at (dm_fields, 0, row, NULL)); + g_message ("\t\tField: %s", field->name); + + g_hash_table_insert (table->ht_fields, field->name, field); + } + } + if (dm_fields != NULL) + { + g_object_unref (dm_fields); + } +} + static void read_tables (GdaConnection *gdacon, GHashTable *ht) { @@ -93,11 +152,14 @@ read_tables (GdaConnection *gdacon, GHashTable *ht) for (row = 0; row < rows; row++) { table = g_new0 (Table, 1); + table->ht_fields = g_hash_table_new (g_str_hash, g_str_equal); 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); + + read_fields (gdacon, table); } } if (dm_tables != NULL) diff --git a/tests/db.db b/tests/db.db index 9831ee9ed9ac7c1e57b3a448a1750eb81d7c9e3d..2cb8c26c7f360cf3cf22a212e991a2b5ed61715e 100644 GIT binary patch delta 83 zcmZn=Xb_knEy&Ekz`z8=Fu*)f$C#g)LHCg=FHne)Ihlbud9xtPGbYLPFeMPWQHqgW TTw0p3iFb%&a|@UN -- 2.49.0