struct _DbtPrivate
{
GdaConnection *gda_conn;
+ GdaSqlParser *gda_parser;
xmlDocPtr xml_doc;
xmlNodePtr xml_root;
DbtPrivate *priv = DBT_GET_PRIVATE (dbt);
priv->gda_conn = NULL;
+ priv->gda_parser = NULL;
priv->xml_doc = NULL;
priv->xml_root = NULL;
}
priv = DBT_GET_PRIVATE (dbt);
/* create an SQL parser */
- parser = gda_connection_create_parser (priv->gda_conn);
- if (!parser) /* @cnc does not provide its own parser => use default one */
+ priv->gda_parser = gda_connection_create_parser (priv->gda_conn);
+ if (!priv->gda_parser) /* @cnc does not provide its own parser => use default one */
{
- parser = gda_sql_parser_new ();
+ priv->gda_parser = gda_sql_parser_new ();
}
- /* attach the parser object to the connection */
- g_object_set_data_full (G_OBJECT (priv->gda_conn), "parser", parser, g_object_unref);
-
return TRUE;
}
{
DbtPrivate *priv;
- GdaSqlParser *parser;
GdaStatement *stmt;
GdaDataModel *dm;
GError *error;
priv = DBT_GET_PRIVATE (dbt);
- parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
- if (!parser)
+ if (!GDA_IS_SQL_PARSER (priv->gda_parser))
{
g_warning ("Invalid sql parser.");
return ret;
/* dbtransformer tables check */
sql = "SELECT id FROM dbt_transformations WHERE 0=1";
error = NULL;
- stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
+ 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",
ret = FALSE;
- GdaSqlParser *parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
- if (!parser)
+ if (!GDA_IS_SQL_PARSER (priv->gda_parser))
{
g_warning ("Invalid sql parser.");
return ret;
}
- sql = g_strdup_printf ("SELECT id FROM dbt_transformations"
+ sql = g_strdup_printf ("SELECT id FROM dbt_transformations"
" WHERE id = %d",
id);
- stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
+ stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error);
if (!stmt)
{
g_warning ("Unable to check operation existance: %s\n",
ret = FALSE;
- GdaSqlParser *parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
- if (!parser)
+ if (!GDA_IS_SQL_PARSER (priv->gda_parser))
{
g_warning ("Invalid sql parser.");
return ret;
" (id, operation)"
" VALUES (%d, '%s')",
id, operation);
- stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
+ stmt = gda_sql_parser_parse_string (priv->gda_parser, sql, NULL, &error);
if (!stmt)
{
g_warning ("Unable to save operation: %s\n",
gchar *sql;
GError *error;
GdaStatement *stmt;
- GdaSqlParser *parser;
gboolean ret;
priv = DBT_GET_PRIVATE (dbt);
- parser = g_object_get_data (G_OBJECT (priv->gda_conn), "parser");
- if (!parser)
+ if (!GDA_IS_SQL_PARSER (priv->gda_parser))
{
g_warning ("Invalid sql parser.");
- return;
+ return FALSE;
}
sql = (gchar *)xmlNodeGetContent (xnode);
error = NULL;
- stmt = gda_sql_parser_parse_string (parser, g_strstrip (sql), NULL, &error);
+ 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",
xpcontext->node = priv->xml_root;
xpresult = xmlXPathEvalExpression ((const xmlChar *)"child::dbtransformation", xpcontext);
- if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval))
+ if (!xmlXPathNodeSetIsEmpty (xpresult->nodesetval) || xpresult->nodesetval->nodeNr < 1)
{
xnodeset = xpresult->nodesetval;
- if (xnodeset->nodeNr < 1)
- {
- g_warning ("No transformations found.");
- }
-
for (i = 0; i < xnodeset->nodeNr; i++)
{
tosave = TRUE;
- /* starting the transaction */
- if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
- {
- error = NULL;
- if (!gda_connection_begin_transaction (priv->gda_conn, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, &error))
- {
- continue;
- }
- }
-
id = strtol (xmlGetProp (xnodeset->nodeTab[i], (const gchar *)"id"), NULL, 10);
if (dbt_check_to_execute (dbt, id))
{
+ /* starting the transaction */
+ if (gda_connection_supports_feature (priv->gda_conn, GDA_CONNECTION_FEATURE_TRANSACTIONS))
+ {
+ error = NULL;
+ if (!gda_connection_begin_transaction (priv->gda_conn, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, &error))
+ {
+ g_warning ("Unable to start the transaction: %s\n",
+ error && error->message ? error->message : "No detail");
+ continue;
+ }
+ }
+
xnode = xnodeset->nodeTab[i]->children;
while (xnode != NULL)
{
{
tosave = dbt_parse_sql (dbt, xnode);
}
- else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0)
+ /*else if (xmlStrcmp (xnode->name, (const xmlChar *)"gda_op") == 0)
{
- //tosave = dbt_parse_gda_op (dbt, xnode);
- }
+ tosave = dbt_parse_gda_op (dbt, xnode);
+ }*/
else
{
g_warning ("Invalid tag: %s", xnode->name);
if (tosave)
{
gchar *operation;
- xmlBufferPtr xbuf = xmlBufferCreate ();
+ xmlBufferPtr xbuf;
+
+ xbuf = xmlBufferCreate ();
xmlNodeDump (xbuf, priv->xml_doc, xnodeset->nodeTab[i], 0, 0);
operation = g_strstrip (g_strdup (xbuf->content));
tosave = dbt_save_transformation (dbt, id, g_strstrip (operation));