diff options
author | randomdan <randomdan@localhost> | 2011-02-17 20:42:53 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-02-17 20:42:53 +0000 |
commit | c5f116af8c044883edf44311173a0c6c017b7d59 (patch) | |
tree | 1ec836764f704d6b39ad52bdddda7fcd35d642f5 /libpqpp/command.cpp | |
parent | Fixes to compile with all gcc warnings as errors (diff) | |
download | libdbpp-postgresql-c5f116af8c044883edf44311173a0c6c017b7d59.tar.bz2 libdbpp-postgresql-c5f116af8c044883edf44311173a0c6c017b7d59.tar.xz libdbpp-postgresql-c5f116af8c044883edf44311173a0c6c017b7d59.zip |
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
Diffstat (limited to 'libpqpp/command.cpp')
-rw-r--r-- | libpqpp/command.cpp | 32 |
1 files changed, 2 insertions, 30 deletions
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<char *>(r.c_str()), 30, "pStatement-%u-%p", no, p)); + r.resize(snprintf(const_cast<char *>(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) { } @@ -26,34 +25,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) { if (values.size() <= n) { @@ -63,6 +34,7 @@ PQ::Command::paramsAtLeast(unsigned int n) } else { free(values[n]); + values[n] = NULL; } } |