1#line 1 "PeConnection.pgc"
16#if __DCL_HAVE_ALLOC_DEBUG
17#undef __DCL_ALLOC_LEVEL
18#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
31#define __DCL_TRACE0_N __DCL_TRACE0
32#define __DCL_TRACE1_N __DCL_TRACE1
33#define __DCL_TRACE2_N __DCL_TRACE2
34#define __DCL_TRACE3_N __DCL_TRACE3
35#define __DCL_TRACE4_N __DCL_TRACE4
37#define __DCL_TRACE0_N(fmt)
38#define __DCL_TRACE1_N(fmt, arg)
39#define __DCL_TRACE2_N(fmt, arg1, arg2)
40#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
41#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
49#define __SET_ERROR(_error) \
50 setErrorHandle(_error, 0L, __THIS_FILE__, __LINE__)
51#define __SET_ERROR_HANDLE(_SQLCODE) \
52 setErrorHandle(SQL::eServerError, _SQLCODE, __THIS_FILE__, __LINE__)
53#define __SET_ERROR_MSG(_message) \
54 setErrorMessage(_message, __THIS_FILE__, __LINE__)
59 : Connection(pszServerTitle)
61 Connection::__canTransact =
true;
66 if (!__connectionID.isEmpty()) {
87 ListedByteStringToByteStringMap map;
88 Connection::splitConnStr(_conns, _connslen, map);
90 ByteString _USER = map[
"USER"];
91 ByteString _PASSWORD = map[
"PASSWORD"];
92 ByteString _SERVER = map[
"SERVER"];
93 ByteString _PORT = map[
"PORT"];
94 ByteString _DATABASE = map[
"DATABASE"];
99 if (!_SERVER.isEmpty()) {
100 sb.append(
"tcp:postgresql://").append(_SERVER);
101 if (!_PORT.isEmpty()) {
102 sb.append(
":").append(_PORT);
105 if (!_DATABASE.isEmpty()) {
111 _TARGET = sb.toByteString();
115 ByteString
connectionID = ByteString::format(
"conn_%zx", (
size_t)
this);
123#line 110 "PeConnection.pgc"
124 char * user = (
_CONST char * ) _USER . data () ;
126#line 111 "PeConnection.pgc"
127 char * pass = (
_CONST char * ) _PASSWORD . data () ;
129#line 112 "PeConnection.pgc"
130 char * target = (
_CONST char * ) _TARGET . data () ;
132#line 113 "PeConnection.pgc"
135#line 114 "PeConnection.pgc"
138 { ECPGconnect(__LINE__, 0, target , user , pass , connID, 0); }
139#line 117 "PeConnection.pgc"
153 if (__connectionID.isEmpty()) {
161#line 136 "PeConnection.pgc"
162 char * connID = (
_CONST char * ) __connectionID . data () ;
164#line 137 "PeConnection.pgc"
167 { ECPGdisconnect(__LINE__, connID);}
168#line 139 "PeConnection.pgc"
175 __connectionID.clear();
196static StmtType __GetStmtType(
const char* _sql)
198 for(
size_t i = 0; sp[i].type !=
StmtOther; i++) {
213 PGconn* conn = ECPGget_PGconn(__connectionID.data());
214 PGresult* res = PQexec(conn, _sql);
215 ExecStatusType status = PQresultStatus(res);
216 if (status != PGRES_COMMAND_OK) {
217 ByteStringBuilder sb;
218 sb.format(
"ExecStatusType(%d)", status)
219 .append(PQresultErrorMessage(res));
226 switch(__GetStmtType(_sql)) {
246#line 214 "PeConnection.pgc"
247 char * connID = (
_CONST char * ) __connectionID . data () ;
249#line 215 "PeConnection.pgc"
252 { ECPGsetconn(__LINE__, connID);}
253#line 217 "PeConnection.pgc"
260 { ECPGtrans(__LINE__,
NULL,
"begin work");}
261#line 223 "PeConnection.pgc"
277#line 236 "PeConnection.pgc"
278 char * connID = (
_CONST char * ) __connectionID . data () ;
280#line 237 "PeConnection.pgc"
283 { ECPGsetconn(__LINE__, connID);}
284#line 239 "PeConnection.pgc"
291 { ECPGtrans(__LINE__,
NULL,
"commit work");}
292#line 245 "PeConnection.pgc"
308#line 258 "PeConnection.pgc"
309 char * connID = (
_CONST char * ) __connectionID . data () ;
311#line 259 "PeConnection.pgc"
314 { ECPGsetconn(__LINE__, connID);}
315#line 261 "PeConnection.pgc"
322 { ECPGtrans(__LINE__,
NULL,
"rollback work");}
323#line 267 "PeConnection.pgc"
344 *_queryHandleOut = pNewQuery;
354 if (_SQLCODE == 0 ) {
355 __lastErrorMessage.clear();
358 ByteStringBuilder sb;
359 sb.format(
"SQLCODE(%d) ", _SQLCODE);
360 sb.append(sqlca.sqlerrm.sqlerrmc, sqlca.sqlerrm.sqlerrml);
361 __lastErrorMessage = sb.toByteString();
368 if (__lastErrorMessage.length() < *_buflen) {
369 *_buflen = __lastErrorMessage.length();
370 *(_buf + *_buflen) =
'\0';
372 strncpy(_buf, __lastErrorMessage.data(), *_buflen);
378 PGconn* conn = ECPGget_PGconn(__connectionID.data());
379 int serverVersion = PQserverVersion(conn);
380 int protocolVersion =
381#ifdef LIBPQ_HAS_FULL_PROTOCOL_VERSION
382 PQfullProtocolVersion(conn)
384 PQprotocolVersion(conn) * 10000
387 int libVersion = PQlibVersion();
389 ByteString s = ByteString::format(
"PostgreSQL %d.%d/%d.%d/%d.%d/ecpg",
390 serverVersion / 10000, serverVersion % 10000,
391 protocolVersion / 10000, protocolVersion % 10000,
392 libVersion / 10000, libVersion % 10000
394 if (s.length() < *_buflen) {
395 *_buflen = s.length();
396 *(_buf + *_buflen) =
'\0';
398 strncpy(_buf, s.data(), *_buflen);
#define __DCL_TRACE1_N(fmt, arg)
#define __SET_ERROR_MSG(_message)
#define __DCL_TRACE0_N(fmt)
#define __SET_ERROR_HANDLE(_SQLCODE)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
#define __SET_ERROR(_errorCode)
#define __UNSET_STATE(state)
#define __SET_STATE(state)
virtual bool __getServerInfo(char *_buf, size_t *_buflen)
_CONST char * connectionID() const
virtual bool __getErrorMessage(char *_buf, size_t *_buflen)
virtual bool __createQueryInstance(SQL::Query **_queryHandleOut)
virtual bool __execute(const char *_sql, size_t _sqllen)
virtual bool __commitTrans()
virtual bool __startTrans()
void setErrorHandle(SQL::Error _error, long _SQLCODE, const wchar_t *_filename, int _line)
PeConnection(const wchar_t *_serverTitle)
virtual bool __rollbackTrans()
virtual bool __open(const char *_conns, size_t _connslen)
static bool test(const wchar_t *_regex, const wchar_t *_string, bool _icase=false) __DCL_THROWS1(RegexException *)
_PROTECTED const wchar_t * _filename
_PROTECTED const wchar_t int _line