From b58f541a17dcc3eadb0502275bc90412ed9115a7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 7 Dec 2015 14:26:09 +0000 Subject: Merge select and modify command's SQL parser --- libpqpp/command.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libpqpp/command.cpp') diff --git a/libpqpp/command.cpp b/libpqpp/command.cpp index ba12574..94079da 100644 --- a/libpqpp/command.cpp +++ b/libpqpp/command.cpp @@ -24,6 +24,27 @@ PQ::Command::~Command() } } +void +PQ::Command::prepareSql(std::string & psql, const std::string & sql) +{ + char buf[4]; + int p = 1; + bool inquote = false; + for(std::string::const_iterator i = sql.begin(); i != sql.end(); ++i) { + if (*i == '?' && !inquote) { + snprintf(buf, 4, "$%d", p++); + psql += buf; + } + else if (*i == '\'') { + inquote = !inquote; + psql += *i; + } + else { + psql += *i; + } + } +} + void PQ::Command::paramsAtLeast(unsigned int n) { -- cgit v1.2.3