From:             
Operating system: Linux 2.6
PHP version:      5.3.6
Package:          PostgreSQL related
Bug Type:         Bug
Bug description:pg_query_params not returning value from PostgreSQL rule

Description:
------------
When using a PostgreSQL rule to return a value on an INSERT, pg_query's
return is a resource that contains the correct information, while
pg_query_params's return is empty/null.



Tested and confirmed on:

'Linux 2.6.18-194.17.1.el5 #1 SMP Mon Sep 20 07:12:06 EDT 2010 x86_64
x86_64 x86_64 GNU/Linux' running PHP 5.3.5-1 [Note:  Production server -
can't upgrade myself for testing]

and on 

'Linux 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686
i686 i386 GNU/Linux' virtual machine running PHP 5.3.5-1 and then also
tested against 5.3.6 compiled from source.  



Test script:
---------------
Database setup:

    CREATE DATABASE test WITH OWNER = postgres ENCODING = 'UTF8' LC_COLLATE
= 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' CONNECTION LIMIT = -1;

    CREATE SEQUENCE widget_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE
9223372036854775807 START 1 CACHE 1; 

    ALTER TABLE widget_id_seq OWNER TO postgres;

    CREATE TABLE widget ( id serial NOT NULL, widgetname character
varying(20) NOT NULL, inserttime timestamp without time zone NOT NULL,
CONSTRAINT widget_pkey PRIMARY KEY (id) ) WITH ( OIDS=FALSE );

    ALTER TABLE widget OWNER TO postgres;

    CREATE OR REPLACE RULE get_widget_id_on_insert AS ON INSERT TO widget
DO  SELECT currval('widget_id_seq'::text::regclass) AS id;



PHP test script:

<?php

    $db_connection = pg_connect("host=localhost dbname=test
user=postgres");



    $good_query  = "INSERT INTO widget (widgetname, inserttime) VALUES
('Good Test Widget', NOW())";

    $good_result_ref = pg_query($db_connection, $good_query);

    $good_result_data =  pg_fetch_array($good_result_ref);

    echo 'Good result ID:' . $good_result_data['id'] . "\n";



    $bad_query  = 'INSERT INTO widget (widgetname, inserttime) VALUES ($1,
NOW())';

    $bad_params = array('Bad Test Widget');

    $bad_result_ref = pg_query_params($db_connection, $bad_query,
$bad_params);

    $bad_result_data =  pg_fetch_array($bad_result_ref);

    echo 'Bad result ID:' . $bad_result_data['id'] . "\n";



    pg_close($db_connection);

    exit;

?>

Expected result:
----------------
(Note:  The difference between this and the actual result is that "Bad
result ID:" has an integer value (its id) accessible)



[justin@mybox ~]$ php rule_failure.php

Good result ID:1

Bad result ID:2

[justin@mybox ~]$ php rule_failure.php

Good result ID:3

Bad result ID:4

[justin@mybox ~]$ psql --dbname test --user postgres

psql (8.4.7)

Type "help" for help.



test=# SELECT * FROM widget;

 id |    widgetname    |         inserttime

----+------------------+----------------------------

  1 | Good Test Widget | 2011-05-18 15:57:22.182711

  2 | Bad Test Widget  | 2011-05-18 15:57:22.187533

  3 | Good Test Widget | 2011-05-18 15:57:26.16656

  4 | Bad Test Widget  | 2011-05-18 15:57:26.170966

(4 rows)



test=#



Actual result:
--------------
[justin@mybox ~]$ php rule_failure.php

Good result ID:1

Bad result ID:

[justin@mybox ~]$ php rule_failure.php

Good result ID:3

Bad result ID:

[justin@mybox ~]$ psql --dbname test --user postgres

psql (8.4.7)

Type "help" for help.



test=# SELECT * FROM widget;

 id |    widgetname    |         inserttime

----+------------------+----------------------------

  1 | Good Test Widget | 2011-05-18 15:57:22.182711

  2 | Bad Test Widget  | 2011-05-18 15:57:22.187533

  3 | Good Test Widget | 2011-05-18 15:57:26.16656

  4 | Bad Test Widget  | 2011-05-18 15:57:26.170966

(4 rows)



test=#



-- 
Edit bug report at http://bugs.php.net/bug.php?id=54863&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54863&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54863&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54863&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54863&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54863&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54863&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54863&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54863&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54863&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54863&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54863&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54863&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54863&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54863&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54863&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54863&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54863&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54863&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54863&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54863&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54863&r=mysqlcfg

Reply via email to