[libgda] Implementing GdaDdlModifiable for DbColumn and DbTable
- From: Pavlo Solntsev <psolntsev src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Implementing GdaDdlModifiable for DbColumn and DbTable
- Date: Sun, 12 Jul 2020 03:38:57 +0000 (UTC)
commit 510d1a12fee7f7edb29900386553d95bd3004b0f
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Thu May 28 08:41:33 2020 -0500
Implementing GdaDdlModifiable for DbColumn and DbTable
libgda/gda-db-column.c | 224 ++++++++++++++++++++++++++++++++++-
libgda/gda-db-table.c | 165 ++++++--------------------
tests/test-server-operation-sqlite.c | 87 ++++++++++++--
3 files changed, 339 insertions(+), 137 deletions(-)
---
diff --git a/libgda/gda-db-column.c b/libgda/gda-db-column.c
index 344fae47e..6b50a0e68 100644
--- a/libgda/gda-db-column.c
+++ b/libgda/gda-db-column.c
@@ -26,6 +26,8 @@
#include "gda-db-buildable.h"
#include "gda-server-provider.h"
#include "gda-db-column-private.h"
+#include "gda-ddl-modifiable.h"
+#include "gda-lockable.h"
G_DEFINE_QUARK (gda-db-column-error, gda_db_column_error)
@@ -36,6 +38,7 @@ typedef struct
gchar *mp_comment;
gchar *mp_default; /* property */
gchar *mp_check;
+ gchar *mp_table; /* Property */
GType m_gtype;
@@ -112,11 +115,22 @@ static const gchar *gdadbcolumnnode[GDA_DB_COLUMN_N_NODES] = {
static void
gda_db_column_buildable_interface_init (GdaDbBuildableInterface *iface);
+static void gda_ddl_modifiable_interface_init (GdaDdlModifiableInterface *iface);
+
+static gboolean gda_db_column_create (GdaDdlModifiable *self, GdaConnection *cnc,
+ gpointer user_data, GError **error);
+static gboolean gda_db_column_drop (GdaDdlModifiable *self, GdaConnection *cnc,
+ gpointer user_data, GError **error);
+static gboolean gda_db_column_rename (GdaDdlModifiable *old_name, GdaConnection *cnc,
+ gpointer new_name, GError **error);
G_DEFINE_TYPE_WITH_CODE (GdaDbColumn, gda_db_column, G_TYPE_OBJECT,
G_ADD_PRIVATE (GdaDbColumn)
G_IMPLEMENT_INTERFACE (GDA_TYPE_DB_BUILDABLE,
- gda_db_column_buildable_interface_init))
+ gda_db_column_buildable_interface_init)
+ G_IMPLEMENT_INTERFACE (GDA_TYPE_DDL_MODIFIABLE,
+ gda_ddl_modifiable_interface_init))
+
enum {
PROP_0,
PROP_COLUMN_NAME,
@@ -129,6 +143,7 @@ enum {
PROP_COLUMN_DEFAULT,
PROP_COLUMN_CHECK,
PROP_COLUMN_SCALE,
+ PROP_COLUMN_TABLE,
/*<private>*/
N_PROPS
};
@@ -163,6 +178,7 @@ gda_db_column_finalize (GObject *object)
g_free (priv->mp_type);
g_free (priv->mp_default);
g_free (priv->mp_check);
+ g_free (priv->mp_table);
G_OBJECT_CLASS (gda_db_column_parent_class)->finalize (object);
}
@@ -207,6 +223,9 @@ gda_db_column_get_property (GObject *object,
case PROP_COLUMN_SCALE:
g_value_set_uint (value, priv->m_scale);
break;
+ case PROP_COLUMN_TABLE:
+ g_value_set_string (value, priv->mp_table);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -257,6 +276,10 @@ gda_db_column_set_property (GObject *object,
case PROP_COLUMN_SCALE:
priv->m_scale = g_value_get_uint (value);
break;
+ case PROP_COLUMN_TABLE:
+ g_free (priv->mp_table);
+ priv->mp_table = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -303,6 +326,10 @@ gda_db_column_class_init (GdaDbColumnClass *klass)
properties[PROP_COLUMN_SCALE] =
g_param_spec_uint ("scale", "Scale", "Number of decimal for numeric type", 0, 64, 2,
G_PARAM_READWRITE);
+
+ properties[PROP_COLUMN_TABLE] =
+ g_param_spec_string ("table", "Table", "Parent table", NULL, G_PARAM_READWRITE);
+
g_object_class_install_properties (object_class, N_PROPS, properties);
}
@@ -322,6 +349,7 @@ gda_db_column_init (GdaDbColumn *self)
priv->m_pkey = FALSE;
priv->mp_default = NULL;
priv->mp_comment = NULL;
+ priv->mp_table = NULL;
}
/**
@@ -556,6 +584,14 @@ gda_db_column_buildable_interface_init (GdaDbBuildableInterface *iface)
iface->write_node = gda_db_column_write_node;
}
+static void
+gda_ddl_modifiable_interface_init (GdaDdlModifiableInterface *iface)
+{
+ iface->create = gda_db_column_create;
+ iface->drop = gda_db_column_drop;
+ iface->rename = gda_db_column_rename;
+}
+
static void
_gda_db_column_set_type (GdaDbColumn *self,
const char *type,
@@ -1259,3 +1295,189 @@ gda_db_column_new_from_meta (GdaMetaTableColumn *column)
return gdacolumn;
}
+static gboolean
+gda_db_column_create (GdaDdlModifiable *self,
+ GdaConnection *cnc,
+ gpointer user_data,
+ GError **error)
+{
+
+ G_DEBUG_HERE();
+ GdaServerOperation *op = NULL;
+ GdaServerProvider *provider = NULL;
+ gchar *buffer_str = NULL;
+ GdaDbTable *table = GDA_DB_TABLE (user_data);
+ GdaDbColumn *column = GDA_DB_COLUMN (self);
+
+ g_return_val_if_fail(GDA_IS_DDL_MODIFIABLE (self), FALSE);
+ g_return_val_if_fail(GDA_IS_CONNECTION (cnc), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+
+ const gchar *strtype;
+
+ if (!gda_connection_is_opened (cnc))
+ {
+ g_set_error (error, GDA_DB_TABLE_ERROR, GDA_DB_TABLE_CONNECTION_NOT_OPENED,
+ _("Connection is not opened"));
+ return FALSE;
+ }
+
+ gda_lockable_lock (GDA_LOCKABLE (cnc));
+
+ provider = gda_connection_get_provider (cnc);
+
+ op = gda_server_provider_create_operation (provider, cnc, GDA_SERVER_OPERATION_ADD_COLUMN,
+ NULL, error);
+
+ if (!op)
+ {
+ g_set_error (error, GDA_DB_TABLE_ERROR, GDA_DB_TABLE_SERVER_OPERATION,
+ _("ServerOperation is NULL"));
+ goto on_error;
+ }
+
+ if (!gda_server_operation_set_value_at (op, gda_db_base_get_full_name (GDA_DB_BASE (table)),
+ error, "/COLUMN_DEF_P/TABLE_NAME"))
+ goto on_error;
+
+ if (!gda_server_operation_set_value_at (op, gda_db_column_get_name (column),
+ error, "/COLUMN_DEF_P/COLUMN_NAME"))
+ goto on_error;
+
+ strtype = gda_server_provider_get_default_dbms_type (gda_connection_get_provider (cnc),
+ cnc, gda_db_column_get_gtype(column));
+
+ if (!gda_server_operation_set_value_at (op, strtype,
+ error, "/COLUMN_DEF_P/COLUMN_TYPE"))
+ goto on_error;
+
+ guint size = gda_db_column_get_size (column);
+
+ buffer_str = g_strdup_printf("%d", size);
+
+ if (!gda_server_operation_set_value_at (op, buffer_str,
+ error, "/COLUMN_DEF_P/COLUMN_SIZE"))
+ goto on_error;
+
+ g_free (buffer_str);
+ buffer_str = NULL;
+
+ guint scale = gda_db_column_get_scale (column);
+
+ buffer_str = g_strdup_printf("%d", scale);
+
+ if (!gda_server_operation_set_value_at (op, buffer_str,
+ error, "/COLUMN_DEF_P/COLUMN_SCALE"))
+ goto on_error;
+
+ g_free (buffer_str);
+ buffer_str = NULL;
+
+ if (!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (gda_db_column_get_nnul (column)),
+ error, "/COLUMN_DEF_P/COLUMN_NNUL"))
+ goto on_error;
+
+ if (!gda_server_provider_perform_operation (provider, cnc, op, error))
+ goto on_error;
+
+ g_object_unref (op);
+
+ gda_lockable_unlock (GDA_LOCKABLE (cnc));
+
+ return TRUE;
+
+on_error:
+ if (op)
+ g_object_unref (op);
+
+ if (buffer_str)
+ g_free (buffer_str);
+
+ gda_lockable_unlock (GDA_LOCKABLE (cnc));
+
+ return FALSE;
+}
+
+static gboolean
+gda_db_column_drop (GdaDdlModifiable *self,
+ GdaConnection *cnc,
+ gpointer user_data,
+ GError **error)
+{
+ return FALSE;
+}
+
+static gboolean
+gda_db_column_rename (GdaDdlModifiable *self,
+ GdaConnection *cnc,
+ gpointer user_data,
+ GError **error)
+{
+ G_DEBUG_HERE();
+ GdaServerOperation *op = NULL;
+ GdaServerProvider *provider = NULL;
+ gchar *table = NULL;
+ GdaDbColumn *column = GDA_DB_COLUMN (self);
+ GdaDbColumn *column_new = GDA_DB_COLUMN (user_data);
+
+ g_return_val_if_fail(GDA_IS_DDL_MODIFIABLE (self), FALSE);
+ g_return_val_if_fail(GDA_IS_CONNECTION (cnc), FALSE);
+
+ if (!gda_connection_is_opened (cnc))
+ {
+ g_set_error (error, GDA_DB_TABLE_ERROR, GDA_DB_TABLE_CONNECTION_NOT_OPENED,
+ _("Connection is not opened"));
+ return FALSE;
+ }
+
+ gda_lockable_lock (GDA_LOCKABLE (cnc));
+
+ provider = gda_connection_get_provider (cnc);
+
+ op = gda_server_provider_create_operation (provider, cnc, GDA_SERVER_OPERATION_RENAME_COLUMN,
+ NULL, error);
+
+ if (!op)
+ {
+ g_set_error (error, GDA_DB_TABLE_ERROR, GDA_DB_TABLE_SERVER_OPERATION,
+ _("ServerOperation is NULL"));
+ goto on_error;
+ }
+
+ g_object_get (column, "table", &table, NULL);
+
+ if (!table)
+ goto on_error;
+
+ if (!gda_server_operation_set_value_at (op, table,
+ error, "/COLUMN_DEF_P/TABLE_NAME"))
+ goto on_error;
+
+ if (!gda_server_operation_set_value_at (op, gda_db_column_get_name (column),
+ error, "/COLUMN_DEF_P/COLUMN_NAME"))
+ goto on_error;
+
+ if (!gda_server_operation_set_value_at (op, gda_db_column_get_name (column_new),
+ error, "/COLUMN_DEF_P/COLUMN_NAME_NEW"))
+ goto on_error;
+
+ if (!gda_server_provider_perform_operation (provider, cnc, op, error))
+ goto on_error;
+
+ g_object_unref (op);
+
+ gda_lockable_unlock (GDA_LOCKABLE (cnc));
+
+ return TRUE;
+
+on_error:
+ if (op)
+ g_object_unref (op);
+
+ if (table)
+ g_free (table);
+
+ gda_lockable_unlock (GDA_LOCKABLE (cnc));
+
+ return FALSE;
+}
diff --git a/libgda/gda-db-table.c b/libgda/gda-db-table.c
index db2a9682f..27804829b 100644
--- a/libgda/gda-db-table.c
+++ b/libgda/gda-db-table.c
@@ -27,6 +27,7 @@
#include "gda-server-provider.h"
#include "gda-connection.h"
#include "gda-meta-struct.h"
+#include "gda-ddl-modifiable.h"
#include <glib/gi18n-lib.h>
G_DEFINE_QUARK (gda_db_table_error, gda_db_table_error)
@@ -62,11 +63,21 @@ typedef struct
*/
static void gda_db_table_buildable_interface_init (GdaDbBuildableInterface *iface);
+static void gda_ddl_modifiable_interface_init (GdaDdlModifiableInterface *iface);
+
+static gboolean gda_db_table_create (GdaDdlModifiable *self, GdaConnection *cnc,
+ gpointer user_data, GError **error);
+static gboolean gda_db_table_drop (GdaDdlModifiable *self, GdaConnection *cnc,
+ gpointer user_data, GError **error);
+static gboolean gda_db_table_rename (GdaDdlModifiable *old_name, GdaConnection *cnc,
+ gpointer new_name, GError **error);
G_DEFINE_TYPE_WITH_CODE (GdaDbTable, gda_db_table, GDA_TYPE_DB_BASE,
G_ADD_PRIVATE (GdaDbTable)
G_IMPLEMENT_INTERFACE (GDA_TYPE_DB_BUILDABLE,
- gda_db_table_buildable_interface_init))
+ gda_db_table_buildable_interface_init)
+ G_IMPLEMENT_INTERFACE (GDA_TYPE_DDL_MODIFIABLE,
+ gda_ddl_modifiable_interface_init))
enum {
PROP_0,
@@ -351,6 +362,13 @@ gda_db_table_buildable_interface_init (GdaDbBuildableInterface *iface)
iface->write_node = gda_db_table_write_node;
}
+static void
+gda_ddl_modifiable_interface_init (GdaDdlModifiableInterface *iface)
+{
+ iface->create = gda_db_table_create;
+ iface->drop = gda_db_table_drop;
+ iface->rename = gda_db_table_rename;
+}
/**
* gda_db_table_set_comment:
* @self: an #GdaDbTable object
@@ -742,10 +760,10 @@ on_error:
* Stability: Stable
* Since: 6.0
*/
-gboolean
-gda_db_table_create (GdaDbTable *self,
+static gboolean
+gda_db_table_create (GdaDdlModifiable *self,
GdaConnection *cnc,
- gboolean ifnotexists,
+ gpointer user_data,
GError **error)
{
g_return_val_if_fail (GDA_IS_DB_TABLE (self), FALSE);
@@ -758,6 +776,8 @@ gda_db_table_create (GdaDbTable *self,
GdaServerOperation *op = NULL;
gboolean res = FALSE;
+ GdaDbTable *table = GDA_DB_TABLE (self);
+
provider = gda_connection_get_provider (cnc);
op = gda_server_provider_create_operation (provider,
@@ -769,7 +789,7 @@ gda_db_table_create (GdaDbTable *self,
{
g_object_set_data_full (G_OBJECT (op), "connection", g_object_ref (cnc), g_object_unref);
- if (gda_db_table_prepare_create (self, op, ifnotexists, error))
+ if (gda_db_table_prepare_create (table, op, TRUE, error))
{
#ifdef GDA_DEBUG
gchar* str = gda_server_operation_render (op, error);
@@ -840,21 +860,24 @@ gda_db_table_append_fkey (GdaDbTable *self,
* Stability: Stable
* Since: 6.0
*/
-gboolean
-gda_db_table_rename (GdaDbTable *old_name,
- GdaDbTable *new_name,
+static gboolean
+gda_db_table_rename (GdaDdlModifiable *old_name,
GdaConnection *cnc,
+ gpointer new_name,
GError **error)
{
G_DEBUG_HERE();
GdaServerOperation *op = NULL;
GdaServerProvider *provider = NULL;
+ GdaDbTable *new_name_table = NULL;
g_return_val_if_fail(GDA_IS_DB_TABLE (old_name), FALSE);
- g_return_val_if_fail(GDA_IS_DB_TABLE (old_name), FALSE);
+ g_return_val_if_fail(new_name, FALSE);
g_return_val_if_fail(GDA_IS_CONNECTION (cnc), FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+ new_name_table = GDA_DB_TABLE (new_name);
+
if (!gda_connection_is_opened (cnc))
{
g_warning ("Connection is not opened");
@@ -874,7 +897,7 @@ gda_db_table_rename (GdaDbTable *old_name,
error, "/TABLE_DESC_P/TABLE_NAME"))
goto on_error;
- if (!gda_server_operation_set_value_at (op, gda_db_base_get_full_name (GDA_DB_BASE (new_name)),
+ if (!gda_server_operation_set_value_at (op, gda_db_base_get_full_name (GDA_DB_BASE (new_name_table)),
error, "/TABLE_DESC_P/TABLE_NEW_NAME"))
goto on_error;
@@ -896,120 +919,6 @@ on_error:
return FALSE;
}
-/**
- * gda_db_table_add_column:
- * @self: an instance of #GdaDbTable where table should be added
- * @col: a column to add
- * @cnc: an opened connection to use
- * @error: An error container
- *
- * This is a convenient method to add a column @col to the table @self.
- *
- * Returns: %TRUE if no error occures and %FALSE otherwise
- *
- * Stability: Stable
- * Since: 6.0
- */
-gboolean
-gda_db_table_add_column (GdaDbTable *self,
- GdaDbColumn *col,
- GdaConnection *cnc,
- GError **error)
-{
- G_DEBUG_HERE();
- GdaServerOperation *op = NULL;
- GdaServerProvider *provider = NULL;
- gchar *buffer_str = NULL;
-
- g_return_val_if_fail(GDA_IS_DB_TABLE (self), FALSE);
- g_return_val_if_fail(GDA_IS_DB_COLUMN (col), FALSE);
- g_return_val_if_fail(GDA_IS_CONNECTION (cnc), FALSE);
- g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
-
- const gchar *strtype;
-
- if (!gda_connection_is_opened (cnc))
- {
- g_set_error (error, GDA_DB_TABLE_ERROR, GDA_DB_TABLE_CONNECTION_NOT_OPENED,
- _("Connection is not opened"));
- return FALSE;
- }
-
- gda_lockable_lock (GDA_LOCKABLE (cnc));
-
- provider = gda_connection_get_provider (cnc);
-
- op = gda_server_provider_create_operation (provider, cnc, GDA_SERVER_OPERATION_ADD_COLUMN,
- NULL, error);
-
- if (!op)
- {
- g_set_error (error, GDA_DB_TABLE_ERROR, GDA_DB_TABLE_SERVER_OPERATION,
- _("ServerOperation is NULL"));
- goto on_error;
- }
-
- if (!gda_server_operation_set_value_at (op, gda_db_base_get_full_name (GDA_DB_BASE (self)),
- error, "/COLUMN_DEF_P/TABLE_NAME"))
- goto on_error;
-
- if (!gda_server_operation_set_value_at (op, gda_db_column_get_name (col),
- error, "/COLUMN_DEF_P/COLUMN_NAME"))
- goto on_error;
-
- strtype = gda_server_provider_get_default_dbms_type (gda_connection_get_provider (cnc),
- cnc, gda_db_column_get_gtype(col));
-
- if (!gda_server_operation_set_value_at (op, strtype,
- error, "/COLUMN_DEF_P/COLUMN_TYPE"))
- goto on_error;
-
- guint size = gda_db_column_get_size (col);
-
- buffer_str = g_strdup_printf("%d", size);
-
- if (!gda_server_operation_set_value_at (op, buffer_str,
- error, "/COLUMN_DEF_P/COLUMN_SIZE"))
- goto on_error;
-
- g_free (buffer_str);
- buffer_str = NULL;
-
- guint scale = gda_db_column_get_scale (col);
-
- buffer_str = g_strdup_printf("%d", scale);
-
- if (!gda_server_operation_set_value_at (op, buffer_str,
- error, "/COLUMN_DEF_P/COLUMN_SCALE"))
- goto on_error;
-
- g_free (buffer_str);
- buffer_str = NULL;
-
- if (!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (gda_db_column_get_nnul (col)),
- error, "/COLUMN_DEF_P/COLUMN_NNUL"))
- goto on_error;
-
- if (!gda_server_provider_perform_operation (provider, cnc, op, error))
- goto on_error;
-
- g_object_unref (op);
-
- gda_lockable_unlock (GDA_LOCKABLE (cnc));
-
- return TRUE;
-
-on_error:
- if (op)
- g_object_unref (op);
-
- if (buffer_str)
- g_free (buffer_str);
-
- gda_lockable_unlock (GDA_LOCKABLE (cnc));
-
- return FALSE;
-}
/**
* gda_db_table_drop:
@@ -1025,10 +934,10 @@ on_error:
* Stability: Stable
* Since: 6.0
*/
-gboolean
-gda_db_table_drop (GdaDbTable *self,
+static gboolean
+gda_db_table_drop (GdaDdlModifiable *self,
GdaConnection *cnc,
- gboolean ifexists,
+ gpointer user_data,
GError **error)
{
G_DEBUG_HERE();
@@ -1063,7 +972,7 @@ gda_db_table_drop (GdaDbTable *self,
"/TABLE_DESC_P/TABLE_NAME"))
goto on_error;
- if (!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (ifexists), error,
+ if (!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (TRUE), error,
"/TABLE_DESC_P/TABLE_IFEXISTS"))
goto on_error;
diff --git a/tests/test-server-operation-sqlite.c b/tests/test-server-operation-sqlite.c
index e367d0007..113071115 100644
--- a/tests/test-server-operation-sqlite.c
+++ b/tests/test-server-operation-sqlite.c
@@ -34,6 +34,7 @@
* Employee table will be renamed to NewEmployee
*
*/
+#include "gda-db-column.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <locale.h>
@@ -859,7 +860,7 @@ test_server_operation_operations_db (TestObjectFixture *fixture,
g_object_unref (pname);
/* Create table */
- gboolean res = gda_db_table_create (tproject, fixture->cnc, TRUE, NULL);
+ gboolean res = gda_ddl_modifiable_create (GDA_DDL_MODIFIABLE (tproject), fixture->cnc, NULL, NULL);
g_assert_true (res);
@@ -918,7 +919,7 @@ test_server_operation_operations_db (TestObjectFixture *fixture,
g_object_unref (fkey);
- res = gda_db_table_create (temployee, fixture->cnc, TRUE, NULL);
+ res = gda_ddl_modifiable_create (GDA_DDL_MODIFIABLE (temployee), fixture->cnc, NULL, NULL);
g_assert_true (res);
@@ -930,7 +931,7 @@ test_server_operation_operations_db (TestObjectFixture *fixture,
gda_db_column_set_scale (cost, 2);
gda_db_column_set_nnul (cost, FALSE);
- res = gda_db_table_add_column (tproject, cost, fixture->cnc, NULL);
+ res = gda_ddl_modifiable_create (GDA_DDL_MODIFIABLE (tproject), fixture->cnc, cost, NULL);
g_assert_true (res);
@@ -941,7 +942,7 @@ test_server_operation_operations_db (TestObjectFixture *fixture,
GdaDbTable *new_table = gda_db_table_new ();
gda_db_base_set_name (GDA_DB_BASE (new_table), "NewEmployee");
- res = gda_db_table_rename (temployee, new_table, fixture->cnc, NULL);
+ res = gda_ddl_modifiable_rename (GDA_DDL_MODIFIABLE (temployee), fixture->cnc, new_table, NULL);
g_assert_true (res);
@@ -950,10 +951,12 @@ test_server_operation_operations_db (TestObjectFixture *fixture,
gda_db_view_set_istemp (myview, FALSE);
gda_db_view_set_defstring (myview, "SELECT name, project_id FROM NewEmployee");
- res = gda_db_view_create (myview, fixture->cnc, TRUE, NULL);
+ res = gda_ddl_modifiable_create (GDA_DDL_MODIFIABLE (myview), fixture->cnc, NULL, NULL);
/* DROP_VIEW operation. We will reuse the view */
- res = gda_db_view_drop (myview, fixture->cnc, TRUE, GDA_DB_VIEW_RESTRICT, NULL);
+ GdaDbViewRefAction action = GDA_DB_VIEW_RESTRICT;
+
+ res = gda_ddl_modifiable_drop (GDA_DDL_MODIFIABLE (myview), fixture->cnc, &action, NULL);
g_assert_true (res);
@@ -980,15 +983,77 @@ test_server_operation_operations_db (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_db_index_drop (index, fixture->cnc, TRUE, NULL);
+ res = gda_ddl_modifiable_drop (GDA_DDL_MODIFIABLE (index), fixture->cnc, NULL, NULL);
g_assert_true (res);
- res = gda_db_table_drop (new_table, fixture->cnc, TRUE, NULL);
+ res = gda_ddl_modifiable_drop (GDA_DDL_MODIFIABLE (new_table), fixture->cnc, NULL, NULL);
g_assert_true (res);
}
+static void
+test_server_operation_operations_db_rename_column (TestObjectFixture *fixture,
+ G_GNUC_UNUSED gconstpointer user_data)
+{
+
+/* Define table Project */
+ GdaDbTable *tproject = gda_db_table_new ();
+ gda_db_base_set_name (GDA_DB_BASE (tproject), "Project");
+ gda_db_table_set_is_temp (tproject, FALSE);
+
+ /* Defining column id */
+ GdaDbColumn *pid = gda_db_column_new ();
+ gda_db_column_set_name (pid, "id");
+ gda_db_column_set_type (pid, G_TYPE_INT);
+ gda_db_column_set_nnul (pid, TRUE);
+ gda_db_column_set_autoinc (pid, TRUE);
+ gda_db_column_set_unique (pid, TRUE);
+ gda_db_column_set_pkey (pid, TRUE);
+
+ gda_db_table_append_column (tproject, pid);
+
+ g_object_unref (pid);
+
+ /* Defining column name */
+ GdaDbColumn *pname = gda_db_column_new ();
+ gda_db_column_set_name (pname, "name");
+ gda_db_column_set_type (pname, G_TYPE_STRING);
+ gda_db_column_set_size (pname, 50);
+ gda_db_column_set_nnul (pname, TRUE);
+ gda_db_column_set_autoinc (pname, FALSE);
+ gda_db_column_set_unique (pname, TRUE);
+ gda_db_column_set_pkey (pname, FALSE);
+ gda_db_column_set_default (pname, "Default_name");
+
+ gda_db_table_append_column (tproject, pname);
+
+/* Create table */
+ gboolean res = gda_ddl_modifiable_create (GDA_DDL_MODIFIABLE (tproject), fixture->cnc, NULL, NULL);
+
+ g_assert_true (res);
+
+ g_object_set (pname, "table", gda_db_base_get_name (GDA_DB_BASE (tproject)), NULL);
+
+ GdaDbColumn *new_column = gda_db_column_new();
+ gda_db_column_set_name (new_column, "name_new");
+ gda_db_column_set_type (new_column, G_TYPE_STRING);
+
+ GError *error = NULL;
+
+ res = gda_ddl_modifiable_rename (GDA_DDL_MODIFIABLE (pname), fixture->cnc, new_column, &error);
+
+ if (error != NULL) {
+ g_print ("Error: %s", error->message != NULL ? error->message : "No detail");
+ g_clear_error (&error);
+ }
+
+ g_assert_true (res);
+
+ g_object_unref (new_column);
+ g_object_unref (tproject);
+}
+
gint
main(gint argc, gchar *argv[])
{
@@ -1010,6 +1075,12 @@ main(gint argc, gchar *argv[])
test_server_operation_operations_db,
test_server_operation_finish);
+ g_test_add ("/test-server-operation-sqlite/gda-db-rename_column",
+ TestObjectFixture,
+ NULL,
+ test_server_operation_start,
+ test_server_operation_operations_db_rename_column,
+ test_server_operation_finish);
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]