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