From 95f829db13e0ebb5a36844292f6947700fef8811 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 18 Oct 2023 05:29:14 +0100 Subject: [PATCH] ext/pdo_pgsql: cleanup the 3rd protocol is supported since circa 2010. (#12464) --- ext/pdo_pgsql/pgsql_driver.c | 20 ++------------------ ext/pdo_pgsql/tests/bug48764.phpt | 2 +- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 531bf14e4bb..8205938a438 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -278,10 +278,6 @@ static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t * execute_only = H->disable_prepares; } - if (!emulate && PQprotocolVersion(H->server) <= 2) { - emulate = 1; - } - if (emulate) { stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; } else { @@ -445,19 +441,7 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_ } case PDO_ATTR_SERVER_VERSION: - if (PQprotocolVersion(H->server) >= 3) { /* PostgreSQL 7.4 or later */ - ZVAL_STRING(return_value, (char*)PQparameterStatus(H->server, "server_version")); - } else /* emulate above via a query */ - { - PGresult *res = PQexec(H->server, "SELECT VERSION()"); - if (res && PQresultStatus(res) == PGRES_TUPLES_OK) { - ZVAL_STRING(return_value, (char *)PQgetvalue(res, 0, 0)); - } - - if (res) { - PQclear(res); - } - } + ZVAL_STRING(return_value, (char*)PQparameterStatus(H->server, "server_version")); break; case PDO_ATTR_CONNECTION_STATUS: @@ -675,8 +659,8 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlCopyFromArray) buffer_len = Z_STRLEN_P(tmp); query = erealloc(query, buffer_len + 2); /* room for \n\0 */ } - memcpy(query, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); query_len = Z_STRLEN_P(tmp); + memcpy(query, Z_STRVAL_P(tmp), query_len); if (query[query_len - 1] != '\n') { query[query_len++] = '\n'; } diff --git a/ext/pdo_pgsql/tests/bug48764.phpt b/ext/pdo_pgsql/tests/bug48764.phpt index d77de54e7f0..f75f9c348b4 100644 --- a/ext/pdo_pgsql/tests/bug48764.phpt +++ b/ext/pdo_pgsql/tests/bug48764.phpt @@ -14,7 +14,7 @@ $db = PDOTest::factory(); $client_version = $db->getAttribute(PDO::ATTR_CLIENT_VERSION); $server_version = $db->getAttribute(PDO::ATTR_SERVER_VERSION); -if (version_compare($server_version, '7.4', '<') || version_compare($client_version, '7.4', '<') || version_compare($server_version, '10', '>=')) { +if (version_compare($server_version, '10', '>=')) { die('skip'); }