[libgda: 4/17] DB: API reimplemented, misc corrections



commit 23622508bf286866b762f598966fc4ba3bd06034
Author: Pavlo Solntsev <p sun fun gmail com>
Date:   Mon Mar 18 13:35:50 2019 -0500

    DB: API reimplemented, misc corrections
    
    The implementation for gda_db_column_prepare_add was modified. Becasue
    of missuse of the API.
    Misc formating corrections.

 libgda/gda-db-column.c | 61 ++++++++++++++++++++++++++++++++------------------
 libgda/gda-db-column.h |  6 +++--
 2 files changed, 43 insertions(+), 24 deletions(-)
---
diff --git a/libgda/gda-db-column.c b/libgda/gda-db-column.c
index d7bb71d5c..cc3810d4b 100644
--- a/libgda/gda-db-column.c
+++ b/libgda/gda-db-column.c
@@ -24,7 +24,6 @@
 #include <glib/gi18n-lib.h>
 #include "gda-util.h"
 #include "gda-db-buildable.h"
-#include "gda-db-base.h"
 #include "gda-server-provider.h"
 
 G_DEFINE_QUARK (gda-db-column-error, gda_db_column_error)
@@ -1007,7 +1006,7 @@ gda_db_column_prepare_create  (GdaDbColumn *self,
 
   cnc = (GdaConnection*) g_object_get_data (G_OBJECT (op), "connection");
 
-  if (cnc == NULL) 
+  if (cnc == NULL)
     {
       g_set_error (error, GDA_DB_COLUMN_ERROR, GDA_DB_COLUMN_ERROR_TYPE,
                    _("Internal error: Operation should be prepared, setting a connection data"));
@@ -1093,27 +1092,42 @@ gda_db_column_prepare_create  (GdaDbColumn *self,
  * prepare @op for %GDA_SERVER_OPERATION_ADD_COLUMN operation.
  *
  * Returns: %TRUE if success, %FALSE otherwise.
+ *
+ * Since: 6.0
  */
 gboolean
 gda_db_column_prepare_add (GdaDbColumn *self,
                            GdaServerOperation *op,
                            GError **error)
 {
+  g_return_val_if_fail(GDA_IS_DB_COLUMN(self), FALSE);
+  g_return_val_if_fail(GDA_IS_SERVER_OPERATION(op), FALSE);
+  g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+
+  GdaServerOperationType sotype = gda_server_operation_get_op_type(op);
+
+  if (sotype != GDA_SERVER_OPERATION_ADD_COLUMN)
+    {
+      g_set_error(error, GDA_DB_COLUMN_ERROR, GDA_DB_COLUMN_ERROR_WRONG_OPERATION,
+                  "Wrong ServerOperation type");
+      return FALSE;
+    }
+
   GdaDbColumnPrivate *priv = gda_db_column_get_instance_private (self);
 
-  if(!gda_server_operation_set_value_at (op, priv->mp_name, error,
-                                        "/COLUMN_DEF_P/COLUMN_NAME"))
+  if (!gda_server_operation_set_value_at (op, priv->mp_name, error,
+                                          "/COLUMN_DEF_P/COLUMN_NAME"))
     return FALSE;
 
-  if(!gda_server_operation_set_value_at (op,priv->mp_type, error,
-                                        "/COLUMN_DEF_P/COLUMN_TYPE"))
+  if (!gda_server_operation_set_value_at (op,priv->mp_type, error,
+                                          "/COLUMN_DEF_P/COLUMN_TYPE"))
     return FALSE;
 
   gchar *sizestr = NULL;
   sizestr = g_strdup_printf ("%d", priv->m_size);
 
-  if(!gda_server_operation_set_value_at (op, sizestr, error,
-                                        "/COLUMN_DEF_P/COLUMN_SIZE"))
+  if (!gda_server_operation_set_value_at (op, sizestr, error,
+                                          "/COLUMN_DEF_P/COLUMN_SIZE"))
     {
       g_free (sizestr);
       return FALSE;
@@ -1121,28 +1135,31 @@ gda_db_column_prepare_add (GdaDbColumn *self,
   else
     g_free (sizestr);
 
-  if(!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_nnul), error,
-                                        "/COLUMN_DEF_P/COLUMN_NNUL"))
+  if (!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_nnul), error,
+                                          "/COLUMN_DEF_P/COLUMN_NNUL"))
     return FALSE;
 
-  if(!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_autoinc), error,
-                                        "/COLUMN_DEF_P/COLUMN_AUTOINC"))
+  if (!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_autoinc), error,
+                                          "/COLUMN_DEF_P/COLUMN_AUTOINC"))
     return FALSE;
 
-  if(!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_unique), error,
-                                        "/COLUMN_DEF_P/COLUMN_UNIQUE"))
-    return FALSE;
+  sizestr = g_strdup_printf("%d",priv->m_scale);
 
-  if(!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_pkey), error,
-                                        "/COLUMN_DEF_P/COLUMN_PKEY"))
-    return FALSE;
+  if (!gda_server_operation_set_value_at (op, sizestr, error,
+                                          "/COLUMN_DEF_P/COLUMN_SCALE"))
+    {
+      g_free (sizestr);
+      return FALSE;
+    }
+  else
+    g_free (sizestr);
 
-  if(!gda_server_operation_set_value_at (op, priv->mp_default, error,
-                                        "/COLUMN_DEF_P/COLUMN_DEFAULT"))
+  if (!gda_server_operation_set_value_at (op, priv->mp_default, error,
+                                          "/COLUMN_DEF_P/COLUMN_DEFAULT"))
     return FALSE;
 
-  if(!gda_server_operation_set_value_at (op, priv->mp_check, error,
-                                        "/COLUMN_DEF_P/COLUMN_CHECK"))
+  if (!gda_server_operation_set_value_at (op, priv->mp_check, error,
+                                          "/COLUMN_DEF_P/COLUMN_CHECK"))
     return FALSE;
 
   return TRUE;
diff --git a/libgda/gda-db-column.h b/libgda/gda-db-column.h
index 56482c8a5..48d8d258a 100644
--- a/libgda/gda-db-column.h
+++ b/libgda/gda-db-column.h
@@ -44,9 +44,10 @@ struct _GdaDbColumnClass
  *
  * Values used to describe the source of the error.
  */
-typedef  enum 
+typedef  enum
 {
-  GDA_DB_COLUMN_ERROR_TYPE
+  GDA_DB_COLUMN_ERROR_TYPE,
+  GDA_DB_COLUMN_ERROR_WRONG_OPERATION
 } GdaDbColumnError;
 
 #define GDA_DB_COLUMN_ERROR gda_db_column_error_quark()
@@ -106,6 +107,7 @@ gboolean        gda_db_column_prepare_create   (GdaDbColumn *self,
 gboolean        gda_db_column_prepare_add      (GdaDbColumn *self,
                                                 GdaServerOperation *op,
                                                 GError **error);
+
 G_END_DECLS
 
 #endif /* GDA_DB_COLUMN_H */


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