Skip to content
Snippets Groups Projects
Commit 00e180dd authored by Marcel Loose's avatar Marcel Loose :sunglasses:
Browse files

Bug 1287: Removed the pqutil stuff

parent 5fe710e3
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,6 @@ pkginclude_HEADERS = Package__Version.h \ ...@@ -35,7 +35,6 @@ pkginclude_HEADERS = Package__Version.h \
Types.h Types.h
noinst_HEADERS = \ noinst_HEADERS = \
pqutil.h \
QueryBuilder/AddCommand.h \ QueryBuilder/AddCommand.h \
StreamUtil.h StreamUtil.h
......
//# pqutil.h: PostgreSQL related utilities; for internal use only.
//#
//# Copyright (C) 2002-2004
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program 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 2 of the License, or
//# (at your option) any later version.
//#
//# This program 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 this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
#ifndef LOFAR_BBSCONTROL_PQUTIL_H
#define LOFAR_BBSCONTROL_PQUTIL_H
//# Never #include <config.h> or #include <lofar_config.h> in a header file!
// \file
// PostgreSQL related utilities; for internal use only.
//# Includes
#include <Common/lofar_string.h>
#include <Common/lofar_vector.h>
namespace LOFAR
{
namespace BBS
{
// \addtogroup BBSControl
// @{
// \internal
// Convert a Postgres-generated C-string to a ParameterSet string. For
// vectors, this means replacing '{' with '[' and '}' with ']'.
// @{
string toPSstring(const char* in);
string toPSstring(const string& in);
// @}
// \internal
// Convert a ParameterSet string to a Postgres string:
// - single quotes will be escaped by doubling them;
// - curly braces and double quotes will be escaped using a backslash.
// - vector delimiters \c [ and \c ] will be replaced with \c { and \c }.
// @{
string toPQstring(const string& in);
string toPQstring(const vector<string>& in);
// @}
// @}
//##---- I n l i n e m e t h o d s ----##//
inline string toPSstring(const string& in)
{
return toPSstring(in.c_str());
}
} // namespace BBS
} // namespace LOFAR
#endif
...@@ -18,7 +18,6 @@ libbbscontrol_la_SOURCES = Package__Version.cc \ ...@@ -18,7 +18,6 @@ libbbscontrol_la_SOURCES = Package__Version.cc \
MultiStep.cc \ MultiStep.cc \
NextChunkCommand.cc \ NextChunkCommand.cc \
NoiseStep.cc \ NoiseStep.cc \
pqutil.cc \
PredictStep.cc \ PredictStep.cc \
QueryBuilder/AddCommand.cc \ QueryBuilder/AddCommand.cc \
RecoverCommand.cc \ RecoverCommand.cc \
......
//# pqutil.cc: PostgreSQL related utilities; for internal use only.
//#
//# Copyright (C) 2002-2004
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program 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 2 of the License, or
//# (at your option) any later version.
//#
//# This program 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 this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
//# Always #include <lofar_config.h> first!
#include <lofar_config.h>
//# Includes
#include <BBSControl/pqutil.h>
#include <Common/lofar_sstream.h>
#include <BBSControl/StreamUtil.h>
namespace LOFAR
{
namespace BBS
{
string toPSstring(const char* in)
{
string out(in);
// When a backslash (\c \\) is read, \c bs is set to true. The next
// character will cause it to toggle to false again. The backslash and
// the character following it will be left untouched in the output.
bool bs(false);
// Toggle indicating whether we're inside a quoted string or not. A
// quoted string is a string delimited by double quotes ("). No
// character substitutions will be done within a quoted string.
bool q(false);
for (string::iterator it = out.begin(); it != out.end(); ++it) {
// If previous character was a backslash, skip current character.
if (bs) {
bs = false;
continue;
}
if (bs = *it == '\\') continue; // skip if current char is backslash
// Toggle if current char is a quote.
if (*it == '"') q = !q;
if (!q) { // we're not between quotes
switch(*it) {
case '{': *it = '['; break;
case '}': *it = ']'; break;
default: break;
}
}
}
return out;
}
string toPQstring(const string& in)
{
string out;
// Toggle indicating whether we're inside a quoted string or not. A
// quoted string is a string delimited by double quotes (").
bool q(false);
for (string::const_iterator it = in.begin(); it != in.end(); ++it) {
switch(*it) {
case '\\' : // backslash must be doubled
out += "\\\\";
break;
case '\'' : // single quote must be doubled
out += "''";
break;
case '"' : // toggle quote character.
q = !q;
out += *it;
break;
case '[' : // replace '[' with '{' when not inside quoted string
if (q) out += *it;
else out += '{';
break;
case ']' : // replace ']' with '}' when not inside quoted string
if (q) out += *it;
else out += '}';
break;
case '{' : // '{' must be escaped when not inside quoted string
if (!q) out += "\\\\";
out += *it;
break;
case '}' : // '}' must be escaped when not inside quoted string
if (!q) out += "\\\\";
out += *it;
break;
default:
out += *it;
break;
}
}
return out;
}
string toPQstring(const vector<string>& in)
{
ostringstream oss;
oss << in;
return toPQstring(oss.str());
}
} // namespace BBS
} // namespace LOFAR
check_PROGRAMS = tpqutil \ check_PROGRAMS = tStrategy \
tStrategy \
tCommandQueue tCommandQueue
check_SCRIPTS = tpqutil.sh \ check_SCRIPTS = tStrategy.sh \
tStrategy.sh \
tCommandQueue.sh tCommandQueue.sh
# programs to run through supplied checktools # programs to run through supplied checktools
CHECKTOOLPROGS = tpqutil \ CHECKTOOLPROGS = tStrategy \
tStrategy \
tCommandQueue tCommandQueue
#ENDCHECKTOOLPROGS #ENDCHECKTOOLPROGS
tpqutil_SOURCES = tpqutil.cc
tpqutil_LDADD = ../src/libbbscontrol.la
tpqutil_DEPENDENCIES = ../src/libbbscontrol.la $(LOFAR_DEPEND)
tStrategy_SOURCES = tStrategy.cc tStrategy_SOURCES = tStrategy.cc
tStrategy_LDADD = ../src/libbbscontrol.la tStrategy_LDADD = ../src/libbbscontrol.la
tStrategy_DEPENDENCIES = ../src/libbbscontrol.la $(LOFAR_DEPEND) tStrategy_DEPENDENCIES = ../src/libbbscontrol.la $(LOFAR_DEPEND)
......
#include <lofar_config.h>
#include <BBSControl/pqutil.h>
#include <APS/ParameterSet.h>
#include <Common/lofar_iostream.h>
#include <Common/LofarLogger.h>
using namespace LOFAR;
using namespace LOFAR::BBS;
using namespace LOFAR::ACC::APS;
#if 0
void toPQ(ostream& os, const ParameterSet& ps)
{
}
void toPS(ostream& os, ParameterSet& ps)
{
}
#endif
int main()
{
INIT_LOGGER("tutil");
ParameterSet ps("tpqutil.parset");
string s1(ps.getString("s1"));
vector<string> s2(ps.getStringVector("s2"));
vector<string> s3(ps.getStringVector("s3"));
string s4(ps.getString("s4"));
vector<string> s5(ps.getStringVector("s5"));
string s6(ps.getString("s6"));
// cout << "s1 = " << s1 << endl;
// cout << "s2 [" << s2.size() << "] = " << endl;
// for (uint i = 0; i < s2.size(); ++i) cout << " " << s2[i] << endl;
// cout << "s3 [" << s3.size() << "] = " << endl;
// for (uint i = 0; i < s3.size(); ++i) cout << " " << s3[i] << endl;
// cout << "s4 = " << s4 << endl;
// cout << "s5 [" << s5.size() << "] = " << endl;
// for (uint i = 0; i < s5.size(); ++i) cout << " " << s5[i] << endl;
// cout << "s6 = " << s6 << endl;
string s;
cout << "\nOriginal:" << endl;
ps.writeBuffer(s);
cout << s << endl;
cout << "\nAs PSQL string:" << endl;
s = toPQstring(s);
cout << s << endl;
cout << "\nAs ParameterSet string:" << endl;
s = toPSstring(s.c_str());
cout << s << endl;
return 0;
#if 1
// \note All backslashes must be doubled in the string initialization,
// because a backslash should be properly escaped using a backslash.
try {
cout << toPSstring("Hello, World") << endl;
cout << toPSstring("{Hello, World, Array}") << endl;
cout << toPSstring("{Curly braces, '{' and '}', must be quoted,")
<< toPSstring(" or escaped like this: \\{ and \\}}") << endl;
cout << toPSstring("{Unbalanced braces do not throw") << endl;
cout << toPSstring("Properly escaped quote: \\',")
<< toPSstring(" and another: \\\\\\'") << endl;
cout << toPSstring("Trailing backslash \\") << endl;
}
catch (Exception& e) {
cerr << e << endl;
return 1;
}
try {
cout << toPSstring("Missing closing single quote ' will throw") << endl;
return 1; // should not get here
}
catch (Exception& e) {
cout << "(Expected): " << e.what() << endl;
}
try {
cout << toPSstring("Missing closing double quote \" will throw") << endl;
return 1; // should not get here
}
catch (Exception& e) {
cout << "(Expected): " << e.what() << endl;
}
try {
cout << toPSstring("Improperly escaped quote \\\\' will throw") << endl;
return 1; // should not get here
}
catch (Exception& e) {
cout << "(Expected): " << e.what() << endl;
}
#else
try {
cout << toPQstring("Hello, World") << endl;
cout << toPQstring("[Hello, World, Array]") << endl;
cout << toPQstring("Curly braces, \"{\" and \"}\", must be quoted,")
<< toPQstring(" or escaped like this: \\{ and \\}") << endl;
cout << toPQstring("[Unbalanced brackets do not throw") << endl;
cout << toPQstring("Properly escaped quote: \\',")
<< toPQstring(" and another: \\\\\\'") << endl;
cout << toPQstring("Trailing backslash \\") << endl;
}
catch (Exception& e) {
cerr << e << endl;
return 1;
}
#endif
return 0;
}
s1=Hello, World
s2=[Hello, World, Array]
s3=[Brackets, "[ and ]", must be quoted]#, or escaped like this: \[ and \]]
s4=[Unbalanced braces do not throw, but it's ugly
s5=[Properly escaped quote: \", and another: \\\"]
s6=Trailing backslash \
.
#!/bin/sh
$lofar_sharedir/runtest.sh tpqutil > tpqutil.log 2>&1
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