From c5f116af8c044883edf44311173a0c6c017b7d59 Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 17 Feb 2011 20:42:53 +0000 Subject: Add check function for when a connection is finished with, but you don't want to close it Use prepared statements only for modifications, use fetch instead for selects (doesn't load an entire record set) Support varchar oid --- libpqpp/command.cpp | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'libpqpp/command.cpp') diff --git a/libpqpp/command.cpp b/libpqpp/command.cpp index 419d953..6edc090 100644 --- a/libpqpp/command.cpp +++ b/libpqpp/command.cpp @@ -6,14 +6,13 @@ static std::string addrStr(void * p, unsigned int no) { std::string r; r.resize(30); - r.resize(snprintf(const_cast(r.c_str()), 30, "pStatement-%u-%p", no, p)); + r.resize(snprintf(const_cast(r.c_str()), 30, "pStatement_%u_%p", no, p)); return r; } PQ::Command::Command(const Connection * conn, const std::string & sql, unsigned int no) : DB::Command(sql), stmntName(addrStr(this, no)), - prepared(false), c(conn) { } @@ -25,34 +24,6 @@ PQ::Command::~Command() } } -void -PQ::Command::prepare() const -{ - if (!prepared) { - std::string psql; - psql.reserve(sql.length() + 20); - 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; - } - } - c->checkResultFree(PQprepare( - c->conn, stmntName.c_str(), psql.c_str(), values.size(), NULL), PGRES_COMMAND_OK); - prepared = true; - } -} - void PQ::Command::paramsAtLeast(unsigned int n) { @@ -63,6 +34,7 @@ PQ::Command::paramsAtLeast(unsigned int n) } else { free(values[n]); + values[n] = NULL; } } -- cgit v1.2.3