Commit 6b81d331 authored by Mateusz Loskot's avatar Mateusz Loskot

Renamed all SOCI_PGSQL_* macros to SOCI_POSTGRESQL_*. Added related options to...

Renamed all SOCI_PGSQL_* macros to SOCI_POSTGRESQL_*. Added related options to CMake configuration to control those preprocessor definitions. Updated documentation.
parent e3f68d2a
......@@ -98,8 +98,8 @@ parameters used in the SQL query.</p>
<p><span class="note">Portability note:</span></p>
<p>Older versions of the PostgreSQL client API do not allow to use input
parameters at all. In order to compile SOCI with those old client
libraries, define the <code>SOCI_PGSQL_NOPARAMS</code> preprocessor
name.</p>
libraries, define the <code>SOCI_POSTGRESQL_NOPARAMS</code> preprocessor
name passing <code>-DSOCI_POSTGRESQL_NOPARAMS=ON</code> variable to CMake.</p>
</div>
<h4 id="bind_position">Binding by position</h4>
......@@ -205,9 +205,11 @@ the given query to the native form - and this is also one of the very few places
where SOCI intrudes into the SQL query. For portability reasons, it is
recommended to use named parameters, as shown in the examples above.<br />
The query rewriting can be switched off by compiling the backend with
the <code>SOCI_PGSQL_NOBINDBYNAME</code> name defined. Note that in this case
it is also necessary to define <code>SOCI_PGSQL_NOPREPARE</code>, because
statement preparation relies on successful query rewriting.
the <code>SOCI_POSTGRESQL_NOBINDBYNAME</code> name defined (pass
<code>-DSOCI_POSTGRESQL_NOBINDBYNAME=ON</code> variable to CMake).
Note that in this case it is also necessary to define <code>SOCI_POSTGRESQL_NOPREPARE</code>
(controlled by CMake variable <code>-DSOCI_POSTGRESQL_NOPREPARE=ON</code>),
because statement preparation relies on successful query rewriting.
In practice, both macros will be needed for PostgreSQL server older than 8.0.</p>
</div>
......
......@@ -77,8 +77,9 @@ does not actually provide this functionality - in which case the library will in
execute the query in a single phase, without really separating
the statement preparation from execution.</p>
<p>For PostgreSQL servers older than 8.0 it is necessary to define the
<code>SOCI_PGSQL_NOPREPARE</code> macro while compiling the library
to fall back to this one-phase behaviour.</p>
<code>SOCI_POSTGRESQL_NOPREPARE</code> macro while compiling the library
to fall back to this one-phase behaviour. Simply, pass
<code>-DSOCI_POSTGRESQL_NOPREPARE=ON</code> variable to CMake.</p>
</div>
<h3 id="rowset">Rowset and iterator-based access</h3>
......
include(CMakeDependentOption)
option(SOCI_POSTGRESQL_NOPARAMS
"Do not use input parameters. PostgreSQL 7.x portability."
OFF)
option(SOCI_POSTGRESQL_NOBINDBYNAME
"Disable query rewriting to native form. PostgreSQL 7.0 portability."
OFF)
cmake_dependent_option(SOCI_POSTGRESQL_NOPREPARE
"Disable prepared statements. Set ON if SOCI_POSTGRESQL_NOBINDBYNAME is ON. PostgreSQL 7.0 portability." ON
SOCI_POSTGRESQL_NOBINDBYNAME OFF)
if(SOCI_POSTGRESQL_NOPARAMS)
add_definitions(-DSOCI_POSTGRESQL_NOPARAMS=1)
endif()
if(SOCI_POSTGRESQL_NOBINDBYNAME)
message("X")
add_definitions(-DSOCI_POSTGRESQL_NOBINDBYNAME=1)
endif()
if(SOCI_POSTGRESQL_NOPREPARE)
message("Y")
add_definitions(-DSOCI_POSTGRESQL_NOPREPARE=1)
endif()
soci_backend(PostgreSQL
DEPENDS PostgreSQL
HEADERS soci-postgresql.h common.h
......
......@@ -14,9 +14,9 @@
#include <ctime>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355)
......
......@@ -10,9 +10,9 @@
#include <backend-loader.h>
#include <libpq/libpq-fs.h> // libpq
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355)
......
......@@ -14,9 +14,9 @@
#include <ctime>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355)
......
......@@ -14,9 +14,9 @@
#include <ctime>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355 4996)
......
......@@ -18,9 +18,9 @@
#include <ctime>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
using namespace soci;
using namespace soci::details;
......
......@@ -18,9 +18,9 @@
#include <limits>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355 4996)
......
......@@ -16,9 +16,9 @@
#include <ctime>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355)
......@@ -53,7 +53,7 @@ void postgresql_statement_backend::clean_up()
void postgresql_statement_backend::prepare(std::string const & query,
statement_type stType)
{
#ifdef SOCI_PGSQL_NOBINDBYNAME
#ifdef SOCI_POSTGRESQL_NOBINDBYNAME
query_ = query;
#else
// rewrite the query by transforming all named parameters into
......@@ -147,9 +147,9 @@ void postgresql_statement_backend::prepare(std::string const & query,
query_ += ss.str();
}
#endif // SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOBINDBYNAME
#ifndef SOCI_PGSQL_NOPREPARE
#ifndef SOCI_POSTGRESQL_NOPREPARE
if (stType == st_repeatable_query)
{
......@@ -171,7 +171,7 @@ void postgresql_statement_backend::prepare(std::string const & query,
stType_ = stType;
#endif // SOCI_PGSQL_NOPREPARE
#endif // SOCI_POSTGRESQL_NOPREPARE
}
statement_backend::exec_fetch_result
......@@ -202,7 +202,7 @@ postgresql_statement_backend::execute(int number)
// not supported anyway, so in the effect the 'number' parameter here
// specifies the size of vectors (into/use), but 'numberOfExecutions'
// specifies the number of loops that need to be performed.
int numberOfExecutions = 1;
if (number > 0)
{
......@@ -262,13 +262,13 @@ postgresql_statement_backend::execute(int number)
}
}
#ifdef SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
throw soci_error("Queries with parameters are not supported.");
#else
#ifdef SOCI_PGSQL_NOPREPARE
#ifdef SOCI_POSTGRESQL_NOPREPARE
result_ = PQexecParams(session_.conn_, query_.c_str(),
static_cast<int>(paramValues.size()),
......@@ -295,9 +295,9 @@ postgresql_statement_backend::execute(int number)
NULL, &paramValues[0], NULL, NULL, 0);
}
#endif // SOCI_PGSQL_NOPREPARE
#endif // SOCI_POSTGRESQL_NOPREPARE
#endif // SOCI_PGSQL_NOPARAMS
#endif // SOCI_POSTGRESQL_NOPARAMS
if (numberOfExecutions > 1)
{
......@@ -330,7 +330,7 @@ postgresql_statement_backend::execute(int number)
// there are no use elements
// - execute the query without parameter information
#ifdef SOCI_PGSQL_NOPREPARE
#ifdef SOCI_POSTGRESQL_NOPREPARE
result_ = PQexec(session_.conn_, query_.c_str());
#else
......@@ -347,7 +347,7 @@ postgresql_statement_backend::execute(int number)
result_ = PQexec(session_.conn_, query_.c_str());
}
#endif // SOCI_PGSQL_NOPREPARE
#endif // SOCI_POSTGRESQL_NOPREPARE
if (result_ == NULL)
{
......
......@@ -56,7 +56,7 @@ void test1()
int id;
std::string name;
#ifndef SOCI_PGSQL_NOPARAMS
#ifndef SOCI_POSTGRESQL_NOPARAMS
sql << "select id, name from soci_test where oid = :rid",
into(id), into(name), use(rid);
......@@ -72,7 +72,7 @@ void test1()
sql << "select id, name from soci_test where oid = " << oid,
into(id), into(name);
#endif // SOCI_PGSQL_NOPARAMS
#endif // SOCI_POSTGRESQL_NOPARAMS
assert(id == 7);
assert(name == "John");
......@@ -94,7 +94,7 @@ public:
try { sql << "create language plpgsql"; }
catch (soci_error const &) {} // ignore if error
#ifndef SOCI_PGSQL_NOPARAMS
#ifndef SOCI_POSTGRESQL_NOPARAMS
sql <<
"create or replace function soci_test(msg varchar) "
......@@ -131,7 +131,7 @@ void test2()
std::string in("my message");
std::string out;
#ifndef SOCI_PGSQL_NOPARAMS
#ifndef SOCI_POSTGRESQL_NOPARAMS
statement st = (sql.prepare <<
"select soci_test(:input)",
......@@ -145,7 +145,7 @@ void test2()
"select soci_test(\'" << in << "\')",
into(out));
#endif // SOCI_PGSQL_NOPARAMS
#endif // SOCI_POSTGRESQL_NOPARAMS
st.execute(true);
assert(out == in);
......@@ -155,7 +155,7 @@ void test2()
std::string in("my message2");
std::string out;
#ifndef SOCI_PGSQL_NOPARAMS
#ifndef SOCI_POSTGRESQL_NOPARAMS
procedure proc = (sql.prepare <<
"soci_test(:input)",
......@@ -167,7 +167,7 @@ void test2()
procedure proc = (sql.prepare <<
"soci_test(\'" << in << "\')", into(out));
#endif // SOCI_PGSQL_NOPARAMS
#endif // SOCI_POSTGRESQL_NOPARAMS
proc.execute(true);
assert(out == in);
......@@ -197,7 +197,7 @@ void test3()
session sql(backEnd, connectString);
blob_table_creator tableCreator(sql);
char buf[] = "abcdefghijklmnopqrstuvwxyz";
sql << "insert into soci_test(id, img) values(7, lo_creat(-1))";
......
......@@ -16,9 +16,9 @@
#include <ctime>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
using namespace soci;
using namespace soci::details;
......
......@@ -16,9 +16,9 @@
#include <limits>
#include <sstream>
#ifdef SOCI_PGSQL_NOPARAMS
#define SOCI_PGSQL_NOBINDBYNAME
#endif // SOCI_PGSQL_NOPARAMS
#ifdef SOCI_POSTGRESQL_NOPARAMS
#define SOCI_POSTGRESQL_NOBINDBYNAME
#endif // SOCI_POSTGRESQL_NOPARAMS
#ifdef _MSC_VER
#pragma warning(disable:4355 4996)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment