/*
*
* 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 "DCMetaStore.hpp"
#include "DCSession.hpp"
#include "DatConfig.hpp"
extern DCSessionPtr sesPtr;
int DCMetaStore(const xmlDocPtr docObj, const char *sessionId, char **externalError, xmlDocPtr *docReturn)
{
xmlXPathContextPtr ctxObj;
xmlXPathObjectPtr resObj;
GdaConnection *connection;
char *extTableName;
gchar *extTableNameQuoted;
char *objDataSource = NULL, *metaOption = NULL;
GError *error = NULL;
GdaMetaContext mcontext = {"_tables", 1, NULL, NULL};
gboolean metaStoreUpdateOK;
/* Create XPath Environment */
ctxObj = xmlXPathNewContext(docObj);
/* Get DataSource name */
resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/@DataSource", ctxObj);
objDataSource = (char *)xmlXPathCastToString(resObj);
/* Get Build Option */
resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/MetaStore/@Option", ctxObj);
metaOption = (char *)xmlXPathCastToString(resObj);
/* Get Connection Object to Data Source */
connection = sesPtr->getGdaConnection(sesPtr, sessionId, objDataSource);
if (connection == NULL)
return 70002;
/* Check Option */
if (strcmp(metaOption, "Update") == 0)
{
/* Get external (= table to build) table name */
resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/MetaStore/ExternalTableName", ctxObj);
extTableName = (char *)xmlXPathCastToString(resObj);
if (extTableName == NULL | strlen(extTableName) == 0)
{
/* Update ALL tables */
metaStoreUpdateOK = gda_connection_update_meta_store(connection, NULL, &error);
if (metaStoreUpdateOK == FALSE)
{
*externalError = error->message;
return 90001;
}
}
else
{
/* Update single table */
mcontext.column_names = g_new (gchar *, 1);
mcontext.column_names[0] = "table_name";
mcontext.column_values = g_new (GValue *, 1);
extTableNameQuoted = gda_sql_identifier_quote(extTableName, connection, NULL, TRUE, FALSE);
g_value_set_string ((mcontext.column_values[0] = gda_value_new(G_TYPE_STRING)), extTableNameQuoted);
g_free(extTableNameQuoted);
metaStoreUpdateOK = gda_connection_update_meta_store(connection, &mcontext, &error);
gda_value_free (mcontext.column_values[0]);
if (metaStoreUpdateOK == FALSE)
{
*externalError = error->message;
return 90001;
}
}
}
else
/* Invalid Option */
return 70027;
/* Create return document */
*docReturn = xmlNewDoc((const xmlChar *)XML_VERSION);
(*docReturn)->children = xmlNewDocNode(*docReturn, NULL, (const xmlChar *)ROOT_ELEM, NULL);
/* Return */
return 0;
}