|
| 1 | +--TEST-- |
| 2 | +PDO PgSQL PDOStatement::getAttribute(PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE) |
| 3 | +--EXTENSIONS-- |
| 4 | +pdo_pgsql |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +require __DIR__ . '/config.inc'; |
| 8 | +require dirname(__DIR__, 2) . '/pdo/tests/pdo_test.inc'; |
| 9 | +PDOTest::skip(); |
| 10 | +if (!defined('PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE')) die('skip constant PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE does not exist'); |
| 11 | +--FILE-- |
| 12 | +<?php |
| 13 | + |
| 14 | +require_once __DIR__ . "/config.inc"; |
| 15 | + |
| 16 | +/** @var Pdo */ |
| 17 | +$db = Pdo::connect($config['ENV']['PDOTEST_DSN']); |
| 18 | + |
| 19 | +echo 'Result set with only 1 row: '; |
| 20 | +$statement = $db->query('select 1'); |
| 21 | +$result_1 = $statement->getAttribute(PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE); |
| 22 | +var_dump($result_1); |
| 23 | + |
| 24 | +echo 'Result set with many rows: '; |
| 25 | +$result = $db->query('select generate_series(1, 10000)'); |
| 26 | +$result_2 = $result->getAttribute(PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE); |
| 27 | +var_dump($result_2); |
| 28 | + |
| 29 | +echo 'Large result sets should require more memory than small ones: '; |
| 30 | +var_dump($result_2 > $result_1); |
| 31 | + |
| 32 | +echo 'Statements that are not executed should not consume memory: '; |
| 33 | +$statement = $db->prepare('select 1'); |
| 34 | +$result_3 = $statement->getAttribute(PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE); |
| 35 | +var_dump($result_3); |
| 36 | + |
| 37 | +echo 'and should emit Error: '; |
| 38 | +printf("%s: %d: %s\n", ...$statement->errorInfo()); |
| 39 | + |
| 40 | +--EXPECTF-- |
| 41 | +Result set with only 1 row: int(%d) |
| 42 | +Result set with many rows: int(%d) |
| 43 | +Large result sets should require more memory than small ones: bool(true) |
| 44 | +Statements that are not executed should not consume memory: NULL |
| 45 | +and should emit Error: HY000: 0: statement '%s' has not been executed yet |
0 commit comments