From 0119a07c8eae2c3069dce9d8ff3715f5da379f47 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 25 Nov 2012 09:51:46 +0100 Subject: [PATCH] Added command line table (to copy only specified tables/views). --- .anjuta_sym_db.db | Bin 36864 -> 36864 bytes src/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- tests/db.db | Bin 3072 -> 3072 bytes 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index 76de4102e41d84f1db60630974d7507fa49200dc..381d89a322b0ef0aaddd1c589ec2e3633ab038ef 100644 GIT binary patch delta 1557 zcmZuxeP~-%6o2=eye#Qg(kAhxZPGQ?#nf)5)pW7Nxn(%&AKUz>P|C*Am%P_DG|B6d z*V_8AwK!bU(rx9ch*PPEq6ltTu!s{BQHG%VL&1*?|CnQlAleo24_AENmzQMK8OV9} zo{#%GzjMz$Gs`fu45yj^?_TokW->pt)kdsz(H0=?!isH=i4XPk-n0Fj^TsB973x0c z(S&eq6?!-U2J0|_i#P@s@gVNUZ}Arx#1IDHZCJ%=I1lsq8LmJEUxO=H4W|p8p*HAp z^Fb>iqiR$YV@Ww1Rh4L58J})*yZCly__wxMz%JSqb{rL$X)2>As^8VXx3P^fp^i_e z(cwf=_BtAPpA|?(7NzK9LVhAk)*B2jDWi;+fIRhed@~E2lru3UE4SDk?3_~2a6(Q> zS?*FT{*G%Lp0DOzI-aD&w>WWyLp;iHTn+mde}*+JrsQsO4f6z&5))~7!&bxVX+Ey= z>b2JLjcj9_++#7Y<+Pef$k_mI7^PS=o{l%chD;3lf#1e7 z6XR?vM^myYW>qC4@2ob?G6L_fs%NDjBzrg+n@A)jITPMwRANLDS)J4As1);=ZsR+c zQ$>}Lhnc#ypoL*qH@TM+xN96-fh=AiU*RM07iRG^cMWXVLvpYW?j-NvPw0fti5*@b zt3)CFv~%jrV|ST@R^{01-L7p%!X#t-p*Jb~}xTlhM@f)uY~EUAL?TCDoQr3nlVZ1>bX5 zNlPsm;>ZwLBr9YU{4fAd!x{Jv{>A`~;c|ZV0YXP}+h}N^ozev#v}!c}l#3o%*bF{n zNfw$RpwUyuoivhj*L7+9c}$g1@D`8&)zCzXT* z)PCGe56!ob0s72*BfUD;LM~CrMLf0ao~r;kI0!Go4`{|PDiFd~0r5h9_5)(YK5o1I z><%o=`UipnLvAnTY4Pfht%O{jBF&Wyikvmg?_>e4Qa~});;XK>O{J0#Dsj4HzBP12 zPm~{?NXONLk}eJtgO*9tA~yXPu85+m>(Uc(P@6@SGM48TXQjz?ex2k;8Mg(lp_CRi-zHJIHj z1SCpN8oF*q{5~PVKlBN6e8P;Uw6xmZ;uE?gpoS_d@kvd6El1aUPL^Wm<8f0?q}5!= zyG00b;G}9K^qd;@wD39)Kq*a4D><^-jKAYuf-6me-|naA$!)Ftew2S?<%~Me&@8m^ zyOM|}v&pUC;ccm8sHwOUY1_E@IdnU)nXiJ97YV6IL-(EO)N9o7- z6Sl%tI7`>5PGjYK7p=sm$_(_Ta{fN8^uKw7_WH;up~vw_WcV^7eHyRRv-AtN3GaYR?r;S^lV$P- z89kHlV!Ic@vul&OrZlD|vPo0Zv;VorWm!*nJw%F7iH}GOhxz!#dM8C?f?qkoEI@$eVaK})M`k~l!TF&HS5$aTS+hf@<9y?GB zu+xR@Y`qYMPK%Xi{Ooce0v**Wwb)EC+#P)&=#V1EPNYX13xj1l5pj;-5BLerRlF_( v+0sH_Po&oWWF~!BS5(XDX{`-P4BJmptUl8E#Aoy*%Pe$w+iSt<{4DEVP7Ysq diff --git a/src/main.c b/src/main.c index f8bf60f..ae30f1a 100644 --- a/src/main.c +++ b/src/main.c @@ -24,12 +24,15 @@ static gchar *ref_db_cnc = NULL; static gchar *db_cnc = NULL; +static gchar **tables_to_copy = NULL; static gboolean drop_tables = FALSE; static gchar *output_file = NULL; static gboolean verbose = FALSE; -static GdaConnection *gda_conn_ref_db; -static GdaConnection *gda_conn_db; +static GdaConnection *gda_conn_ref_db = NULL; +static GdaConnection *gda_conn_db = NULL; + +static GHashTable *ht_tables_to_copy = NULL; static xmlDoc *xdoc; static xmlNode *xroot; @@ -38,6 +41,7 @@ static GOptionEntry entries[] = { { "ref-db-cnc", 0, 0, G_OPTION_ARG_STRING, &ref_db_cnc, "Reference database connection string", "CNC_STRING" }, { "db-cnc", 0, 0, G_OPTION_ARG_STRING, &db_cnc, "Database connection string", "CNC_STRING" }, + { "table", 0, 0, G_OPTION_ARG_STRING_ARRAY, &tables_to_copy, "The table/view's name to copy (can be used multiple times)", "TABLE_NAME" }, { "drop-tables", 0, 0, G_OPTION_ARG_NONE, &drop_tables, "Drop tables before creating new ones", NULL }, { "output-file", 0, 0, G_OPTION_ARG_FILENAME, &output_file, "Ouput the whole operation in an xmlfile", "FILENAME" }, { "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "Verbose", NULL }, @@ -404,6 +408,17 @@ read_tables () table->sqlbuilder = NULL; table->fields = NULL; + if (ht_tables_to_copy != NULL) + { + if (!g_hash_table_lookup (ht_tables_to_copy, + table->name)) + { + g_free (table->name); + g_free (table); + continue; + } + } + g_printf ("\tTable: %s\n", table->name); @@ -520,6 +535,15 @@ read_views () for (row = 0; row < rows; row++) { view_name = g_strdup (gda_value_stringify (gda_data_model_get_value_at (dm_views, 0, row, NULL))); + if (ht_tables_to_copy != NULL) + { + if (!g_hash_table_lookup (ht_tables_to_copy, + view_name)) + { + g_free (view_name); + continue; + } + } g_printf ("\tView: %s\n", view_name); @@ -699,6 +723,24 @@ main (int argc, char *argv[]) return; } + if (tables_to_copy != NULL) + { + guint i; + guint l; + + l = g_strv_length (tables_to_copy); + if (l > 0) + { + ht_tables_to_copy = g_hash_table_new (g_str_hash, g_str_equal); + } + for (i = 0; i < l; i++) + { + g_hash_table_insert (ht_tables_to_copy, + tables_to_copy[i], + tables_to_copy[i]); + } + } + if (output_file != NULL) { /* initialize output file */ diff --git a/tests/db.db b/tests/db.db index 3acae74c67fb1993f874253949d4aa9a3f8b9ce9..8f7cd10fa4e04102bc1cb31e361e6d3110df5914 100644 GIT binary patch delta 88 zcmZpWXpop7EjWvTfq@x{nHU%tLni7N3(sQEeWb<<6lGum%6c;GVA`=+kmWTa6XVi} fjnPbu9upfUFm4A5y=R^{;WR5FP$3h97r+Vt|Hl+V literal 3072 zcmWFz^vNtqRY=P(%1ta$FlJz3U}R))P*7lCV4Tdrz`zW|P{8O5WU#<^K$;PWje`j^ zL-&ysFHn}5DVl*fpJ@k>8U-UG1fqr5L^U-z%F8lS!8ks-w74WcH?^o3B!b{M2e~?i zxGIEsx`r#D$|yJnD-@^Zq$ZarXep!><>xBEjc7CxWEYp0XKXSrNlXH&fEf*EFhPwC zadh%=Md(w|$V^f2^b2uycMVbq2=erG42o3nc8%0gC@w9^OUzAG2y+Z__HYc+Fg4Ir zaB+2W4D|_7P*>Mcz$=-QSyYmdl31zW0`v;dtdhi%(qgzhFk=if8~Fs-#igYg8-Xf7 z&d$k9%_}K}Qp~7MhRBiRU`$u)DByLPCMa)0b2U<49~lXB)R&_nFw#Q+l>eES&oD4Q z2NI)TGz3ONV917mBoiBhxTqqBdr@j?o^N7NrJ<#nfv%yEuA!kgBO8M-P%0=j#VbD} P&(PA;RM)^n*T@I}uI8Js -- 2.49.0