From cc60cacd485e3d5d7b6b561e51cfa1e60e9ddb53 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 3 Mar 2023 15:34:20 +0100 Subject: [PATCH 01/16] prepare v2.2.1 * Fixed PHP-8.2 compatibility (see gh issue #46) --- package.xml | 10 +++------- php_pq.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/package.xml b/package.xml index 5209743..e989104 100644 --- a/package.xml +++ b/package.xml @@ -41,9 +41,9 @@ remi@php.net yes - 2021-08-30 + 2023-03-03 - 2.2.0 + 2.2.1 2.1.0 @@ -52,11 +52,7 @@ BSD-2-Clause diff --git a/php_pq.h b/php_pq.h index d887a9c..f7a3e44 100644 --- a/php_pq.h +++ b/php_pq.h @@ -14,7 +14,7 @@ #ifndef PHP_PQ_H #define PHP_PQ_H -#define PHP_PQ_VERSION "2.2.0" +#define PHP_PQ_VERSION "2.2.1" #ifdef PHP_WIN32 # define PHP_PQ_API __declspec(dllexport) -- 2.30.2 From 50d036f2061d397ef6d2f0731ae5613190634c90 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 3 May 2023 14:04:41 +0200 Subject: [PATCH 02/16] ci: update actions to ubuntu 22.04 and recent PHP --- .github/workflows/ci.yml | 91 +++++++++++++++++++++--------- scripts/gen_github_workflow_ci.php | 8 +-- 2 files changed, 68 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a546008..fd250c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: enable_maintainer_zts: "yes" enable_json: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -51,7 +51,7 @@ jobs: enable_maintainer_zts: "yes" enable_json: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -87,7 +87,7 @@ jobs: enable_maintainer_zts: "yes" enable_json: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -123,7 +123,7 @@ jobs: enable_maintainer_zts: "yes" enable_json: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -159,7 +159,7 @@ jobs: enable_maintainer_zts: "yes" enable_json: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -187,14 +187,51 @@ jobs: run: | make -f scripts/ci/Makefile test - next-0: - name: "next-0 (8.1)" + old-matrix-5: + name: "old-matrix-5 (8.0)" + env: + PHP: "8.0" + enable_debug: "yes" + enable_maintainer_zts: "yes" + enable_json: "yes" + PQ_DSN: "postgres:///runner" + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + sudo apt-get install -y \ + php-cli \ + php-pear \ + libpq-dev \ + re2c + - name: Prepare + run: | + make -f scripts/ci/Makefile php || make -f scripts/ci/Makefile clean php + make -f scripts/ci/Makefile pecl PECL=m6w6/ext-raphf.git:raphf:master + - name: Build + run: | + make -f scripts/ci/Makefile ext PECL=pq + - name: Prepare Test + run: | + sudo systemctl start postgresql + sudo -u postgres createuser --login runner + sudo -u postgres createdb -O runner runner + - name: Test + run: | + make -f scripts/ci/Makefile test + + old-matrix-6: + name: "old-matrix-6 (8.1)" env: PHP: "8.1" enable_debug: "yes" - enable_zts: "yes" + enable_maintainer_zts: "yes" + enable_json: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -222,15 +259,15 @@ jobs: run: | make -f scripts/ci/Makefile test - next-1: - name: "next-1 (master)" + next-0: + name: "next-0 (master)" continue-on-error: true env: PHP: "master" enable_debug: "yes" enable_zts: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -259,13 +296,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-0: - name: "cur-dbg-zts-0 (8.0)" + name: "cur-dbg-zts-0 (8.2)" env: - PHP: "8.0" + PHP: "8.2" enable_debug: "yes" enable_zts: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -294,13 +331,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-1: - name: "cur-dbg-zts-1 (8.0)" + name: "cur-dbg-zts-1 (8.2)" env: - PHP: "8.0" + PHP: "8.2" enable_debug: "no" enable_zts: "yes" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -329,13 +366,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-2: - name: "cur-dbg-zts-2 (8.0)" + name: "cur-dbg-zts-2 (8.2)" env: - PHP: "8.0" + PHP: "8.2" enable_debug: "yes" enable_zts: "no" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -364,13 +401,13 @@ jobs: make -f scripts/ci/Makefile test cur-dbg-zts-3: - name: "cur-dbg-zts-3 (8.0)" + name: "cur-dbg-zts-3 (8.2)" env: - PHP: "8.0" + PHP: "8.2" enable_debug: "no" enable_zts: "no" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -399,13 +436,13 @@ jobs: make -f scripts/ci/Makefile test cur-cov-0: - name: "cur-cov-0 (8.0)" + name: "cur-cov-0 (8.2)" env: CFLAGS: "-O0 -g --coverage" CXXFLAGS: "-O0 -g --coverage" - PHP: "8.0" + PHP: "8.2" PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: diff --git a/scripts/gen_github_workflow_ci.php b/scripts/gen_github_workflow_ci.php index 7c2e009..78d770a 100755 --- a/scripts/gen_github_workflow_ci.php +++ b/scripts/gen_github_workflow_ci.php @@ -11,16 +11,16 @@ jobs: github([ "old-matrix" => [ - "PHP" => ["7.0", "7.1", "7.2", "7.3", "7.4"], + "PHP" => ["7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"], "enable_debug" => "yes", "enable_maintainer_zts" => "yes", "enable_json" => "yes", ], "next" => [ - "PHP" => ["8.1", "master"], + "PHP" => ["master"], "enable_debug" => "yes", "enable_zts" => "yes", ], @@ -46,7 +46,7 @@ foreach ($job as $id => $env) { } ?> PQ_DSN: "postgres:///runner" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: -- 2.30.2 From 9ff77f91387b319a8acc6ba2e4e625df983a07f3 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 3 May 2023 14:17:21 +0200 Subject: [PATCH 03/16] test #47 --- tests/gh-issue047_jsonb.phpt | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/gh-issue047_jsonb.phpt diff --git a/tests/gh-issue047_jsonb.phpt b/tests/gh-issue047_jsonb.phpt new file mode 100644 index 0000000..1f049d4 --- /dev/null +++ b/tests/gh-issue047_jsonb.phpt @@ -0,0 +1,40 @@ +--TEST-- +json conv broken since 2.2.1 +--SKIPIF-- + +--INI-- +date.timezone=UTC +--FILE-- +defaultFetchType = \pq\Result::FETCH_ASSOC; + +$q = <<exec($q); + +var_dump($r->fetchAll()); +?> +===DONE=== +--EXPECT-- +Test +array(2) { + [0]=> + array(1) { + ["jsonb"]=> + string(4) "text" + } + [1]=> + array(1) { + ["jsonb"]=> + int(0) + } +} +===DONE=== -- 2.30.2 From 63aa327253c94b4a7dc92c0e7920f63ddac2a1f2 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 3 May 2023 13:55:55 +0200 Subject: [PATCH 04/16] fix #47: JSON conv broken since 2.2.1 --- src/php_pq_params.c | 10 ++++------ src/php_pqres.c | 8 ++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/php_pq_params.c b/src/php_pq_params.c index 259fbb9..9e92226 100644 --- a/src/php_pq_params.c +++ b/src/php_pq_params.c @@ -16,9 +16,7 @@ #include #include -#if PHP_PQ_HAVE_PHP_JSON_H -#include /* we've added the include directory to INCLUDES */ -#endif +#include #include #include @@ -75,12 +73,12 @@ unsigned php_pq_params_add_type_oid(php_pq_params_t *p, Oid type) static zend_string *object_param_to_string(php_pq_params_t *p, zval *zobj, Oid type) { -#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON) +#ifdef PHP_PQ_OID_JSON smart_str str = {0}; #endif switch (type) { -#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON) +#ifdef PHP_PQ_OID_JSON # ifdef PHP_PQ_OID_JSONB case PHP_PQ_OID_JSONB: # endif @@ -207,7 +205,7 @@ static zend_string *array_param_to_string(php_pq_params_t *p, zval *zarr, Oid ty struct apply_to_param_from_array_arg arg = {NULL}; switch (type) { -#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON) +#ifdef PHP_PQ_OID_JSON # ifdef PHP_PQ_OID_JSONB case PHP_PQ_OID_JSONB: # endif diff --git a/src/php_pqres.c b/src/php_pqres.c index 5406ebf..e9de463 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -17,9 +17,7 @@ #include #include -#if PHP_PQ_HAVE_PHP_JSON_H -#include /* we've added the include directory to INCLUDES */ -#endif +#include #include @@ -215,7 +213,7 @@ zval *php_pqres_typed_zval(php_pqres_t *res, Oid typ, zval *zv) php_pqdt_from_string(zv, NULL, str->val, str->len, "Y-m-d H:i:s.uO", NULL); break; -#if PHP_PQ_HAVE_PHP_JSON_H && defined(PHP_PQ_OID_JSON) +#ifdef PHP_PQ_OID_JSON # ifdef PHP_PQ_OID_JSONB case PHP_PQ_OID_JSONB: # endif @@ -1350,9 +1348,7 @@ PHP_MINIT_FUNCTION(pqres) zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_SCALAR"), PHP_PQRES_CONV_SCALAR); zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ARRAY"), PHP_PQRES_CONV_ARRAY); zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_DATETIME"), PHP_PQRES_CONV_DATETIME); -#if PHP_PQ_HAVE_PHP_JSON_H zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_JSON"), PHP_PQRES_CONV_JSON); -#endif zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_BYTEA"), PHP_PQRES_CONV_BYTEA); zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ALL"), PHP_PQRES_CONV_ALL); -- 2.30.2 From b86e51c70a5c3dce33955b7a6805362fc5ec097f Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 12 Jun 2023 12:24:59 +0200 Subject: [PATCH 05/16] prepare v2.2.2 * Fix JSON coversion (see gh issue #47) --- package.xml | 7 ++++--- php_pq.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.xml b/package.xml index e989104..402e0db 100644 --- a/package.xml +++ b/package.xml @@ -41,9 +41,9 @@ remi@php.net yes - 2023-03-03 + 2023-06-12 - 2.2.1 + 2.2.2 2.1.0 @@ -52,7 +52,7 @@ BSD-2-Clause @@ -138,6 +138,7 @@ + diff --git a/php_pq.h b/php_pq.h index f7a3e44..a97cdb3 100644 --- a/php_pq.h +++ b/php_pq.h @@ -14,7 +14,7 @@ #ifndef PHP_PQ_H #define PHP_PQ_H -#define PHP_PQ_VERSION "2.2.1" +#define PHP_PQ_VERSION "2.2.2" #ifdef PHP_WIN32 # define PHP_PQ_API __declspec(dllexport) -- 2.30.2 From 7b61c6f8eb76dc00a5e456ebcaaa2166644ef8ae Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 12 Jun 2023 17:09:39 +0200 Subject: [PATCH 06/16] add libraryVersion, protocolVersion and serverVersion properties --- src/php_pqconn.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/php_pqconn.c b/src/php_pqconn.c index 6278323..70e2c82 100644 --- a/src/php_pqconn.c +++ b/src/php_pqconn.c @@ -491,6 +491,40 @@ static void php_pqconn_object_write_def_auto_conv(void *o, zval *value) obj->intern->default_auto_convert = zval_get_long(value) & PHP_PQRES_CONV_ALL; } +#ifdef HAVE_PQLIBVERSION +static void php_pqconn_object_read_lib_version(void *o, zval *return_value) +{ + char ver[16]; + int v = PQlibVersion(); + + if (v < 100000) { + slprintf(ver, sizeof(ver), "%d.%d.%d", v/10000, v/100%100, v%100); + } else { + slprintf(ver, sizeof(ver), "%d.%d", v/10000, v%100); + } + RETVAL_STRING(ver); +} +#endif +static void php_pqconn_object_read_protocol_version(void *o, zval *return_value) +{ + php_pqconn_object_t *obj = o; + + RETVAL_LONG(PQprotocolVersion(obj->intern->conn)); +} +static void php_pqconn_object_read_server_version(void *o, zval *return_value) +{ + php_pqconn_object_t *obj = o; + char ver[16]; + int v = PQserverVersion(obj->intern->conn); + + if (v < 100000) { + slprintf(ver, sizeof(ver), "%d.%d.%d", v/10000, v/100%100, v%100); + } else { + slprintf(ver, sizeof(ver), "%d.%d", v/10000, v%100); + } + RETVAL_STRING(ver); +} + static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t *obj) { zval zsocket, zmember; @@ -2131,6 +2165,20 @@ PHP_MINIT_FUNCTION(pqconn) zend_hash_str_add_mem(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert")-1, (void *) &ph, sizeof(ph)); ph.write = NULL; +#ifdef HAVE_PQLIBVERSION + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("libraryVersion"), ZEND_ACC_PUBLIC); + ph.read = php_pqconn_object_read_lib_version; + zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("libraryVersion"), (void *) &ph, sizeof(ph)); +#endif + + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC); + ph.read = php_pqconn_object_read_protocol_version; + zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("protocolVersion"), (void *) &ph, sizeof(ph)); + + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC); + ph.read = php_pqconn_object_read_server_version; + zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("serverVersion"), (void *) &ph, sizeof(ph)); + zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK); zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD); zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED); -- 2.30.2 From c8b946f8140cebf645d7b5bf5bc7140583a7096d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 12 Jun 2023 17:10:22 +0200 Subject: [PATCH 07/16] use serverVersion to skip json test --- package.xml | 1 + tests/_skipif.inc | 5 ++++- tests/basic003.phpt | 22 ++++++++++++++++++++++ tests/gh-issue047_jsonb.phpt | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/basic003.phpt diff --git a/package.xml b/package.xml index 402e0db..1c7ba19 100644 --- a/package.xml +++ b/package.xml @@ -118,6 +118,7 @@ + diff --git a/tests/_skipif.inc b/tests/_skipif.inc index 9bf235c..0391d77 100644 --- a/tests/_skipif.inc +++ b/tests/_skipif.inc @@ -6,7 +6,10 @@ _ext("pq"); include "_setup.inc"; defined("PQ_DSN") or die("skip PQ_DSN undefined"); try { - new pq\Connection(PQ_DSN); + $c = new pq\Connection(PQ_DSN); + if (defined("SERVER_MIN") && version_compare(SERVER_MIN, $c->serverVersion) > 0) { + die("skip server {$c->serverVersion} is too old, needed " . SERVER_MIN); + } } catch (pq\Exception $e) { die("skip could not connect to PQ_DSN ".$e->getMessage()); } diff --git a/tests/basic003.phpt b/tests/basic003.phpt new file mode 100644 index 0000000..4645e8c --- /dev/null +++ b/tests/basic003.phpt @@ -0,0 +1,22 @@ +--TEST-- +basic functionality +--SKIPIF-- + +--FILE-- +libraryVersion); +var_dump($c->protocolVersion); +var_dump($c->serverVersion); +?> +DONE +--EXPECTF-- +Test +string(%d) "%s" +int(%d) +string(%d) "%s" +DONE diff --git a/tests/gh-issue047_jsonb.phpt b/tests/gh-issue047_jsonb.phpt index 1f049d4..5e145fb 100644 --- a/tests/gh-issue047_jsonb.phpt +++ b/tests/gh-issue047_jsonb.phpt @@ -2,6 +2,7 @@ json conv broken since 2.2.1 --SKIPIF-- --INI-- -- 2.30.2 From 6e1eccce4603846f83b38e74f3f53741e073af10 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 13 Jun 2023 07:32:40 +0200 Subject: [PATCH 08/16] check that needed functions exists --- config9.m4 | 2 ++ src/php_pqconn.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/config9.m4 b/config9.m4 index d3fb2b2..d845e28 100644 --- a/config9.m4 +++ b/config9.m4 @@ -99,6 +99,8 @@ if test "$PHP_PQ" != "no"; then PHP_SUBST(PQ_SHARED_LIBADD) PQ_CHECK_FUNC(PQlibVersion) + PQ_CHECK_FUNC(PQprotocolVersion) + PQ_CHECK_FUNC(PQserverVersion) PQ_CHECK_FUNC(PQconninfo) PQ_CHECK_FUNC(PQsetSingleRowMode) diff --git a/src/php_pqconn.c b/src/php_pqconn.c index 70e2c82..32cc526 100644 --- a/src/php_pqconn.c +++ b/src/php_pqconn.c @@ -505,12 +505,15 @@ static void php_pqconn_object_read_lib_version(void *o, zval *return_value) RETVAL_STRING(ver); } #endif +#ifdef HAVE_PQPROTOCOLVERSION static void php_pqconn_object_read_protocol_version(void *o, zval *return_value) { php_pqconn_object_t *obj = o; RETVAL_LONG(PQprotocolVersion(obj->intern->conn)); } +#endif +#ifdef HAVE_PQSERVERVERSION static void php_pqconn_object_read_server_version(void *o, zval *return_value) { php_pqconn_object_t *obj = o; @@ -524,6 +527,7 @@ static void php_pqconn_object_read_server_version(void *o, zval *return_value) } RETVAL_STRING(ver); } +#endif static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t *obj) { @@ -2171,13 +2175,17 @@ PHP_MINIT_FUNCTION(pqconn) zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("libraryVersion"), (void *) &ph, sizeof(ph)); #endif +#ifdef HAVE_PQPROTOCOLVERSION zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC); ph.read = php_pqconn_object_read_protocol_version; zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("protocolVersion"), (void *) &ph, sizeof(ph)); +#endif +#ifdef HAVE_PQSERVERVERSION zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC); ph.read = php_pqconn_object_read_server_version; zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("serverVersion"), (void *) &ph, sizeof(ph)); +#endif zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK); zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD); -- 2.30.2 From e0a5926fd4e74fac3ab128ddae275f5ba785af5d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 12 Jun 2023 16:25:20 +0200 Subject: [PATCH 09/16] fix library version in PHPinfo --- src/php_pq_module.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/php_pq_module.c b/src/php_pq_module.c index cd99217..3d6dacb 100644 --- a/src/php_pq_module.c +++ b/src/php_pq_module.c @@ -105,7 +105,11 @@ static PHP_MINFO_FUNCTION(pq) php_info_print_table_header(3, "Used Library", "Compiled", "Linked"); #ifdef HAVE_PQLIBVERSION libpq_v = PQlibVersion(); - slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000%100, libpq_v/100%100, libpq_v%100); + if (libpq_v < 100000) { + slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000, libpq_v/100%100, libpq_v%100); + } else { + slprintf(libpq_version, sizeof(libpq_version), "%d.%d", libpq_v/10000, libpq_v%100); + } #endif php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version); php_info_print_table_end(); -- 2.30.2 From ee45162841e41d7eea48c9fb6f2082e3dc449ddc Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 13 Jun 2023 15:06:39 +0200 Subject: [PATCH 10/16] add php_pq_version_to_string() helper (factorization) --- src/php_pq_misc.c | 8 ++++++++ src/php_pq_misc.h | 2 ++ src/php_pq_module.c | 6 +----- src/php_pqconn.c | 14 ++------------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/php_pq_misc.c b/src/php_pq_misc.c index 9acef34..4d251d2 100644 --- a/src/php_pq_misc.c +++ b/src/php_pq_misc.c @@ -29,6 +29,14 @@ #undef PHP_PQ_TYPE #include "php_pq_type.h" +/* convert version to string */ +extern void php_pq_version_to_string(int version, char *buffer, int len) { + if (version < 100000) { + slprintf(buffer, len, "%d.%d.%d", version/10000, version/100%100, version%100); + } else { /* since version 10 */ + slprintf(buffer, len, "%d.%d", version/10000, version%100); + } +} /* clear result object associated with a result handle */ void php_pqres_clear(PGresult *r) { diff --git a/src/php_pq_misc.h b/src/php_pq_misc.h index 34ab6c1..d86beeb 100644 --- a/src/php_pq_misc.h +++ b/src/php_pq_misc.h @@ -33,6 +33,8 @@ extern PGresult *php_pq_exec_params(PGconn *conn, const char *command, int nPara extern PGresult *php_pq_prepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes); extern PGresult *php_pq_exec_prepared(PGconn *conn, const char *stmtName, int nParams, const char *const * paramValues, const int *paramLengths, const int *paramFormats, int resultFormat); +/* convert version to string */ +extern void php_pq_version_to_string(int version, char *buffer, int len); /* trim LF from EOL */ extern char *php_pq_rtrim(char *e); diff --git a/src/php_pq_module.c b/src/php_pq_module.c index 3d6dacb..7385b0b 100644 --- a/src/php_pq_module.c +++ b/src/php_pq_module.c @@ -105,11 +105,7 @@ static PHP_MINFO_FUNCTION(pq) php_info_print_table_header(3, "Used Library", "Compiled", "Linked"); #ifdef HAVE_PQLIBVERSION libpq_v = PQlibVersion(); - if (libpq_v < 100000) { - slprintf(libpq_version, sizeof(libpq_version), "%d.%d.%d", libpq_v/10000, libpq_v/100%100, libpq_v%100); - } else { - slprintf(libpq_version, sizeof(libpq_version), "%d.%d", libpq_v/10000, libpq_v%100); - } + php_pq_version_to_string(libpq_v, libpq_version, sizeof(libpq_version)); #endif php_info_print_table_row(3, "libpq", PHP_PQ_LIBVERSION, libpq_version); php_info_print_table_end(); diff --git a/src/php_pqconn.c b/src/php_pqconn.c index 32cc526..0e9e32f 100644 --- a/src/php_pqconn.c +++ b/src/php_pqconn.c @@ -495,13 +495,8 @@ static void php_pqconn_object_write_def_auto_conv(void *o, zval *value) static void php_pqconn_object_read_lib_version(void *o, zval *return_value) { char ver[16]; - int v = PQlibVersion(); - if (v < 100000) { - slprintf(ver, sizeof(ver), "%d.%d.%d", v/10000, v/100%100, v%100); - } else { - slprintf(ver, sizeof(ver), "%d.%d", v/10000, v%100); - } + php_pq_version_to_string(PQlibVersion(), ver, sizeof(ver)); RETVAL_STRING(ver); } #endif @@ -518,13 +513,8 @@ static void php_pqconn_object_read_server_version(void *o, zval *return_value) { php_pqconn_object_t *obj = o; char ver[16]; - int v = PQserverVersion(obj->intern->conn); - if (v < 100000) { - slprintf(ver, sizeof(ver), "%d.%d.%d", v/10000, v/100%100, v%100); - } else { - slprintf(ver, sizeof(ver), "%d.%d", v/10000, v%100); - } + php_pq_version_to_string(PQserverVersion(obj->intern->conn), ver, sizeof(ver)); RETVAL_STRING(ver); } #endif -- 2.30.2 From d7871d891a32d77df66ce5738dbd2a5a25d5a504 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 13 Jun 2023 16:13:08 +0200 Subject: [PATCH 11/16] new properties are read only --- src/php_pq_misc.h | 3 +++ src/php_pqconn.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/php_pq_misc.h b/src/php_pq_misc.h index d86beeb..dab24ec 100644 --- a/src/php_pq_misc.h +++ b/src/php_pq_misc.h @@ -101,6 +101,9 @@ extern int php_pq_compare_index(const void *lptr, const void *rptr); ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args) #endif +#ifndef ZEND_ACC_READONLY +#define ZEND_ACC_READONLY 0 +#endif extern PHP_MINIT_FUNCTION(pq_misc); diff --git a/src/php_pqconn.c b/src/php_pqconn.c index 0e9e32f..19ea6f0 100644 --- a/src/php_pqconn.c +++ b/src/php_pqconn.c @@ -2160,19 +2160,19 @@ PHP_MINIT_FUNCTION(pqconn) ph.write = NULL; #ifdef HAVE_PQLIBVERSION - zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("libraryVersion"), ZEND_ACC_PUBLIC); + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("libraryVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY); ph.read = php_pqconn_object_read_lib_version; zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("libraryVersion"), (void *) &ph, sizeof(ph)); #endif #ifdef HAVE_PQPROTOCOLVERSION - zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC); + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY); ph.read = php_pqconn_object_read_protocol_version; zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("protocolVersion"), (void *) &ph, sizeof(ph)); #endif #ifdef HAVE_PQSERVERVERSION - zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC); + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC|ZEND_ACC_READONLY); ph.read = php_pqconn_object_read_server_version; zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("serverVersion"), (void *) &ph, sizeof(ph)); #endif -- 2.30.2 From 85e091d9fdee787e2bfe37edd9cb95e995642c68 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 21 Aug 2023 14:38:29 +0200 Subject: [PATCH 12/16] Fix doc links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a7d54c3..c823ddd 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ This is a modern binding to the mature [libpq](http://www.postgresql.org/docs/cu ### Highlights: -* Nearly 100% support for [asynchronous usage](https://mdref.m6w6.name/pq/Connection/:+Asynchronous+Usage). -* Extended [type support by pg_type](https://mdref.m6w6.name/pq/Types/:+Overview). +* Nearly 100% support for [asynchronous usage](https://mdref.m6w6.name/pq/Connection/:%20Asynchronous%20Usage). +* Extended [type support by pg_type](https://mdref.m6w6.name/pq/Types/:%20Overview). * Fetching simple [multi-dimensional array maps](https://mdref.m6w6.name/pq/Result/map). * Working [Gateway implementation](https://github.com/m6w6/pq-gateway). -- 2.30.2 From e81e57aadf5647511f5c27843ea565a141cf2e3d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 29 Jan 2024 16:47:49 +0100 Subject: [PATCH 13/16] Fix incompatible pointer types --- src/php_pqlob.c | 2 +- src/php_pqres.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/php_pqlob.c b/src/php_pqlob.c index 0cb44a8..a419390 100644 --- a/src/php_pqlob.c +++ b/src/php_pqlob.c @@ -169,7 +169,7 @@ static int php_pqlob_stream_flush(php_stream *stream) return SUCCESS; } -static ZEND_RESULT_CODE php_pqlob_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset) +static ZEND_RESULT_CODE php_pqlob_stream_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset) { ZEND_RESULT_CODE rv = FAILURE; php_pqlob_object_t *obj = stream->abstract; diff --git a/src/php_pqres.c b/src/php_pqres.c index e9de463..c8262ac 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -398,24 +398,24 @@ static zend_object_iterator_funcs php_pqres_iterator_funcs = { #endif }; -static inline ZEND_RESULT_CODE php_pqres_count_elements_ex(zend_object *object, long *count) +static inline ZEND_RESULT_CODE php_pqres_count_elements_ex(zend_object *object, zend_long *count) { php_pqres_object_t *obj = PHP_PQ_OBJ(NULL, object); if (!obj->intern) { return FAILURE; } else { - *count = (long) PQntuples(obj->intern->res); + *count = (zend_long) PQntuples(obj->intern->res); return SUCCESS; } } #if PHP_VERSION_ID >= 80000 -static ZEND_RESULT_CODE php_pqres_count_elements(zend_object *object, long *count) +static ZEND_RESULT_CODE php_pqres_count_elements(zend_object *object, zend_long *count) { return php_pqres_count_elements_ex(object, count); } #else -static ZEND_RESULT_CODE php_pqres_count_elements(zval *object, long *count) +static ZEND_RESULT_CODE php_pqres_count_elements(zval *object, zend_long *count) { return php_pqres_count_elements_ex(Z_OBJ_P(object), count); } -- 2.30.2 From 77dce501422e1402bb70ba3aad94e070850aaa3b Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 29 Jan 2024 16:50:42 +0100 Subject: [PATCH 14/16] Fix [-Wformat=] --- src/php_pqres.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/php_pqres.c b/src/php_pqres.c index c8262ac..e3986c5 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -736,7 +736,7 @@ static ZEND_RESULT_CODE column_nn(php_pqres_object_t *obj, zval *zcol, php_pqres } if (!col->name) { - php_error_docref(NULL, E_WARNING, "Failed to find column at index %ld", index); + php_error_docref(NULL, E_WARNING, "Failed to find column at index " ZEND_LONG_FMT, index); return FAILURE; } if (col->num == -1) { @@ -791,7 +791,7 @@ static int apply_bound(zval *zbound, int argc, va_list argv, zend_hash_key *key) ZEND_RESULT_CODE *rv = va_arg(argv, ZEND_RESULT_CODE *); if (!(zvalue = zend_hash_index_find(Z_ARRVAL_P(zrow), key->h))) { - php_error_docref(NULL, E_WARNING, "Failed to find column ad index %lu", key->h); + php_error_docref(NULL, E_WARNING, "Failed to find column ad index " ZEND_ULONG_FMT, key->h); *rv = FAILURE; return ZEND_HASH_APPLY_STOP; } else { -- 2.30.2 From ea88a82879ac87d41c03d80ea285d843346f2114 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 29 Jan 2024 17:05:04 +0100 Subject: [PATCH 15/16] Fix incompatible pointer types --- src/php_pqres.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php_pqres.c b/src/php_pqres.c index e3986c5..802fcf4 100644 --- a/src/php_pqres.c +++ b/src/php_pqres.c @@ -1172,7 +1172,7 @@ static PHP_METHOD(pqres, count) { zend_restore_error_handling(&zeh); if (SUCCESS == rv) { - long count; + zend_long count; if (SUCCESS != php_pqres_count_elements_ex(Z_OBJ_P(getThis()), &count)) { throw_exce(EX_UNINITIALIZED, "pq\\Result not initialized"); -- 2.30.2 From 4f1f575de002c0e7037be44fc7d1f7e83d84af22 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 5 Feb 2024 19:56:09 +0100 Subject: [PATCH 16/16] prepare v2.2.3 --- package.xml | 6 +++--- php_pq.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.xml b/package.xml index 1c7ba19..e6b668e 100644 --- a/package.xml +++ b/package.xml @@ -41,9 +41,9 @@ remi@php.net yes - 2023-06-12 + 2024-02-05 - 2.2.2 + 2.2.3 2.1.0 @@ -52,7 +52,7 @@ BSD-2-Clause diff --git a/php_pq.h b/php_pq.h index a97cdb3..022c553 100644 --- a/php_pq.h +++ b/php_pq.h @@ -14,7 +14,7 @@ #ifndef PHP_PQ_H #define PHP_PQ_H -#define PHP_PQ_VERSION "2.2.2" +#define PHP_PQ_VERSION "2.2.3" #ifdef PHP_WIN32 # define PHP_PQ_API __declspec(dllexport) -- 2.30.2