File tree Expand file tree Collapse file tree 4 files changed +68
-1
lines changed Expand file tree Collapse file tree 4 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,9 @@ PHP_MINIT_FUNCTION(pdo_pgsql)
156
156
REGISTER_PDO_CLASS_CONST_LONG ("PGSQL_TRANSACTION_INTRANS" , (zend_long )PGSQL_TRANSACTION_INTRANS );
157
157
REGISTER_PDO_CLASS_CONST_LONG ("PGSQL_TRANSACTION_INERROR" , (zend_long )PGSQL_TRANSACTION_INERROR );
158
158
REGISTER_PDO_CLASS_CONST_LONG ("PGSQL_TRANSACTION_UNKNOWN" , (zend_long )PGSQL_TRANSACTION_UNKNOWN );
159
+ #ifdef HAVE_PG_RESULT_MEMORY_SIZE
160
+ REGISTER_PDO_CLASS_CONST_LONG ("PGSQL_ATTR_RESULT_MEMORY_SIZE" , (zend_long )PRO_PGSQL_ATTR_RESULT_MEMORY_SIZE );
161
+ #endif
159
162
160
163
PdoPgsql_ce = register_class_PdoPgsql (pdo_dbh_ce );
161
164
PdoPgsql_ce -> create_object = pdo_dbh_new ;
Original file line number Diff line number Diff line change @@ -705,6 +705,26 @@ static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt)
705
705
return 1 ;
706
706
}
707
707
708
+ static int pgsql_stmt_get_attr (pdo_stmt_t * stmt , zend_long attr , zval * val )
709
+ {
710
+ pdo_pgsql_stmt * S = (pdo_pgsql_stmt * )stmt -> driver_data ;
711
+
712
+ switch (attr ) {
713
+ #ifdef HAVE_PG_RESULT_MEMORY_SIZE
714
+ case PRO_PGSQL_ATTR_RESULT_MEMORY_SIZE :
715
+ if (stmt -> executed ) {
716
+ ZVAL_LONG (val , PQresultMemorySize (S -> result ));
717
+ } else {
718
+ ZVAL_NULL (val );
719
+ }
720
+ return 1 ;
721
+ #endif
722
+
723
+ default :
724
+ return 0 ;
725
+ }
726
+ }
727
+
708
728
const struct pdo_stmt_methods pgsql_stmt_methods = {
709
729
pgsql_stmt_dtor ,
710
730
pgsql_stmt_execute ,
@@ -713,7 +733,7 @@ const struct pdo_stmt_methods pgsql_stmt_methods = {
713
733
pgsql_stmt_get_col ,
714
734
pgsql_stmt_param_hook ,
715
735
NULL , /* set_attr */
716
- NULL , /* get_attr */
736
+ pgsql_stmt_get_attr ,
717
737
pgsql_stmt_get_column_meta ,
718
738
NULL , /* next_rowset */
719
739
pdo_pgsql_stmt_cursor_closer
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ extern const struct pdo_stmt_methods pgsql_stmt_methods;
86
86
87
87
enum {
88
88
PDO_PGSQL_ATTR_DISABLE_PREPARES = PDO_ATTR_DRIVER_SPECIFIC ,
89
+ PRO_PGSQL_ATTR_RESULT_MEMORY_SIZE ,
89
90
};
90
91
91
92
struct pdo_pgsql_lob_self {
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ PDO PgSQL PDOStatement::getAttribute(PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE)
3
+ --EXTENSIONS--
4
+ pdo
5
+ pdo_pgsql
6
+ --SKIPIF--
7
+ <?php
8
+ require __DIR__ . '/config.inc ' ;
9
+ require dirname (__DIR__ , 2 ) . '/pdo/tests/pdo_test.inc ' ;
10
+ PDOTest::skip ();
11
+ if (!defined ('PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE ' )) die ('skip constant PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE does not exist ' );
12
+ ?>
13
+ --FILE--
14
+ <?php
15
+
16
+ require_once __DIR__ . "/config.inc " ;
17
+
18
+ /** @var Pdo */
19
+ $ db = Pdo::connect ($ config ['ENV ' ]['PDOTEST_DSN ' ]);
20
+
21
+ echo 'Result set with only 1 row: ' ;
22
+ $ statement = $ db ->query ('select 1 ' );
23
+ $ result_1 = $ statement ->getAttribute (PDO ::PGSQL_ATTR_RESULT_MEMORY_SIZE );
24
+ var_dump ($ result_1 );
25
+
26
+ echo 'Result set with many rows: ' ;
27
+ $ result = $ db ->query ('select generate_series(1, 10000) ' );
28
+ $ result_2 = $ result ->getAttribute (PDO ::PGSQL_ATTR_RESULT_MEMORY_SIZE );
29
+ var_dump ($ result_2 );
30
+
31
+ echo 'Large result sets should require more memory than small ones: ' ;
32
+ var_dump ($ result_2 > $ result_1 );
33
+
34
+ echo 'Statements that are not executed should not consume memory: ' ;
35
+ $ statement = $ db ->prepare ('select 1 ' );
36
+ $ result_3 = $ statement ->getAttribute (PDO ::PGSQL_ATTR_RESULT_MEMORY_SIZE );
37
+ var_dump ($ result_3 );
38
+
39
+ --EXPECTF --
40
+ Result set with only 1 row: int(%d)
41
+ Result set with many rows: int(%d)
42
+ Large result sets should require more memory than small ones: bool(true)
43
+ Statements that are not executed should not consume memory: NULL
You can’t perform that action at this time.
0 commit comments