Re: [gnome-db] GDA: PostgreSQL empty slots table



Please see at attachment for a patch to add AUTOINC (set type to
serial) on Postgresql.

Hops this helps to Phil in the problem to autoincrement Pkey at
Postgresql GDA provider,

This will close Bugs: #515306 and #515528


Just wait for gnome-db developers to review it.

2008/2/7, Mark Johnson <mrj001 shaw ca>:
> The slots table includes an id field which is "auto_increment".
> PostgreSQL does not implement that keyword.  Instead, it appears to
> accept it, but ignore it when creating the table.  (This may actually be
> libgda's PostgreSQL provider doing that.)  Gnucash-gda relies upon that
> field auto-incrementing when inserts are done to the slots table.  The
> result is similar to this for every insert to the slots table:
> ERROR:  null value in column "slot_id" violates not-null constraint
> STATEMENT:  INSERT INTO slots (obj_guid, name, slot_type, int64_val,
> string_val, double_val, timespec_val, guid_val, numeric_val_num,
> numeric_val_denom) VALUES ('77889f8da5fb434ae68891da19bef5ad',
> 'reconcile-info/last-date', 1, 1199170799, NULL, NULL, '1969-12-31',
> NULL, 0, 1)
>
> When saving to the gda backend, both MySql and sqlite have many records
> in the slots table.  PostgreSQL ends up with none.
>
> Mark
>
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel gnucash org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>


-- 
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los
cuates: LIBRE)
Index: doc/C/libgda-3.0-docs.sgml
===================================================================
--- doc/C/libgda-3.0-docs.sgml	(revisión: 3056)
+++ doc/C/libgda-3.0-docs.sgml	(copia de trabajo)
@@ -207,6 +207,16 @@
 	<contrib>libgda, gda-postgres, gda-mysql
         </contrib>
       </author>
+      <author>
+        <firstname>Daniel</firstname>
+        <surname>Espinosa Ortiz</surname>
+        <affiliation>
+          <orgname></orgname>
+          <address><email>esodan gmail com</email></address>
+        </affiliation>
+	<contrib>libgda, gda-postgres, gda-mysql
+        </contrib>
+      </author>
     </authorgroup>
     <date>1999 February</date>
     <copyright>
Index: doc/C/tmpl/gda-data-model-bdb.sgml
===================================================================
--- doc/C/tmpl/gda-data-model-bdb.sgml	(revisión: 3056)
+++ doc/C/tmpl/gda-data-model-bdb.sgml	(copia de trabajo)
@@ -29,17 +29,9 @@
 
 </para>
 
+ object: 
+ priv: 
 
-<!-- ##### ARG GdaDataModelBdb:db-name ##### -->
-<para>
-
-</para>
-
-<!-- ##### ARG GdaDataModelBdb:filename ##### -->
-<para>
-
-</para>
-
 <!-- ##### STRUCT GdaDataModelBdbClass ##### -->
 <para>
 
Index: providers/postgres/gda-postgres-ddl.c
===================================================================
--- providers/postgres/gda-postgres-ddl.c	(revisión: 3056)
+++ providers/postgres/gda-postgres-ddl.c	(copia de trabajo)
@@ -155,8 +155,14 @@
 			g_string_append_c (string, '\"');
 			g_string_append_c (string, ' ');
 				
-			value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
-			g_string_append (string, g_value_get_string (value));
+			value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_AUTOINC/%d", i);
+			if (value)
+				g_string_append (string, "serial");
+			else
+			{
+				value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_TYPE/%d", i);
+				g_string_append (string, g_value_get_string (value));
+			}
 				
 			value = gda_server_operation_get_value_at (op, "/FIELDS_A/@COLUMN_SIZE/%d", i);
 			if (value && G_VALUE_HOLDS (value, G_TYPE_UINT)) {
Index: providers/postgres/postgres_specs_create_table.xml.in
===================================================================
--- providers/postgres/postgres_specs_create_table.xml.in	(revisión: 3056)
+++ providers/postgres/postgres_specs_create_table.xml.in	(copia de trabajo)
@@ -33,6 +33,7 @@
     <gda_array_field id="COLUMN_SIZE" _name="Size" gdatype="guint"/>
     <gda_array_field id="COLUMN_SCALE" _name="Scale" gdatype="guint"/>
     <gda_array_field id="COLUMN_NNUL" _name="Not NULL" gdatype="gboolean"/>
+    <gda_array_field id="COLUMN_AUTOINC" _name="Auto increment" gdatype="gboolean"/>
     <gda_array_field id="COLUMN_UNIQUE" _name="Unique" gdatype="gboolean"/>
     <gda_array_field id="COLUMN_PKEY" _name="Primary key" gdatype="gboolean"/>
     <gda_array_field id="COLUMN_DEFAULT" _name="Default" _descr="Default value" gdatype="gchararray"/>
@@ -44,6 +45,7 @@
             <gda_value></gda_value>
             <gda_value></gda_value>
             <gda_value>FALSE</gda_value>
+            <gda_value>TRUE</gda_value>
             <gda_value>FALSE</gda_value>
             <gda_value>TRUE</gda_value>
             <gda_value></gda_value>
Index: providers/postgres/gda-postgres-provider.c
===================================================================
--- providers/postgres/gda-postgres-provider.c	(revisión: 3056)
+++ providers/postgres/gda-postgres-provider.c	(copia de trabajo)
@@ -1569,6 +1569,74 @@
 	return retval;
 }
 
+static GdaParameter *
+gda_postgres_provider_get_last_inserted_id (GdaServerProvider *provider,
+					  GdaConnection *cnc,
+					  GdaDataModel *recset)
+{
+	Oid oid;
+	PGresult *pgres;
+	GdaPostgresConnectionData *priv_data;
+	GdaPostgresProvider *pg_prv = (GdaPostgresProvider *) provider;
+
+	g_return_val_if_fail (GDA_IS_POSTGRES_PROVIDER (pg_prv), NULL);
+	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+
+	priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
+	if (!priv_data) {
+		gda_connection_add_event_string (cnc, _("Invalid PostgreSQL handle"));
+		return NULL;
+	}
+
+	if (recset) {
+		g_return_val_if_fail (GDA_IS_POSTGRES_RECORDSET (recset), NULL);
+		/* get the PQresult from the recordset */
+		pgres = gda_postgres_recordset_get_pgresult (GDA_POSTGRES_RECORDSET (recset));
+		if (pgres) {
+			oid = PQoidValue (pgres);
+			if (oid != InvalidOid)
+			{
+				GdaParameter *param;
+				GValue *value;
+				
+				g_value_init (value, G_TYPE_INT);
+				g_value_set_int (value, oid);
+				
+				gda_parameter_new (G_TYPE_INT);
+				
+				gda_parameter_set_value (param, value);
+				
+				return param;
+			}
+		}
+		return NULL;
+	}
+
+	/* get the last inserted OID kept */
+	if (priv_data->last_insert_id)
+	{
+		GdaParameter *param;
+		GValue *value;
+		GValue *str;
+		gint *oid;
+		
+		g_value_init (str, G_TYPE_STRING);
+		g_value_set (str, priv_data->last_insert_id);
+		
+		g_value_init (value, G_TYPE_INT);
+		
+		g_value_transform (str, value);
+		
+		gda_parameter_new (G_TYPE_INT);
+		
+		gda_parameter_set_value (param, value);
+		
+		return param;
+	}
+	else
+		return NULL;
+}
+
 static gchar *
 gda_postgres_provider_get_last_insert_id (GdaServerProvider *provider,
 					  GdaConnection *cnc,
@@ -1607,6 +1675,7 @@
 		return NULL;
 }
 
+
 static gboolean 
 gda_postgres_provider_begin_transaction (GdaServerProvider *provider,
 				         GdaConnection *cnc,
Index: libgda/gda-data-model-query.c
===================================================================
--- libgda/gda-data-model-query.c	(revisión: 3056)
+++ libgda/gda-data-model-query.c	(copia de trabajo)
@@ -1516,12 +1516,13 @@
 static GdaQueryTarget *auto_compute_assert_modify_target (GdaDataModelQuery *model, const gchar *target, GError **error);
 static GSList   *auto_compute_make_cond_query_fields (GdaDataModelQuery *model, GdaQueryTarget *modify_target, 
 						      gboolean use_all_if_no_pk, GError **error);
-static GSList   *auto_compute_make_mod_query_fields (GdaDataModelQuery *model, GdaQueryTarget *modify_target,
-						     GError **error);
-static void      auto_compute_add_mod_fields_to_query (GdaDataModelQuery *model, GdaQueryTarget *modify_target,
-						       GSList *mod_query_fields, GdaQuery *query);
+static GSList   *auto_compute_make_mod_query_fields (GdaDataModelQuery *model, GdaQueryTarget *modify_target, 
+													 GdaDataModelQueryOptions options,
+													 GError **error);
+static void      auto_compute_add_mod_fields_to_query (GdaDataModelQuery *model, GdaQueryTarget *modify_target, 
+													   GSList *mod_query_fields, GdaQuery *query);
 static void      auto_compute_add_where_cond_to_query (GdaDataModelQuery *model, GSList *mod_query_fields, 
-						       GdaQuery *query);
+													   GdaQuery *query);
 /**
  * gda_data_model_query_compute_modification_queries
  * @model: a GdaDataModelQuery object
@@ -1573,7 +1574,8 @@
 	if (!cond_query_fields)
 		return FALSE;
 
-	mod_query_fields = auto_compute_make_mod_query_fields (model, modify_target, error);
+	mod_query_fields = auto_compute_make_mod_query_fields (model, modify_target,
+														   options, error);
 	if (!mod_query_fields) {
 		g_slist_free (cond_query_fields);
 		return FALSE;
@@ -1766,11 +1768,14 @@
 }
 
 static GSList *
-auto_compute_make_mod_query_fields (GdaDataModelQuery *model, GdaQueryTarget *modify_target, GError **error)
+auto_compute_make_mod_query_fields (GdaDataModelQuery *model, GdaQueryTarget *modify_target, 
+					GdaDataModelQueryOptions options,
+					GError **error)
 {
 	GSList *mod_query_fields = NULL;
 	GSList *mod_dict_fields = NULL;
 	GSList *target_fields, *list;
+	GSList *pk_ai_fields; /* List of PrimaryKeys and Autoincrement or serial fields */
 	gboolean duplicate = FALSE;
 
 	/* make sure there are no duplicates in the fields referenced by modify_target */
@@ -1779,13 +1784,22 @@
 	for (list = target_fields; list && !duplicate; list = list->next) {
 		GdaQueryFieldField *qfield = (GdaQueryFieldField *) (list->data);
 		GdaEntityField *efield;
+		GdaDictFieldAttribute attr;
 		
 		g_assert (GDA_IS_QUERY_FIELD_FIELD (qfield));
 		efield = gda_query_field_field_get_ref_field (qfield);
 		g_assert (GDA_IS_DICT_FIELD (efield));
+		attr = gda_dict_field_get_attributes (GDA_DICT_FIELD (efield));
 		if (!g_slist_find (mod_dict_fields, efield)) {
+			
 			mod_dict_fields = g_slist_prepend (mod_dict_fields, efield);
-			mod_query_fields = g_slist_prepend (mod_query_fields, qfield);
+			
+			if (!(options & GDA_DATA_MODEL_QUERY_OPTION_DONT_USE_PK_AI_FIELDS
+				 && attr & FIELD_AUTO_INCREMENT
+				 && gda_dict_field_is_pkey_part (GDA_DICT_FIELD (efield))))
+			{
+				mod_query_fields = g_slist_prepend (mod_query_fields, qfield);
+			}
 		}
 		else {
 			GdaDictTable *mod_table;
@@ -1800,9 +1814,10 @@
 		}
 	}
 	
+	
 	g_slist_free (target_fields);
 	g_slist_free (mod_dict_fields);
-
+	
 	if (duplicate) {
 		g_slist_free (mod_query_fields);
 		mod_query_fields = NULL;
Index: libgda/gda-data-model-query.h
===================================================================
--- libgda/gda-data-model-query.h	(revisión: 3056)
+++ libgda/gda-data-model-query.h	(copia de trabajo)
@@ -48,7 +48,9 @@
 } GdaDataModelQueryError;
 
 typedef enum {
-	GDA_DATA_MODEL_QUERY_OPTION_USE_ALL_FIELDS_IF_NO_PK = 1 << 0
+	GDA_DATA_MODEL_QUERY_OPTION_NONE = 0,
+	GDA_DATA_MODEL_QUERY_OPTION_DONT_USE_PK_AI_FIELDS   = 1 << 0,
+	GDA_DATA_MODEL_QUERY_OPTION_USE_ALL_FIELDS_IF_NO_PK = 1 << 1
 } GdaDataModelQueryOptions;
 
 struct _GdaDataModelQuery {
Index: libgda/graph/Makefile.am
===================================================================
--- libgda/graph/Makefile.am	(revisión: 3056)
+++ libgda/graph/Makefile.am	(copia de trabajo)
@@ -20,3 +20,4 @@
         gda-graph-item.c \
         gda-graph-query.c \
 	gda-dict-reg-graphs.c
+
Index: libgda/gda-data-proxy.c
===================================================================
--- libgda/gda-data-proxy.c	(revisión: 3056)
+++ libgda/gda-data-proxy.c	(copia de trabajo)
@@ -110,7 +110,7 @@
 {
 	PROP_0,
 	PROP_MODEL,
-	PROP_ADD_NULL_ENTRY,
+	PROP_PREPEND_NULL_ENTRY,
 	PROP_DEFER_SYNC,
 	PROP_SAMPLE_SIZE
 };
@@ -408,12 +408,17 @@
 {
 	GSList *list;
 	gint i;
+	
+	g_return_if_fail (rm);
 		
 	list = rm->modify_values;
 	while (list) {
-		if (ROW_VALUE (list->data)->value)
-			gda_value_free (ROW_VALUE (list->data)->value);
-		g_free (list->data);
+		if (list->data) 
+		{
+			if (ROW_VALUE (list->data)->value)
+				gda_value_free (ROW_VALUE (list->data)->value);
+			g_free (list->data);
+		}
 		list = g_slist_next (list);
 	}
 	g_slist_free (rm->modify_values);
@@ -533,6 +538,32 @@
 
 	parent_class = g_type_class_peek_parent (class);
 
+	/* virtual functions */
+#ifdef GDA_DEBUG
+	GDA_OBJECT_CLASS (class)->dump = (void (*)(GdaObject *, guint)) gda_data_proxy_dump;
+#endif
+
+	object_class->dispose = gda_data_proxy_dispose;
+	object_class->finalize = gda_data_proxy_finalize;
+
+	/* Properties */
+	object_class->set_property = gda_data_proxy_set_property;
+	object_class->get_property = gda_data_proxy_get_property;
+
+	g_object_class_install_property (object_class, PROP_MODEL,
+					 g_param_spec_object ("model", _("Data model"), NULL,
+                                                               GDA_TYPE_DATA_MODEL,
+							       (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)));
+	g_object_class_install_property (object_class, PROP_PREPEND_NULL_ENTRY,
+					 g_param_spec_boolean ("prepend-null-entry", NULL, NULL, FALSE,
+							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+	g_object_class_install_property (object_class, PROP_DEFER_SYNC,
+					 g_param_spec_boolean ("defer-sync", NULL, NULL, TRUE,
+							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+	g_object_class_install_property (object_class, PROP_SAMPLE_SIZE,
+					 g_param_spec_int ("sample-size", NULL, NULL, 0, G_MAXINT - 1, 300,
+							   (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)));
+
 	/* signals */
 	gda_data_proxy_signals [ROW_DELETE_CHANGED] =
 		g_signal_new ("row_delete_changed",
@@ -583,31 +614,6 @@
 	class->pre_changes_applied = m_pre_changes_applied;
 	class->post_changes_applied = NULL;
 
-	/* virtual functions */
-#ifdef GDA_DEBUG
-	GDA_OBJECT_CLASS (class)->dump = (void (*)(GdaObject *, guint)) gda_data_proxy_dump;
-#endif
-
-	object_class->dispose = gda_data_proxy_dispose;
-	object_class->finalize = gda_data_proxy_finalize;
-
-	/* Properties */
-	object_class->set_property = gda_data_proxy_set_property;
-	object_class->get_property = gda_data_proxy_get_property;
-
-	g_object_class_install_property (object_class, PROP_MODEL,
-					 g_param_spec_object ("model", _("Data model"), NULL,
-                                                               GDA_TYPE_DATA_MODEL,
-							       (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)));
-	g_object_class_install_property (object_class, PROP_ADD_NULL_ENTRY,
-					 g_param_spec_boolean ("prepend_null_entry", NULL, NULL, FALSE,
-							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-	g_object_class_install_property (object_class, PROP_DEFER_SYNC,
-					 g_param_spec_boolean ("defer_sync", NULL, NULL, TRUE,
-							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-	g_object_class_install_property (object_class, PROP_SAMPLE_SIZE,
-					 g_param_spec_int ("sample_size", NULL, NULL, 0, G_MAXINT - 1, 300,
-							   (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)));
 }
 
 static void
@@ -870,7 +876,7 @@
 				proxy->priv->chunk = NULL;
 			}
 			break;
-		case PROP_ADD_NULL_ENTRY:
+		case PROP_PREPEND_NULL_ENTRY:
 			if (proxy->priv->add_null_entry != g_value_get_boolean (value)) {
 				proxy->priv->add_null_entry = g_value_get_boolean (value);
 
@@ -915,7 +921,10 @@
 	proxy = GDA_DATA_PROXY (object);
 	if (proxy->priv) {
 		switch (param_id) {
-		case PROP_ADD_NULL_ENTRY:
+		case PROP_MODEL:
+			g_value_set_object (value, proxy->priv->model);
+			break;
+		case PROP_PREPEND_NULL_ENTRY:
 			g_value_set_boolean (value, proxy->priv->add_null_entry);
 			break;
 		case PROP_DEFER_SYNC:
@@ -1909,7 +1918,7 @@
 						    GDA_VALUE_ATTR_IS_DEFAULT)
 							newvalue = NULL;
 						else {
-							if (! ROW_VALUE (list->data)->value) {
+							if (! G_IS_VALUE (ROW_VALUE (list->data)->value)) {
 								newvalue = gda_value_new_null ();
 								free_val [i] = newvalue;
 							}
@@ -1953,7 +1962,7 @@
 						    GDA_VALUE_ATTR_IS_DEFAULT)
 							newvalue = NULL;
 						else {
-							if (! ROW_VALUE (list->data)->value) {
+							if (! G_IS_VALUE (ROW_VALUE (list->data)->value)) {
 								newvalue = gda_value_new_null ();
 								free_val [i] = newvalue;
 							}
Index: libgda/gda-value.c
===================================================================
--- libgda/gda-value.c	(revisión: 3056)
+++ libgda/gda-value.c	(copia de trabajo)
@@ -1210,6 +1210,7 @@
 
 	l_g_value_unset (value);
 	g_free (value);
+	value = NULL;
 }
 
 /* gda_value_reset_with_type
Index: libgda/gda-init.c
===================================================================
--- libgda/gda-init.c	(revisión: 3056)
+++ libgda/gda-init.c	(copia de trabajo)
@@ -337,99 +337,114 @@
 {
 	GdaServerOperation *op;
 	GdaServerProvider *server;
+			
+	g_return_val_if_fail (gda_connection_is_opened (cnn), FALSE);	
+		
+	server = gda_connection_get_provider_obj(cnn);
 	
-	g_return_val_if_fail (GDA_IS_CONNECTION (cnn), FALSE);
-	g_return_val_if_fail (gda_connection_is_opened (cnn), FALSE);
+	/* FIXME: Need to create a GdaParameterList with the flags supported in this function */
+	if (!gda_server_provider_supports_operation (server, cnn, GDA_SERVER_OPERATION_CREATE_TABLE, NULL))
+	{
+		*error = g_error_new (GDA_GENERAL_ERROR, GDA_GENERAL_OBJECT_NAME_ERROR, 
+			    "CREATE TABLE operation is not supported by the database server");
+		return FALSE;
+	}
+	else
+	{
 	
-	server = gda_connection_get_provider_obj(cnn);
+		op = gda_server_provider_create_operation (server, cnn, 
+							   GDA_SERVER_OPERATION_CREATE_TABLE, NULL, error);
 	
-	op = gda_server_provider_create_operation (server, cnn, 
-						   GDA_SERVER_OPERATION_CREATE_TABLE, NULL, error);
-	if (GDA_IS_SERVER_OPERATION (op)) {
+		GError *gda_returned_error = NULL;
 		va_list  args;
 		gchar   *arg;
 		GType    type;
 		gchar   *dbms_type;
-		xmlDocPtr parameters;
-		xmlNodePtr root;
-		xmlNodePtr table, op_data, array_data, array_row, array_value;
-		
+		GdaGeneralCreateTableFlag flag;
+		gint i;
+	
 		if (table_name == NULL) {
 			g_message("Table name is NULL!");      
-			g_set_error (error, GDA_GENERAL_ERROR, GDA_GENERAL_OBJECT_NAME_ERROR, 
-				    "Couldn't create table with a NULL string");
-			return FALSE;    
+			*error = g_error_new (GDA_GENERAL_ERROR, GDA_GENERAL_OBJECT_NAME_ERROR, 
+									"Couldn't create table with a NULL string");
+			return FALSE;
 		}
-		
 	
-		/* Initation of the xmlDoc */
-		parameters = xmlNewDoc ((xmlChar*)"1.0");
-		
-		root = xmlNewDocNode (parameters, NULL, (xmlChar*)"serv_op_data", NULL);
-		xmlDocSetRootElement (parameters, root);
-		table = xmlNewChild (root, NULL, (xmlChar*)"op_data", (xmlChar*)table_name);
-		xmlSetProp(table, (xmlChar*)"path", (xmlChar*)"/TABLE_DEF_P/TABLE_NAME");
-
-		op_data = xmlNewChild (root, NULL, (xmlChar*)"op_data", NULL);
-		xmlSetProp(op_data, (xmlChar*)"path", (xmlChar*)"/FIELDS_A");
-		array_data = xmlNewChild (op_data, NULL, (xmlChar*)"gda_array_data", NULL);
-			
+		gda_server_operation_set_value_at (op, table_name, error, "/TABLE_DEF_P/TABLE_NAME");
+				
 		va_start (args, error);
 		type = 0;
 		arg = NULL;
+		i = 0;
 		
 		while ((arg = va_arg (args, gchar*))) {
-			g_message("Getting the arguments...");			
+			/* First argument for Column's name */			
+			gda_server_operation_set_value_at (op, arg, error, "/FIELDS_A/@COLUMN_NAME/%d", i);
+		
+			/* Second to Define column's type */
 			type = va_arg (args, GType);
 			if (type == 0) {
-				g_set_error(error, GDA_GENERAL_ERROR, GDA_GENERAL_INCORRECT_VALUE_ERROR, 
-					    "Error the number of arguments are incorrect; couldn't create the table");
+				*error = g_error_new (GDA_GENERAL_ERROR, 
+									  GDA_GENERAL_INCORRECT_VALUE_ERROR, 
+									  "Error the number of arguments are incorrect; \
+									  couldn't create the table");
 				g_object_unref (op);
-				xmlFreeDoc(parameters);
 				return FALSE;
 			}
-			
 			dbms_type = (gchar *) gda_server_provider_get_default_dbms_type (server, 
 											 cnn, type);
-			array_row = xmlNewChild (array_data, NULL, (xmlChar*)"gda_array_row", NULL);
-			array_value = xmlNewChild (array_row, NULL, (xmlChar*)"gda_array_value", (xmlChar*)arg);
-			xmlSetProp(array_value, (xmlChar*)"colid", (xmlChar*)"COLUMN_NAME");
+			gda_server_operation_set_value_at (op, dbms_type, error, "/FIELDS_A/@COLUMN_TYPE/%d", i);
 		
-			array_value = xmlNewChild(array_row, NULL, (xmlChar*)"gda_array_value", (xmlChar*)dbms_type);
-			xmlSetProp(array_value, (xmlChar*)"colid", (xmlChar*)"COLUMN_TYPE");
-			
+			/* Third for column's flags */
+			flag = va_arg (args, GdaGeneralCreateTableFlag);
+			switch (flag)
+			{
+				case GDA_GENERAL_CREATE_TABLE_NOTHING_FLAG:
+					break;
+				case GDA_GENERAL_CREATE_TABLE_PKEY_FLAG:
+				{
+					gda_server_operation_set_value_at (op, "TRUE", error, "/FIELDS_A/@COLUMN_PKEY/%d", i);
+					break;
+				}
+				case GDA_GENERAL_CREATE_TABLE_NOT_NULL_FLAG:
+				{
+					gda_server_operation_set_value_at (op, "TRUE", error, "/FIELDS_A/@COLUMN_NNUL/%d", i);
+					break;
+				}
+				case GDA_GENERAL_CREATE_TABLE_AUTOINC_FLAG:
+				{
+					gda_server_operation_set_value_at (op, "TRUE", error, "/FIELDS_A/@COLUMN_AUTOINC/%d", i);
+					break;
+				}
+				case GDA_GENERAL_CREATE_TABLE_PKEY_AUTOINC_FLAG:
+				{
+					GValue *val;
+					
+					gda_server_operation_set_value_at (op, "TRUE", error, "/FIELDS_A/@COLUMN_PKEY/%d", i);
+					
+					gda_server_operation_set_value_at (op, "TRUE", error, "/FIELDS_A/@COLUMN_AUTOINC/%d", i);
+					
+					break;
+				}
+			}
+			i++;
 		}
 		
+	
 		va_end(args);
 		
-		if (!gda_server_operation_load_data_from_xml (op, root, error)) {
-			/* error */
-			g_set_error (error, GDA_GENERAL_ERROR, GDA_GENERAL_OPERATION_ERROR, 
-				     "The XML operation doesn't exist or could't be loaded");
-			g_object_unref (op);
-			xmlFreeDoc(parameters);
-			return FALSE;
-		}
-		else {
-			if (gda_server_provider_perform_operation (server, cnn, op, error)) {
+		if (!gda_server_provider_perform_operation (server, cnn, op, &gda_returned_error)) {
 				/* error */
-				g_set_error(error, GDA_GENERAL_ERROR, GDA_GENERAL_OPERATION_ERROR, 
-					    "The Server couldn't perform the CREATE TABLE operation!");
+				*error = g_error_new (GDA_GENERAL_ERROR, GDA_GENERAL_OPERATION_ERROR, 
+						"The Server couldn't perform the CREATE TABLE operation!. \
+						Provider Error Message: '%s'", gda_returned_error->message);
 				g_object_unref (op);
-				xmlFreeDoc(parameters);
 				return FALSE;
-			}
 		}
-		
+
 		g_object_unref (op);
-		xmlFreeDoc(parameters);
+		return TRUE;
 	}
-	else {
-		g_set_error(error, GDA_GENERAL_ERROR, GDA_GENERAL_OBJECT_NAME_ERROR, 
-			    "The Server doesn't support the CREATE TABLE operation!");
-		return FALSE;
-	}
-	return TRUE;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]