2 Postgresql/pqxx C++ traits for sqlgg
6 This is free and unencumbered software released into the public domain.
8 Anyone is free to copy, modify, publish, use, compile, sell, or
9 distribute this software, either in source code form or as a compiled
10 binary, for any purpose, commercial or non-commercial, and by any
13 For more information, please refer to <http://unlicense.org/>
17 #define SQLGG_STR(x) x
26 #if defined(SQLGG_DEBUG)
34 typedef std::string Text
;
37 typedef pqxx::result::const_iterator row
;
38 typedef pqxx::work
& connection
;
40 static void get_column(row r
, int index
, Int
& data
)
45 static void get_column(row r
, int index
, Text
& data
)
49 typedef pqxx::prepare::declaration stmt_decl
;
51 static void set_param(stmt_decl
const& stmt
, const Text
& val
, int index
)
53 stmt("varchar",pqxx::prepare::treat_string
);
56 static void set_param(stmt_decl
const& stmt
, const Int
& val
, int index
)
58 stmt("INTEGER",pqxx::prepare::treat_direct
);
62 static void set_param(pqxx::prepare::invocation
& stmt
, const T
& val
, int index
)
67 template<class Container
, class Binder
, class Params
>
68 static bool do_select(connection db
, Container
& result
, const char* sql
, Binder binder
, Params params
)
70 const char* name
= "sqlgg_stmt";
71 cout
<< "start prepare" << endl
;
72 pqxx::prepare::declaration decl
= db
.conn().prepare(name
,sql
);
73 params
.set_params(decl
);
75 cout
<< "start invoke" << endl
;
76 pqxx::prepare::invocation call
= db
.prepared(name
);
77 cout
<< "set params" << endl
;
78 params
.set_params(call
);
79 cout
<< "exec" << endl
;
81 cout
<< "execed" << endl
;
83 db
.conn().unprepare(name
);
90 void set_params(pqxx::prepare::declaration
const&) {}
91 void set_params(pqxx::prepare::invocation
&) {}
103 template<class Params
>
104 static bool do_execute(connection db
, const char* sql
, Params params
)
107 return do_select(db
,R
,sql
,no_binder
<int>(),params
);