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