/* * * ProLinga-Data * * Copyright (C) 2002-2009 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Data. * * ProLinga-Data is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Data is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Data. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "DatCommon.h" #include "DatMain.hpp" #include "ExecuteSql.hpp" #include #include GdaDataModel *ExecuteSqlDataModelCommand(GdaConnection *connection, const gchar * buffer, DCSessionPtr sesPtr, const char *sessionId) { // GdaCommand *command; // GdaTransaction *trans; // GdaDataModel *dm; GdaSqlParser *parser; GdaStatement *stmt; GdaDataModel *dm = NULL; GError *error = NULL; gboolean dmUpdateOK, metaStoreUpdateOK; gchar *str; /* Create and Execute Command */ // command = gda_command_new(buffer, GDA_COMMAND_TYPE_TABLE, GDA_COMMAND_OPTION_STOP_ON_ERRORS); parser = gda_connection_create_parser (connection); if (!parser) parser = gda_sql_parser_new (); stmt = gda_sql_parser_parse_string (parser, buffer, NULL, &error); g_object_unref(parser); if (!stmt) { g_error_free(error); return NULL; } /* Check if part of transaction */ // trans = sesPtr->getTransaction(sesPtr, sessionId); // if (trans != NULL) // gda_command_set_transaction(command, trans); /* Execute command */ //dm = gda_connection_execute_select_command(connection, command, NULL, NULL); dm = gda_connection_statement_execute_select(connection, stmt, NULL, &error); if (!dm) { g_object_unref (stmt); g_error_free(error); return NULL; } g_object_unref (stmt); dmUpdateOK = gda_data_select_compute_modification_statements (GDA_DATA_SELECT (dm), &error); if (dmUpdateOK == FALSE) { /* Ignore error. Data model will be read-only */ } /* DEBUG */ // g_object_get (G_OBJECT (dm), "update-stmt", &stmt, NULL); // str = gda_statement_to_sql (stmt, NULL, NULL); // g_print ("Computed UPDATE: %s\n", str); // g_free (str); // g_object_unref (stmt); // g_object_get (G_OBJECT (dm), "delete-stmt", &stmt, NULL); // str = gda_statement_to_sql (stmt, NULL, NULL); // g_print ("Computed DELETE: %s\n", str); // g_free (str); // g_object_unref (stmt); // g_object_get (G_OBJECT (dm), "insert-stmt", &stmt, NULL); // str = gda_statement_to_sql (stmt, NULL, NULL); // g_print ("Computed INSERT: %s\n", str); // g_free (str); // g_object_unref (stmt); /* Clean up */ //gda_command_free(command); /* Return */ return dm; } GdaDataModel *ExecuteSqlSingleCommand(GdaConnection *connection, const gchar *buffer, DCSessionPtr sesPtr, const char *sessionId) { GdaSqlParser *parser; GdaStatement *stmt; GdaDataModel *dm = NULL; GError *error = NULL; /* Create and Parse Command */ parser = gda_connection_create_parser (connection); if (!parser) parser = gda_sql_parser_new (); stmt = gda_sql_parser_parse_string (parser, buffer, NULL, &error); g_object_unref(parser); if (!stmt) { g_error_free(error); return NULL; } /* Check if part of transaction */ // trans = sesPtr->getTransaction(sesPtr, sessionId); // if (trans != NULL) // gda_command_set_transaction(command, trans); /* Execute command */ dm = gda_connection_statement_execute_select(connection, stmt, NULL, &error); if (!dm) { g_error_free(error); return NULL; } /* Clean up */ g_object_unref (stmt); /* Return */ return dm; } gint ExecuteSqlNonQuery (GdaConnection *connection, const gchar *buffer, DCSessionPtr sesPtr, const char *sessionId) { gint number = 0; GdaSqlParser *parser; GdaStatement *stmt; GError *error = NULL; /* Create and Parse Command */ parser = gda_connection_create_parser (connection); if (!parser) parser = gda_sql_parser_new (); stmt = gda_sql_parser_parse_string (parser, buffer, NULL, &error); g_object_unref(parser); if (!stmt) { g_error_free(error); return NULL; } /* Check if part of transaction */ // trans = sesPtr->getTransaction(sesPtr, sessionId); // if (trans != NULL) // { // gda_command_set_transaction(command, trans); // printf("NOT NULL %s - %d\n", sessionId, trans); // } // else // printf("NULL %s \n", sessionId); /* Execute command */ number = gda_connection_statement_execute_non_select(connection, stmt, NULL, NULL, &error); /* Clean up */ g_object_unref (stmt); /* Return */ return (number); }