static gboolean zak_dbt_dbt_check_db (ZakDbtDbt *zak_dbt_dbt, gboolean create_tables);
-static gboolean zak_dbt_dbt_parse_create_index (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode);
-static gboolean zak_dbt_dbt_parse_add_column (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode);
-static gboolean zak_dbt_dbt_parse_drop_column (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode);
+static gchar *zak_dbt_dbt_parse_create_index (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode);
+static gchar *zak_dbt_dbt_parse_add_column (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode);
+static gchar *zak_dbt_dbt_parse_drop_column (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode);
#define ZAK_DBT_DBT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_DBT_TYPE_DBT, ZakDbtDbtPrivate))
}
else
{
- guint nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
- if (nrows == -1)
+ if (gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error) == -1)
{
g_warning ("NON SELECT error: %s.\n%s",
error != NULL && error->message != NULL ? error->message : "no detail",
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_sql (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_sql (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
- ZakDbtDbtPrivate *priv;
-
- gchar *sql;
- GError *error;
- GdaStatement *stmt;
-
- gboolean ret;
-
- ret = TRUE;
-
- priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
-
- if (!GDA_IS_SQL_PARSER (priv->gda_parser))
- {
- g_warning ("Invalid sql parser.");
- return FALSE;
- }
-
- sql = (gchar *)xmlNodeGetContent (xnode);
-
- error = NULL;
- stmt = gda_sql_parser_parse_string (priv->gda_parser, g_strstrip (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);
- }
-
- return ret;
+ return g_strstrip ((gchar *)xmlNodeGetContent (xnode));
}
-static gboolean
-zak_dbt_dbt_parse_gda_op (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_gda_op (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *str_operation_type;
GdaServerOperationType operation_type;
GError *error;
GdaServerOperation *op;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlNodeIsText (cur))
{
if (xmlStrcmp (cur->name, (const xmlChar *)"serv_op_data") != 0)
{
g_warning ("Invalid tag \"%s\".", cur->name);
- ret = FALSE;
+ ret = NULL;
cur = cur->next;
continue;
}
if (operation_type == G_MAXINT)
{
g_warning ("Operation type \"%s\" not supported: %s.", str_operation_type,
- error != NULL && error->message != NULL ? error->message : "no detail");
- return FALSE;
+ error != NULL && error->message != NULL ? error->message : "no detail");
+ return NULL;
}
if (gda_server_provider_supports_operation (priv->gda_provider, priv->gda_conn, operation_type, NULL))
{
g_warning ("Unable to create operation type \"%s\": %s.", str_operation_type,
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
else
{
{
g_warning ("Unable to load GdaServerOperation from the file: %s.\n",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
else
{
- if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ error = NULL;
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
- g_warning ("Error on executing GdaServerOperation from the file: %s.\n",
+ g_warning ("Error on rendering GdaServerOperation from the file: %s.\n",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
}
g_object_unref (op);
else
{
g_warning ("Operation type \"%s\" not supported by the provider.", str_operation_type);
- ret = FALSE;
+ ret = NULL;
}
cur = cur->next;
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_create_table (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_create_table (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
+ GString *sql;
xmlNodePtr cur;
gchar *table_name;
xmlNode *node;
GError *error;
+ GdaServerOperation *op;
- ret = TRUE;
+ gchar *drop;
+
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
table_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
{
- table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ table_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
}
- if (table_name != NULL && g_strcmp0 (table_name, "") != 0)
+ if (table_name != NULL
+ && g_strcmp0 (table_name, "") != 0)
{
- GdaServerOperation *op;
-
error = NULL;
op = gda_server_provider_create_operation (priv->gda_provider,
priv->gda_conn,
{
g_warning ("Unable to create GdaServerOperation create_table: %s.",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
else
{
gda_server_operation_set_value_at (op, "integer", &error, "/FIELDS_A/@COLUMN_TYPE/0");
error = NULL;
- if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ sql = g_string_new (gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error));
+ if (sql == NULL
+ || error != NULL)
{
g_warning ("Error executing the operation: %s.",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
- g_object_unref (op);
-
- if (ret)
+ else
{
+ g_object_unref (op);
+
cur = xnode->children;
while (cur != NULL && ret)
{
xmlNodeSetContent (node, (const xmlChar *)"zdbt_to_be_delete");
xmlAddChild (cur, node);
- zak_dbt_dbt_parse_drop_column (zak_dbt_dbt, cur);
+ drop = zak_dbt_dbt_parse_drop_column (zak_dbt_dbt, cur);
+
+ g_string_append_printf (sql, ";\n%s", drop != NULL ? drop : "");
+
+ g_free (drop);
+
+ ret = g_strdup (sql->str);
}
+ g_string_free (sql, TRUE);
}
}
else
{
g_warning ("You must provide the name of the table to create.");
- ret = FALSE;
+ ret = NULL;
}
+ g_free (table_name);
+
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_drop_table (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_drop_table (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *table_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
table_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
{
- table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ table_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
}
- if (table_name != NULL && g_strcmp0 (table_name, "") != 0)
+ if (table_name != NULL
+ && g_strcmp0 (table_name, "") != 0)
{
- gchar *sql;
- GdaStatement *stmt;
-
- sql = g_strdup_printf ("DROP TABLE %s", table_name);
+ GdaServerOperation *op;
error = NULL;
- stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error);
- if (stmt == NULL)
+ op = gda_server_provider_create_operation (priv->gda_provider,
+ priv->gda_conn,
+ GDA_SERVER_OPERATION_DROP_TABLE,
+ NULL,
+ &error);
+ if (op == NULL
+ || error != NULL)
{
- g_warning ("Unable to create GdaStatement from sql: %s.\n%s",
- error != NULL && error->message != NULL ? error->message : "no detail",
- sql);
- ret = FALSE;
+ g_warning ("Unable to create GdaServerOperation create_table: %s.",
+ error != NULL && error->message != NULL ? error->message : "no detail");
+ ret = NULL;
}
else
{
- guint nrows;
+ error = NULL;
+ gda_server_operation_set_value_at (op, table_name, &error, "/TABLE_DESC_P/TABLE_NAME");
- nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
- if (nrows == -1)
+ error = NULL;
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
- g_warning ("NON SELECT error: %s.\n%s",
- error != NULL && error->message != NULL ? error->message : "no detail",
- sql);
- ret = FALSE;
+ g_warning ("Error executing the operation: %s.",
+ error != NULL && error->message != NULL ? error->message : "no detail");
+ ret = NULL;
}
- g_object_unref (stmt);
}
}
else
{
g_warning ("You must provide the name of the table to drop.");
- ret = FALSE;
+ ret = NULL;
}
+ g_free (table_name);
+
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_rename_table (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_rename_table (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *table_name;
gchar *new_table_name;
GError *error;
+ GdaServerOperation *op;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
table_name = NULL;
new_table_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
{
- table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ table_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"new_table_name") == 0)
{
- new_table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ new_table_name = g_strstrip ((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);
+ error = NULL;
gda_server_operation_set_value_at (op, table_name, &error, "/TABLE_DESC_P/TABLE_NAME");
+
+ error = NULL;
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))
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
- g_warning ("Error executing the operation: %s.",
- error != NULL && error->message != NULL ? error->message : "No detail");
- ret = FALSE;
+ g_warning ("Error executing the operation: %s",
+ error != NULL && error->message != NULL ? error->message : "no detail.");
+ ret = NULL;
}
g_object_unref (op);
}
else
{
- g_warning ("You must provide the name of the table to drop.");
- ret = FALSE;
+ g_warning ("You must provide the name of the table to rename and the new name.");
+ ret = NULL;
}
+ g_free (table_name);
+ g_free (new_table_name);
+
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_drop_view (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_drop_view (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *view_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
view_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"view_name") == 0)
{
- view_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ view_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
}
- if (view_name != NULL && g_strcmp0 (view_name, "") != 0)
+ if (view_name != NULL
+ && g_strcmp0 (view_name, "") != 0)
{
- gchar *sql;
- GdaStatement *stmt;
-
- sql = g_strdup_printf ("DROP VIEW %s", view_name);
+ GdaServerOperation *op;
error = NULL;
- stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error);
- if (stmt == NULL)
+ op = gda_server_provider_create_operation (priv->gda_provider,
+ priv->gda_conn,
+ GDA_SERVER_OPERATION_DROP_VIEW,
+ NULL,
+ &error);
+ if (op == NULL
+ || error != NULL)
{
- g_warning ("Unable to create GdaStatement from sql: %s.\n%s",
- error != NULL && error->message != NULL ? error->message : "no detail",
- sql);
- ret = FALSE;
+ g_warning ("Unable to create GdaServerOperation create_table: %s.",
+ error != NULL && error->message != NULL ? error->message : "no detail");
+ ret = NULL;
}
else
{
- guint nrows;
+ error = NULL;
+ gda_server_operation_set_value_at (op, view_name, &error, "/VIEW_DESC_P/VIEW_NAME");
- nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
- if (nrows == -1)
+ error = NULL;
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
- g_warning ("NON SELECT error: %s.\n%s",
- error != NULL && error->message != NULL ? error->message : "no detail",
- sql);
- ret = FALSE;
+ g_warning ("Error executing the operation: %s.",
+ error != NULL && error->message != NULL ? error->message : "no detail");
+ ret = NULL;
}
- g_object_unref (stmt);
}
}
else
{
g_warning ("You must provide the name of the view to drop.");
- ret = FALSE;
+ ret = NULL;
}
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_rename_view (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_rename_view (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *view_name;
gchar *new_view_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
view_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"view_name") == 0)
{
- view_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ view_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"new_view_name") == 0)
{
- new_view_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ new_view_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
g_warning ("Unable to create GdaStatement from sql: %s.\n%s",
error != NULL && error->message != NULL ? error->message : "no detail",
sql);
- ret = FALSE;
+ ret = NULL;
}
else
{
- guint nrows;
-
- nrows = gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error);
- if (nrows == -1)
+ if (gda_connection_statement_execute_non_select (priv->gda_conn, stmt, NULL, NULL, &error) == -1)
{
g_warning ("NON SELECT error: %s.\n%s",
error != NULL && error->message != NULL ? error->message : "no detail",
sql);
- ret = FALSE;
+ ret = NULL;
}
g_object_unref (stmt);
}
else
{
g_warning ("You must provide the name of the view to drop.");
- ret = FALSE;
+ ret = NULL;
}
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_create_index (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_create_index (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *index_name;
gchar *table_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
column_names = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"index_name") == 0)
{
- index_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ index_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
{
- table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ table_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_name") == 0)
{
- column_names = g_slist_append (column_names, g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur))));
+ column_names = g_slist_append (column_names, g_strstrip ((gchar *)xmlNodeGetContent (cur)));
}
cur = cur->next;
if (index_name != NULL && g_strcmp0 (index_name, "") != 0
&& table_name != NULL && g_strcmp0 (table_name, "") != 0
&& column_names != NULL && g_slist_length (column_names) > 0)
- {g_debug("%s %s",index_name,table_name);
+ {
GdaServerOperation *op;
guint i;
}
error = NULL;
-g_debug("%s",gda_server_provider_render_operation(priv->gda_provider, priv->gda_conn, op, &error));
- if (error != NULL)
- {
- g_warning ("%s", error->message);
- }
+ g_debug("%s",gda_server_provider_render_operation(priv->gda_provider, priv->gda_conn, op, &error));
+ if (error != NULL)
+ {
+ g_warning ("%s", error->message);
+ }
i = 0;
while (column_names != NULL)
}
error = NULL;
-g_debug("%s",gda_server_provider_render_operation(priv->gda_provider, priv->gda_conn, op, &error));
- if (error != NULL)
- {
- g_warning ("%s", error->message);
- }
+ g_debug("%s",gda_server_provider_render_operation(priv->gda_provider, priv->gda_conn, op, &error));
+ if (error != NULL)
+ {
+ g_warning ("%s", error->message);
+ }
error = NULL;
- if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
g_warning ("Error executing the operation: %s.",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
g_object_unref (op);
}
else
{
g_warning ("You must provide the name of the index, the name of the table and one or more column's name.");
- ret = FALSE;
+ ret = NULL;
}
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_drop_index (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_drop_index (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *index_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
index_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"index_name") == 0)
{
- index_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ index_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
gda_server_operation_set_value_at (op, index_name, &error, "/INDEX_DESC_P/INDEX_NAME");
error = NULL;
- if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
- g_warning ("Error executing the operation: %s.",
- error != NULL && error->message != NULL ? error->message : "No detail");
- ret = FALSE;
+ g_warning ("Error executing the operation: %s",
+ error != NULL && error->message != NULL ? error->message : "no detail.");
+ ret = NULL;
}
g_object_unref (op);
}
else
{
g_warning ("You must provide the name of the index.");
- ret = FALSE;
+ ret = NULL;
}
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_add_column (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_add_column (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *table_name;
gchar *column_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
column_default = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
{
- table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ table_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_name") == 0)
{
- column_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_type") == 0)
{
- column_type = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_type = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_size") == 0)
{
- column_size = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_size = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_not_null") == 0)
{
- column_not_null = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_not_null = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_auto_increment") == 0)
{
- column_auto_increment = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_auto_increment = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_unique") == 0)
{
- column_unique = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_unique = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_default") == 0)
{
- column_default = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_default = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
{
g_warning ("Unable to create GdaServerOperation add_column: %s.",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
else
{
}
error = NULL;
- if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
g_warning ("Error executing the operation: %s.",
error != NULL && error->message != NULL ? error->message : "No detail");
- ret = FALSE;
+ ret = NULL;
}
g_object_unref (op);
}
g_warning ("You must provide at least:\n"
" - the name of the table and the column\n"
" - the column's type");
- ret = FALSE;
+ ret = NULL;
}
return ret;
}
-static gboolean
-zak_dbt_dbt_parse_drop_column (ZakDbtDbt *zak_dbt_dbt, xmlNodePtr xnode)
+static gchar
+*zak_dbt_dbt_parse_drop_column (ZakDbtDbt *zak_dbt_dbt, xmlNode *xnode)
{
ZakDbtDbtPrivate *priv;
- gboolean ret;
+ gchar *ret;
- xmlNodePtr cur;
+ xmlNode *cur;
gchar *table_name;
gchar *column_name;
GError *error;
- ret = TRUE;
+ ret = NULL;
priv = ZAK_DBT_DBT_GET_PRIVATE (zak_dbt_dbt);
column_name = NULL;
cur = xnode->children;
- while (cur != NULL && ret)
+ while (cur != NULL)
{
if (xmlStrcmp (cur->name, (const xmlChar *)"table_name") == 0)
{
- table_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ table_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
else if (xmlStrcmp (cur->name, (const xmlChar *)"column_name") == 0)
{
- column_name = g_strstrip (g_strdup ((gchar *)xmlNodeGetContent (cur)));
+ column_name = g_strstrip ((gchar *)xmlNodeGetContent (cur));
}
cur = cur->next;
{
g_warning ("Unable to create GdaServerOperation drop_column: %s.",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
else
{
gda_server_operation_set_value_at (op, column_name, &error, "/COLUMN_DESC_P/COLUMN_NAME");
error = NULL;
- if (!gda_server_provider_perform_operation (priv->gda_provider, priv->gda_conn, op, &error))
+ ret = gda_server_provider_render_operation (priv->gda_provider, priv->gda_conn, op, &error);
+ if (ret == NULL
+ || error != NULL)
{
g_warning ("Error executing the operation: %s.",
error != NULL && error->message != NULL ? error->message : "no detail");
- ret = FALSE;
+ ret = NULL;
}
g_object_unref (op);
}
{
g_warning ("You must provide at least:\n"
" - the name of the table and the column");
- ret = FALSE;
+ ret = NULL;
}
return ret;
gchar *str_id;
guint id;
- gboolean tosave;
+ gchar *sql;
+
+ gchar *operation;
+ xmlBufferPtr xbuf;
+ GdaBatch *batch;
+
+ const GSList *list;
guint i;
return;
}
+ if (!GDA_IS_SQL_PARSER (priv->gda_parser))
+ {
+ g_warning ("Invalid sql parser.");
+ return;
+ }
+
xpcontext = xmlXPathNewContext (priv->xml_doc);
xpcontext->node = priv->xml_root;
for (i = 0; i < xnodeset->nodeNr; i++)
{
- tosave = TRUE;
-
str_id = xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id");
if (str_id == NULL)
{
}
}
+ sql = NULL;
+
xnode = xnodeset->nodeTab[i]->children;
while (xnode != NULL)
{
if (!xmlNodeIsText (xnode))
{
+ sql = NULL;
+
if (xmlStrcmp (xnode->name, (const xmlChar *)"sql") == 0)
{
- tosave = zak_dbt_dbt_parse_sql (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_sql (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0)
{
- tosave = zak_dbt_dbt_parse_gda_op (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_gda_op (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"create_table") == 0)
{
- tosave = zak_dbt_dbt_parse_create_table (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_create_table (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_table") == 0)
{
- tosave = zak_dbt_dbt_parse_drop_table (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_drop_table (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"rename_table") == 0)
{
- tosave = zak_dbt_dbt_parse_rename_table (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_rename_table (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_view") == 0)
{
- tosave = zak_dbt_dbt_parse_drop_view (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_drop_view (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"rename_view") == 0)
{
- tosave = zak_dbt_dbt_parse_rename_view (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_rename_view (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"create_index") == 0)
{
- tosave = zak_dbt_dbt_parse_create_index (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_create_index (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_index") == 0)
{
- tosave = zak_dbt_dbt_parse_drop_index (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_drop_index (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"add_column") == 0)
{
- tosave = zak_dbt_dbt_parse_add_column (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_add_column (zak_dbt_dbt, xnode);
}
else if (xmlStrcmp (xnode->name, (const xmlChar *)"drop_column") == 0)
{
- tosave = zak_dbt_dbt_parse_drop_column (zak_dbt_dbt, xnode);
+ sql = zak_dbt_dbt_parse_drop_column (zak_dbt_dbt, xnode);
}
else
{
g_warning ("Invalid tag: %s.", xnode->name);
- tosave = FALSE;
+ sql = NULL;
+ }
+
+ if (sql != NULL)
+ {
+ /* execute the transformation */
+ error = NULL;
+ batch = gda_sql_parser_parse_string_as_batch (priv->gda_parser, sql, NULL, &error);
+ if (batch == NULL)
+ {
+ g_warning ("Unable to create batch of GdaStatement's from sql: %s.\n%s",
+ error != NULL && error->message != NULL ? error->message : "no detail",
+ sql);
+ g_free (sql);
+ sql = NULL;
+ break;
+ }
+ else
+ {
+ for (list = gda_batch_get_statements (batch); list; list = list->next)
+ {
+ if (gda_connection_statement_execute_non_select (priv->gda_conn, GDA_STATEMENT (list->data), NULL, NULL, &error) == -1)
+ {
+ g_warning ("NON SELECT error: %s.\n%s",
+ error != NULL && error->message != NULL ? error->message : "no detail",
+ sql);
+ g_free (sql);
+ sql = NULL;
+ break;
+ }
+ }
+ }
}
}
xnode = xnode->next;
}
- if (tosave)
+ if (sql != NULL)
{
- gchar *operation;
- xmlBufferPtr xbuf;
-
+ /* saving transformation in db */
xbuf = xmlBufferCreate ();
xmlNodeDump (xbuf, priv->xml_doc, xnodeset->nodeTab[i], 0, 0);
operation = g_strstrip (g_strdup (xbuf->content));
- tosave = zak_dbt_dbt_save_transformation (zak_dbt_dbt, id, g_strstrip (operation));
- }
-
- /* ending transaction */
- if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
- {
- error = NULL;
- if (tosave)
+ if (!zak_dbt_dbt_save_transformation (zak_dbt_dbt, id, g_strstrip (operation)))
{
- gda_connection_commit_transaction (priv->gda_conn, NULL, &error);
+ /* ending transaction */
+ if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
+ {
+ error = NULL;
+ gda_connection_rollback_transaction (priv->gda_conn, NULL, &error);
+ }
}
else
{
+ /* ending transaction */
+ if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
+ {
+ error = NULL;
+ gda_connection_commit_transaction (priv->gda_conn, NULL, &error);
+ }
+ }
+ }
+ else
+ {
+ /* ending transaction */
+ if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
+ {
+ error = NULL;
gda_connection_rollback_transaction (priv->gda_conn, NULL, &error);
}
}
+
+ g_free (sql);
+ sql = NULL;
}
}
}