81 ByteString conns(_conns, _connslen);
82 const char* regex =
"CURSOR *= *[^&;]*[&;]*";
83 if (conns.searches(regex,
true)) {
84 ByteString
cursor = conns.substring(regex,
true);
87 __cursor = strtol(
cursor, &endptr, 10);
89 conns = conns.replace_r(regex,
"",
true);
92 ListedByteStringToByteStringMap map;
93 Connection::splitConnStr(conns, conns.length(), map);
95 ByteString _USER = map[
"USER"];
96 ByteString _PASSWORD = map[
"PASSWORD"];
97 ByteString _SERVER = map[
"SERVER"];
98 ByteString _PORT = map[
"PORT"];
99 ByteString _DATABASE = map[
"DATABASE"];
100 ByteString _CONNECT_TIMEOUT = map[
"CONNECT_TIMEOUT"];
101 ByteString _APPLICATION = map[
"APPLICATION"];
104 if (!(_USER.isEmpty() || _SERVER.isEmpty() || _DATABASE.isEmpty())) {
106 ByteStringBuilder sb(
"postgresql://");
108 if (!_PASSWORD.isEmpty()) {
109 sb.append(
":").append(_PASSWORD);
111 sb.append(
"@").append(_SERVER);
112 if (!_PORT.isEmpty()) {
113 sb.append(
":").append(_PORT);
115 sb.append(
"/").append(_DATABASE)
116 .append(
"?connect_timeout=")
117 .append(_CONNECT_TIMEOUT.isEmpty() ?
"10" : _CONNECT_TIMEOUT)
118 .append(
"&application_name=")
119 .append(_APPLICATION.isEmpty() ?
"DCL" : _APPLICATION)
121 uri = sb.toByteString();
125 uri = conns.replace_r(
"client_encoding=[^&]*&*",
"",
true);
126 if (uri.indexOf(
'?') == (
size_t)-1) {
129 regex =
"connect_timeout=[^&]*&*";
130 if (!uri.searches(regex,
true)) {
131 uri = uri +
"&connect_timeout=10";
133 regex =
"application_name=[^&]*&*";
134 if (!uri.searches(regex,
true)) {
135 uri = uri +
"&application_name=DCL";
138 uri = uri.replace_r(
"&{2,}",
"&",
true)
139 .replace_r(
"\\?&",
"?",
true)
143 uri = uri +
"&client_encoding=UTF8";
145 uri.data(), String::valueOf(__cursor).data()
148 PGconn* conn = PQconnectdb(uri.data());
149 if (PQstatus(conn) != CONNECTION_OK) {
156 if (!
__execute(
"SET DateStyle TO 'ISO'; SET IntervalStyle TO 'iso_8601'", (
size_t)-1))
159 __DCL_TRACE1_N(L
"client_encoding [%hs]\n", PQparameterStatus(conn,
"client_encoding"));
160 __DCL_TRACE1_N(L
"DateStyle [%hs]\n", PQparameterStatus(conn,
"DateStyle"));
161 __DCL_TRACE1_N(L
"integer_datetimes [%hs]\n", PQparameterStatus(conn,
"integer_datetimes"));
162 __DCL_TRACE1_N(L
"IntervalStyle [%hs]\n", PQparameterStatus(conn,
"IntervalStyle"));;
163 __DCL_TRACE1_N(L
"server_encoding [%hs]\n", PQparameterStatus(conn,
"server_encoding"));
164 __DCL_TRACE1_N(L
"server_version [%hs]\n", PQparameterStatus(conn,
"server_version"));
165 __DCL_TRACE1_N(L
"TimeZone [%hs]\n", PQparameterStatus(conn,
"TimeZone"));
282 int serverVersion = PQserverVersion(__conn);
283 int protocolVersion =
284#ifdef LIBPQ_HAS_FULL_PROTOCOL_VERSION
285 PQfullProtocolVersion(__conn)
287 PQprotocolVersion(__conn) * 10000
290 int libVersion = PQlibVersion();
292 ByteString s = ByteString::format(
"PostgreSQL %d.%d/%d.%d/%d.%d",
293 serverVersion / 10000, serverVersion % 10000,
294 protocolVersion / 10000, protocolVersion % 10000,
295 libVersion / 10000, libVersion % 10000
297 if (s.length() < *_buflen) {
298 *_buflen = s.length();
299 *(_buf + *_buflen) =
'\0';
301 strncpy(_buf, s.data(), *_buflen);