summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql/pgsql_driver.c
diff options
context:
space:
mode:
authorMatteo Beccati <mbeccati@php.net>2009-04-30 12:38:43 +0000
committerMatteo Beccati <mbeccati@php.net>2009-04-30 12:38:43 +0000
commit6e22ab5e3eb0593cd17903621995da25edb29ef5 (patch)
treef0667b5dc6c3f51ffd54d4867db86d206a9f7de9 /ext/pdo_pgsql/pgsql_driver.c
parent5c97c813a9c50f05b7041e3b8d33d202a4ee5693 (diff)
downloadphp-git-6e22ab5e3eb0593cd17903621995da25edb29ef5.tar.gz
MFH:
- Changed PDO_PGSQL configure script to require libpq 7.4 - Cleaned up usage of HAVE_PQ* defines - Fixed compiler warnings - Removed custom implementation of PQunescapeByte # Rationale: # - PDO_PGSQL couldn't even compile when using libpq 7.3 # - PostgreSQL 7.3 is unsupported since a long time # - Got consensus from pgsql devs on freenode
Diffstat (limited to 'ext/pdo_pgsql/pgsql_driver.c')
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index b9bafd3326..80b34c9039 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -232,7 +232,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
if (S->cursor_name) {
efree(S->cursor_name);
}
- spprintf(&S->cursor_name, 0, "pdo_pgsql_cursor_%08x", (unsigned int) stmt);
+ spprintf(&S->cursor_name, 0, "pdo_crsr_%016lx", (unsigned long) stmt);
#if HAVE_PQPREPARE
emulate = 1;
#endif
@@ -264,7 +264,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
return 0;
}
- spprintf(&S->stmt_name, 0, "pdo_pgsql_stmt_%08x", (unsigned int)stmt);
+ spprintf(&S->stmt_name, 0, "pdo_stmt_%016lx", (unsigned long)stmt);
/* that's all for now; we'll defer the actual prepare until the first execute call */
if (nsql) {
@@ -300,9 +300,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
return -1;
}
H->pgoid = PQoidValue(res);
-#if HAVE_PQCMDTUPLES
ret = atol(PQcmdTuples(res));
-#endif
PQclear(res);
return ret;
@@ -312,16 +310,17 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
{
unsigned char *escaped;
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
+ size_t tmp_len;
switch (paramtype) {
case PDO_PARAM_LOB:
/* escapedlen returned by PQescapeBytea() accounts for trailing 0 */
#ifdef HAVE_PQESCAPE_BYTEA_CONN
- escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, quotedlen);
+ escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, &tmp_len);
#else
- escaped = PQescapeBytea(unquoted, unquotedlen, quotedlen);
+ escaped = PQescapeBytea(unquoted, unquotedlen, &tmp_len);
#endif
- *quotedlen += 1;
+ *quotedlen = (int)tmp_len + 1;
*quoted = emalloc(*quotedlen + 1);
memcpy((*quoted)+1, escaped, *quotedlen-2);
(*quoted)[0] = '\'';
@@ -402,11 +401,9 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
break;
case PDO_ATTR_SERVER_VERSION:
-#ifdef HAVE_PQPROTOCOLVERSION
if (PQprotocolVersion(H->server) >= 3) { /* PostgreSQL 7.4 or later */
ZVAL_STRING(return_value, (char*)PQparameterStatus(H->server, "server_version"), 1);
} else /* emulate above via a query */
-#endif
{
PGresult *res = PQexec(H->server, "SELECT VERSION()");
if (res && PQresultStatus(res) == PGRES_TUPLES_OK) {
@@ -456,7 +453,6 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
case PDO_ATTR_SERVER_INFO: {
int spid = PQbackendPID(H->server);
char *tmp;
-#ifdef HAVE_PQPROTOCOLVERSION
spprintf(&tmp, 0,
"PID: %d; Client Encoding: %s; Is Superuser: %s; Session Authorization: %s; Date Style: %s",
spid,
@@ -464,9 +460,6 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
(char*)PQparameterStatus(H->server, "is_superuser"),
(char*)PQparameterStatus(H->server, "session_authorization"),
(char*)PQparameterStatus(H->server, "DateStyle"));
-#else
- spprintf(&tmp, 0, "PID: %d", spid);
-#endif
ZVAL_STRING(return_value, tmp, 0);
}
break;