1--TEST-- 2PDO PgSQL Bug #75402 Possible Memory Leak using PDO::CURSOR_SCROLL option 3--EXTENSIONS-- 4pdo_pgsql 5--SKIPIF-- 6<?php 7require __DIR__ . '/config.inc'; 8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 9PDOTest::skip(); 10?> 11--FILE-- 12<?php 13require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 14$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 15 16$resp = new \stdClass(); 17$resp->entries = []; 18 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?> 85--CLEAN-- 86<?php 87require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 88$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 89$db->exec('DROP TABLE IF EXISTS bug75402'); 90?> 91--EXPECT-- 92object(stdClass)#2 (1) { 93 ["entries"]=> 94 array(1) { 95 [0]=> 96 object(stdClass)#4 (10) { 97 ["sid"]=> 98 string(19) "20171016083645_5337" 99 ["sgroupid"]=> 100 string(21) "G_20171016083645_5337" 101 ["sowner"]=> 102 string(11) "TESTPetunia" 103 ["soperation"]=> 104 string(6) "IMPORT" 105 ["sinfo"]=> 106 string(0) "" 107 ["sshortstatus"]=> 108 string(3) "DON" 109 ["sstatus"]=> 110 string(9) "Completed" 111 ["sprogress"]=> 112 string(3) "100" 113 ["bhidden"]=> 114 string(1) "0" 115 ["sdatetime"]=> 116 string(19) "2017.10.16 08:36:45" 117 } 118 } 119} 120