{
GdaConnection *gda_conn;
GdaSqlParser *gda_parser;
+ GdaServerProvider *gda_provider;
xmlDocPtr xml_doc;
xmlNodePtr xml_root;
priv->gda_conn= NULL;
return;
}
+
+ priv->gda_provider = gda_connection_get_provider (priv->gda_conn);
}
static gboolean
if (!dm)
{
/* table doesn't exist */
- GdaServerProvider *provider;
GdaServerOperation *op;
gint i;
/* create a new GdaServerOperation object */
- provider = gda_connection_get_provider (priv->gda_conn);
- op = gda_server_provider_create_operation (provider, priv->gda_conn, GDA_SERVER_OPERATION_CREATE_TABLE, NULL, &error);
+ op = gda_server_provider_create_operation (priv->gda_provider, priv->gda_conn, GDA_SERVER_OPERATION_CREATE_TABLE, NULL, &error);
if (!op)
{
g_warning ("CREATE TABLE operation is not supported by the provider: %s.",
*/
/* execute the operation */
- if (!gda_server_provider_perform_operation (provider, priv->gda_conn, op, &error))
+ if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
{
g_warning ("Error executing the operation: %s.",
error != NULL && error->message != NULL ? error->message : "No detail");
GError *error;
GdaStatement *stmt;
+ g_return_val_if_fail (id > 0, FALSE);
+
priv = DBT_GET_PRIVATE (dbt);
ret = FALSE;
gchar *str_operation_type;
GdaServerOperationType operation_type;
- GdaServerProvider *provider;
GError *error;
GdaServerOperation *op;
return FALSE;
}
- provider = gda_connection_get_provider (priv->gda_conn);
- if (gda_server_provider_supports_operation (provider, priv->gda_conn, operation_type, NULL))
+ if (gda_server_provider_supports_operation (priv->gda_provider, priv->gda_conn, operation_type, NULL))
{
error = NULL;
- op = gda_server_provider_create_operation (provider, priv->gda_conn, operation_type, NULL, &error);
+ op = gda_server_provider_create_operation (priv->gda_provider, priv->gda_conn, operation_type, NULL, &error);
if (!op)
{
g_warning ("Unable to create operation type \"%s\": %s.", str_operation_type,
}
else
{
- if (!gda_server_provider_perform_operation (provider, priv->gda_conn, op, &error))
+ if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
{
g_warning ("Error on executing GdaServerOperation from the file: %s.\n",
error != NULL && error->message != NULL ? error->message : "no detail");
return ret;
}
+static gboolean
+dbt_parse_rename_table (Dbt *dbt, xmlNodePtr xnode)
+{
+ DbtPrivate *priv;
+
+ gboolean ret;
+
+ xmlNodePtr cur;
+ gchar *table_name;
+ gchar *new_table_name;
+
+ GError *error;
+
+ ret = TRUE;
+
+ priv = DBT_GET_PRIVATE (dbt);
+
+ table_name = NULL;
+ new_table_name = NULL;
+ cur = xnode->children;
+ while (cur != NULL && ret)
+ {
+ if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
+ {
+ table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ }
+ else if (xmlStrcmp (cur->name, (const xmlChar *)"new_table_name") == 0)
+ {
+ new_table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ }
+
+ cur = cur->next;
+ }
+
+ if (table_name != NULL && g_strcmp0 (table_name, "") != 0
+ && new_table_name != NULL && g_strcmp0 (new_table_name, "") != 0)
+ {
+ GdaServerOperation *op;
+
+ error = NULL;
+ op = gda_server_provider_create_operation (priv->gda_provider,
+ priv->gda_conn,
+ GDA_SERVER_OPERATION_RENAME_TABLE,
+ NULL,
+ &error);
+ gda_server_operation_set_value_at (op, table_name, &error, "/TABLE_DESC_P/TABLE_NAME");
+ gda_server_operation_set_value_at (op, new_table_name, &error, "/TABLE_DESC_P/TABLE_NEW_NAME");
+
+ error = NULL;
+ if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ {
+ g_warning ("Error executing the operation: %s.",
+ error != NULL && error->message != NULL ? error->message : "No detail");
+ ret = FALSE;
+ }
+ g_object_unref (op);
+ }
+ else
+ {
+ g_warning ("You must provide the name of the table to drop.");
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
static gboolean
dbt_parse_drop_view (Dbt *dbt, xmlNodePtr xnode)
{
return ret;
}
+static gboolean
+dbt_parse_rename_view (Dbt *dbt, xmlNodePtr xnode)
+{
+ DbtPrivate *priv;
+
+ gboolean ret;
+
+ xmlNodePtr cur;
+ gchar *view_name;
+ gchar *new_view_name;
+
+ GError *error;
+
+ ret = TRUE;
+
+ priv = DBT_GET_PRIVATE (dbt);
+
+ view_name = NULL;
+ cur = xnode->children;
+ while (cur != NULL && ret)
+ {
+ if (xmlStrcmp (cur->name, (const xmlChar *)"view_name") == 0)
+ {
+ view_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ }
+ else if (xmlStrcmp (cur->name, (const xmlChar *)"new_view_name") == 0)
+ {
+ new_view_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ }
+
+ cur = cur->next;
+ }
+
+ if (view_name != NULL && g_strcmp0 (view_name, "") != 0
+ && new_view_name != NULL && g_strcmp0 (new_view_name, "") != 0)
+ {
+ gchar *sql;
+ GdaStatement *stmt;
+
+ sql = g_strdup_printf ("ALTER VIEW %s RENAME TO %s", view_name, new_view_name);
+
+ error = NULL;
+ stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error);
+ if (stmt == NULL)
+ {
+ g_warning ("Unable to create GdaStatement from sql: %s.\n%s",
+ error != NULL && error->message != NULL ? error->message : "no detail",
+ sql);
+ ret = FALSE;
+ }
+ else
+ {
+ guint nrows;
+
+ nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
+ if (nrows == -1)
+ {
+ g_warning ("NON SELECT error: %s.\n%s",
+ error != NULL && error->message != NULL ? error->message : "no detail",
+ sql);
+ ret = FALSE;
+ }
+ g_object_unref (stmt);
+ }
+ }
+ else
+ {
+ g_warning ("You must provide the name of the view to drop.");
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
/**
* dbt_transform:
* @dbt:
GError *error;
+ gchar *str_id;
guint id;
gboolean tosave;
{
tosave = TRUE;
- id = strtol (xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id"), NULL, 10);
+ str_id= xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id");
+ if (str_id == NULL)
+ {
+ g_warning ("Operation id cannot be minor equal to zero.");
+ continue;
+ }
+ id = strtol (str_id, NULL, 10);
if (dbt_check_to_execute (dbt, id))
{
{
tosave = dbt_parse_drop_table (dbt, xnode);
}
+ else if (xmlStrcmp (xnode->name, (const xmlChar *)"rename_table") == 0)
+ {
+ tosave = dbt_parse_rename_table (dbt, xnode);
+ }
else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_view") == 0)
{
tosave = dbt_parse_drop_view (dbt, xnode);
}
+ else if (xmlStrcmp (xnode->name, (const xmlChar *)"rename_view") == 0)
+ {
+ tosave = dbt_parse_rename_view (dbt, xnode);
+ }
else
{
g_warning ("Invalid tag: %s.", xnode->name);