From ff261d260eb75b17773fc50489c1c96c6bc87950 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 24 Nov 2012 18:25:45 +0100 Subject: [PATCH] Read if a field is a primary key, if it is nullable and its default value. --- .anjuta_sym_db.db | Bin 34816 -> 34816 bytes src/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++---- tests/db.db | Bin 3072 -> 3072 bytes tests/refdb.db | Bin 3072 -> 3072 bytes 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index e8988f40c82b2988448ef0bf5b074ca2a86fcf80..a527b479be25c444eed00eb8001f939da53cb077 100644 GIT binary patch delta 83 zcmZpez|=5-X@WH4(}^<9j88Wv%#>!gure~TGBV#J!zjwQe=?KdPsS6I{}_5QCU15# m+QR}AVm9{@J;5)`s?5p6Sd^NW5?_*-l#^NvRFGsoF8~0G$s2P3 delta 83 zcmZpez|=5-X@WH4*@-gFjAu6{%#>y~w=yudGBn*J!zjvlU^0{8PsSOO{}_5Q8gF(p m+QR}AVm9{@oxv~6s?5p6Sd^NW5?_*-l#^NvRFGsoF8}~&yBdT5 diff --git a/src/main.c b/src/main.c index 829ce56..cc612f5 100644 --- a/src/main.c +++ b/src/main.c @@ -154,8 +154,7 @@ copy_data () error = NULL; if (!gda_holder_set_value (holder, gval, &error)) { - g_warning ("Unable to set the holder for parameter «%s»: %s.", - param_name, + g_warning ("Unable to set the holder for parameter: %s.", error != NULL && error->message != NULL ? error->message : "no details"); } g_free (param_name); @@ -252,7 +251,14 @@ read_fields (Table *table, GdaServerOperation *op) column->gtype = mt_column->gtype; column->pkey = mt_column->pkey; column->nullok = mt_column->nullok; - column->default_value = g_strdup (mt_column->default_value); + if (mt_column->default_value != NULL) + { + column->default_value = g_strdup (mt_column->default_value); + } + else + { + column->default_value = NULL; + } table->fields = g_slist_append (table->fields, column); if (verbose) @@ -281,7 +287,7 @@ read_fields (Table *table, GdaServerOperation *op) if (!gda_server_operation_set_value_at (op, column->column_name, &error, - g_strdup_printf ("/FIELDS_A/@COLUMN_NAME/%d", i))) + "/FIELDS_A/@COLUMN_NAME/%d", i)) { g_warning ("Error on setting GdaServerOperation's value: %s.", error != NULL && error->message != NULL ? error->message : "no details"); @@ -292,12 +298,54 @@ read_fields (Table *table, GdaServerOperation *op) if (!gda_server_operation_set_value_at (op, column->column_type, &error, - g_strdup_printf ("/FIELDS_A/@COLUMN_TYPE/%d", i))) + "/FIELDS_A/@COLUMN_TYPE/%d", i)) { g_warning ("Error on setting GdaServerOperation's value: %s.", error != NULL && error->message != NULL ? error->message : "no details"); continue; } + + if (column->pkey) + { + error = NULL; + if (!gda_server_operation_set_value_at (op, + "TRUE", + &error, + "/FIELDS_A/@COLUMN_PKEY/%d", i)) + { + g_warning ("Error on setting GdaServerOperation's value: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + continue; + } + } + + if (!column->nullok) + { + error = NULL; + if (!gda_server_operation_set_value_at (op, + "TRUE", + &error, + "/FIELDS_A/@COLUMN_NNUL/%d", i)) + { + g_warning ("Error on setting GdaServerOperation's value: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + continue; + } + } + + if (column->default_value != NULL) + { + error = NULL; + if (!gda_server_operation_set_value_at (op, + column->default_value, + &error, + "/FIELDS_A/@COLUMN_DEFAULT/%d", i)) + { + g_warning ("Error on setting GdaServerOperation's value: %s.", + error != NULL && error->message != NULL ? error->message : "no details"); + continue; + } + } } } g_object_unref (mstruct); diff --git a/tests/db.db b/tests/db.db index e5ace60f48966dc6caf863e7af4769b18e38b61c..77295cccbf00de1e7b147391e34398fd8aeb3862 100644 GIT binary patch delta 80 zcmZpWXpop7CB(?Yz`(!^#2^}kpH0*;0*UHAQsV`38CZbQ`Aj=D7J4%=Zl74Vjd9|{ Z!YQnbKpE!Ef*kLeH!E;FV4m2Z3IHXH5fuOc literal 3072 zcmWFz^vNtqRY=P(%1ta$FlJz3U}R))P*7lCVE6*W%s>nScYq8Q7zao*BC&BXzcA=N zlHvu*GBJH%V6FxdqhK@y1~3E~IXKwG<>eV0<4Y2ga#E8^i%arzQ;Uk>3})vbSH}=n zg%C$4A6Esqu!2Trih`$Kh^xD6kd8ueX;EHcZmL3JMMU{q@W(K;3M!JTE;*4yZ!a%v8)D*A$ jj66e2Q&U|76I~-CQ2vM3>P$n`2#4S~@RATI;}+oo+> diff --git a/tests/refdb.db b/tests/refdb.db index 932e681acccb2d3d9b928af5e5f0bad7678254fc..7b3d334f8d818d7d4b6caa60a80a2005c4f010a1 100644 GIT binary patch delta 149 zcmZpWXpop7Ey&5hz`zW|Fu*oZ#~3K6`$&x!D8$56#lRfMRJE~?i;1f-go#~TUY@b3 zeDV?|e+`9{)U?FXoDv0fbsdGg#N1ScFvlQg562)4Qv*#T$;sQ8<+NlaY-z7A+>OMiVA>ad~;h fCiBTHO#YLXFxzi7V!p(}#K5vykmCvS#0D_{CpHio -- 2.49.0