xref: /PHP-8.3/ext/pdo_pgsql/tests/bug75402.phpt (revision 4f84b159)
1--TEST--
2PDO PgSQL Bug #75402 Possible Memory Leak using PDO::CURSOR_SCROLL option
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
16
17$resp = new \stdClass();
18$resp->entries = [];
19
20$db->query('CREATE TABLE bug75402 (
21    "id" character varying(64) NOT NULL,
22    "group_id" character varying(64) NOT NULL,
23    "submitter" character varying(320) NOT NULL,
24    "operation" character varying(32) NOT NULL,
25    "description" character varying(320) NOT NULL,
26    "stage" character varying(16) NOT NULL,
27    "status" character varying(64) NOT NULL,
28    "progress" integer NOT NULL,
29    "insert_datetime" timestamp(3) NOT NULL,
30    "begin_datetime" timestamp(3),
31    "end_datetime" timestamp(3),
32    "life_hours" integer NOT NULL,
33    "family" character varying(32) NOT NULL,
34    "parallelism_group" character varying(32) NOT NULL,
35    "max_parallelism" integer NOT NULL,
36    "hidden" boolean NOT NULL,
37    "abort" boolean NOT NULL,
38    "order_folder_pathname" character varying(320),
39    "worker" character varying(32) NOT NULL,
40    CONSTRAINT "pk_bug75402" PRIMARY KEY ("id")
41) WITH (oids = false);');
42
43
44
45$db->query("INSERT INTO bug75402 (\"id\", \"group_id\", \"submitter\", \"operation\", \"description\", \"stage\", \"status\", \"progress\", \"insert_datetime\", \"begin_datetime\", \"end_datetime\", \"life_hours\", \"family\", \"parallelism_group\", \"max_parallelism\", \"hidden\", \"abort\", \"order_folder_pathname\", \"worker\") VALUES
46('20171016083645_5337',	'G_20171016083645_5337',	'TESTPetunia',	'IMPORT',	'',	'DON',	'Completed',	100,	'2017-10-16 08:36:45',	'2017-10-16 08:36:46',	'2017-10-16 08:36:46',	96,	'IMPORT',	'',	-1,	'f',	'f',	'C:\ProgramData\TestPath\TestApp\Jobs\Jobs\\20171016083645_5337',	'MainService')");
47
48
49
50$sql = "SELECT
51            ID as \"sID\",
52            GROUP_ID as \"sGroupID\",
53            SUBMITTER as \"sOwner\",
54            OPERATION as \"sOperation\",
55            DESCRIPTION as \"sInfo\",
56            STAGE as \"sShortStatus\",
57            STATUS as \"sStatus\",
58            PROGRESS as \"sProgress\",
59            HIDDEN as \"bHidden\",
60            to_char(INSERT_DATETIME, 'IYYY.MM.DD HH24:MI:SS')  as \"sDatetime\"
61          FROM bug75402
62          ORDER BY INSERT_DATETIME DESC";
63
64if ($db) {
65    $stmt = $db->prepare($sql,
66        array(
67            // With the following options memory is not being
68            // deallocated
69              \PDO::ATTR_CURSOR => \PDO::CURSOR_SCROLL
70            // With the following option memory is de-allocated
71            // \PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY
72        )
73    );
74    $stmt->execute();
75
76    while ($entry = $stmt->fetchObject()) {
77      $resp->entries [] = $entry;
78    }
79    $stmt->closeCursor();
80    $stmt = null;
81    $db = null;
82}
83
84var_dump($resp);
85?>
86--CLEAN--
87<?php
88require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
89$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
90$db->exec('DROP TABLE IF EXISTS bug75402');
91?>
92--EXPECT--
93object(stdClass)#2 (1) {
94  ["entries"]=>
95  array(1) {
96    [0]=>
97    object(stdClass)#4 (10) {
98      ["sid"]=>
99      string(19) "20171016083645_5337"
100      ["sgroupid"]=>
101      string(21) "G_20171016083645_5337"
102      ["sowner"]=>
103      string(11) "TESTPetunia"
104      ["soperation"]=>
105      string(6) "IMPORT"
106      ["sinfo"]=>
107      string(0) ""
108      ["sshortstatus"]=>
109      string(3) "DON"
110      ["sstatus"]=>
111      string(9) "Completed"
112      ["sprogress"]=>
113      string(3) "100"
114      ["bhidden"]=>
115      string(1) "0"
116      ["sdatetime"]=>
117      string(19) "2017.10.16 08:36:45"
118    }
119  }
120}
121