/* * * 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 #include #include #include #include "DatMain.hpp" #include "DCDataSource.hpp" #include "DCExecuteNonQuery.hpp" #include "ExecuteSql.hpp" #include "DCSession.hpp" #include "DatConfig.hpp" extern DCSessionPtr sesPtr; int DCExecuteNonQuery(const xmlDocPtr docObj, const char *sessionId, char **externalError, xmlDocPtr *docReturn) { xmlNodePtr curReturn; xmlXPathContextPtr ctxObj; xmlXPathObjectPtr resObj; GdaConnection *connection; char *objDataSource, *sqlBuffer, tmpString[255]; int noRows; /* Create XPath Environment */ ctxObj = xmlXPathNewContext(docObj); /* Get DataSource name */ resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/@DataSource", ctxObj); objDataSource = (char *)xmlXPathCastToString(resObj); /* Get Connection Object to Data Source */ connection = sesPtr->getGdaConnection(sesPtr, sessionId, objDataSource); if (connection == NULL) return 70002; /* Get SQL statement */ resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/NonQuery/Sql", ctxObj); sqlBuffer = new char[(strlen((char *)xmlXPathCastToString(resObj))+1)]; strcpy(sqlBuffer, (char *)xmlXPathCastToString(resObj)); /* Execute Statement */ noRows = ExecuteSqlNonQuery(connection, sqlBuffer, sesPtr, sessionId); if (noRows == -1) { delete sqlBuffer; *externalError = ConnectionError(connection); return 90001; } /* No longer needed */ delete sqlBuffer; /* Create return document */ *docReturn = xmlNewDoc((const xmlChar *)XML_VERSION); (*docReturn)->children = xmlNewDocNode(*docReturn, NULL, (const xmlChar *)ROOT_ELEM, NULL); curReturn = xmlDocGetRootElement(*docReturn); curReturn = xmlNewTextChild(curReturn, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp(curReturn, (const xmlChar *)"DataSource", (const xmlChar *)objDataSource); sprintf(tmpString,"%d",noRows); curReturn = xmlNewTextChild(curReturn, NULL, (const xmlChar *)"NonQuery", (const xmlChar *)""); curReturn = xmlNewTextChild(curReturn, NULL, (const xmlChar *)"RowsAffected", (const xmlChar *)tmpString); /* Return */ return 0; }