Skip to content
Snippets Groups Projects
Commit 717896c5 authored by Ruud Overeem's avatar Ruud Overeem
Browse files

Task #1418: Allowing single quotes in campaignnames and other campaign fields.

parent de230c68
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ string VersionNr(int32 VersNumber);
bool isReference(const string& limitsContents);
uint32 getVersionNrFromName(const string& aName);
string cleanNodeName(const string& aName);
string escapeQuotes (const string& origin);
// @}
} // namespace OTDB
......
......@@ -127,26 +127,14 @@ CREATE OR REPLACE FUNCTION saveCampaign(INT4, VARCHAR(30), VARCHAR(100), VARCHAR
-- $Id: addComponentToVT_func.sql 19935 2012-01-25 09:06:14Z mol $
DECLARE
vID campaign.ID%TYPE;
vName TEXT;
vTitle TEXT;
vPI TEXT;
vCO_I TEXT;
vContact TEXT;
BEGIN
-- remove single quotes
vName := replace($2, \'\\\'\', \'\');
vTitle := replace($3, \'\\\'\', \'\');
vPI := replace($4, \'\\\'\', \'\');
vCO_I := replace($5, \'\\\'\', \'\');
vContact := replace($6, \'\\\'\', \'\');
-- check if node exists
IF $1 = 0 THEN
SELECT ID
INTO vID
FROM campaign
WHERE name = vName;
WHERE name = $2;
ELSE
SELECT ID
INTO vID
......
......@@ -25,7 +25,9 @@
//# Includes
#include <Common/LofarLogger.h>
#include <Common/lofar_datetime.h>
#include <OTDB/Campaign.h>
#include <OTDB/misc.h>
#include <pqxx/transaction>
......@@ -150,10 +152,12 @@ int32 Campaign::saveCampaign(const CampaignInfo& aCampaign)
work xAction(*(itsConn->getConn()), "saveCampaign");
try {
result res = xAction.exec(formatString(
string query(formatString(
"SELECT saveCampaign(%d,'%s','%s','%s','%s','%s')",
aCampaign.ID(), aCampaign.name.c_str(), aCampaign.title.c_str(),
aCampaign.PI.c_str(), aCampaign.CO_I.c_str(), aCampaign.contact.c_str()));
aCampaign.ID(), escapeQuotes(aCampaign.name).c_str(),
escapeQuotes(aCampaign.title).c_str(), escapeQuotes(aCampaign.PI).c_str(),
escapeQuotes(aCampaign.CO_I).c_str(), escapeQuotes(aCampaign.contact).c_str()));
result res = xAction.exec(query);
// Analyze result
int32 newID;
......@@ -167,7 +171,7 @@ int32 Campaign::saveCampaign(const CampaignInfo& aCampaign)
}
catch (std::exception& ex) {
itsError = string("Exception during getCampaignList:") + ex.what();
itsError = string("Exception during saveCampaign:") + ex.what();
LOG_FATAL(itsError);
}
......
......@@ -25,6 +25,7 @@
//# Includes
#include <Common/LofarLogger.h>
#include <Common/lofar_string.h>
#include <Common/StringUtil.h>
#include <OTDB/misc.h>
#include <cstdio>
......@@ -93,5 +94,19 @@ string cleanNodeName(const string& aName)
return(theName.substr(0, start));
}
string escapeQuotes(const string& origin)
{
string result(origin);
string::size_type prev_pos = 0;
string::size_type pos;
while ((pos = result.find("'", prev_pos)) != string::npos) {
result.insert(prev_pos+pos, 1, '\\');
prev_pos = pos + 2;
}
return (result);
}
} // namespace OTDB
} // namespace LOFAR
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment