php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24679 pg_insert problem!
Submitted: 2003-07-16 09:44 UTC Modified: 2008-10-16 00:46 UTC
Votes:17
Avg. Score:4.6 ± 0.7
Reproduced:17 of 17 (100.0%)
Same Version:14 (82.4%)
Same OS:15 (88.2%)
From: rorezende at hotmail dot com Assigned: helly (profile)
Status: Closed Package: PostgreSQL related
PHP Version: 4.3.2 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rorezende at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-07-16 09:44 UTC] rorezende at hotmail dot com
Description:
------------
In source code of php 4.3.2 exists an error ext/pgsql/pgsql.c.
In the function pg_convert (php_pgsql_convert) it is not necessary to specify the schema name. But in the sql statement insert it is. Below is the portion of the source code which needs to be fixed.

Reproduce code:
---------------
ext/pgsql/pgsql.c :
function : PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var_array, ulong opt, char **sql TSRMLS_DC)

line (HERE -->	smart_str_appends(&querystr, table);)

Must be something like :

NEW HERE -->	
smart_str_appends(&querystr, schema);
smart_str_appends(&querystr, ".");
smart_str_appends(&querystr, table);

the schema name can be obtained from realnamespace collumn (oid) from table pg_class.

Expected result:
----------------
pg_insert should include the schema name in the insert sql statement.

Actual result:
--------------
the schema name is not specify in sql

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-16 21:28 UTC] sniper@php.net
Please provide an example script which shows the problem clearly.

 [2003-07-23 22:30 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2005-09-21 05:03 UTC] nathanr at nathanr dot net
Nope, this is a genuine bug, I've tested on SuSE Linux Professional 9.3 using both PHP 4.3.10 and 5.0.3 against PostgreSQL 8.0.3. They both produce non-working results. To replicate the bug:

test.sql:
create schema tstschma;
create table tstschma.tsttbl (
x int not null,
y int not null,
primary key (x)
);

now try this php:
$db = pg_connect("dbname=testdb");
$l = array('x'=>'1', 'y'=>'2');
pg_insert($db, "tstschma.tsttbl", $l);
pg_close($db);

If you remove the schema (tstschma) from the name then the select works, but the insert of course does not.

The problem stems from the fact that pg_class.relname does not include the schema name, but to run a query against the table you must have the schema name. I suggest your fix is to strip everything before and including the last dot in the table name (won't change anything for those not using schemas, but will strip "tstschma." from the above example), but use the table name passed to the method (ie. including the "tstschma.") when you go to do the insert.
 [2005-09-21 05:04 UTC] nathanr at nathanr dot net
Nope, this is a genuine bug, I've tested on SuSE Linux Professional 9.3 using both PHP 4.3.10 and 5.0.3 against PostgreSQL 8.0.3. They both produce non-working results. To replicate the bug:

test.sql:
create schema tstschma;
create table tstschma.tsttbl (
x int not null,
y int not null,
primary key (x)
);

now try this php:
$db = pg_connect("dbname=testdb");
$l = array('x'=>'1', 'y'=>'2');
pg_insert($db, "tstschma.tsttbl", $l);
pg_close($db);

If you remove the schema (tstschma) from the name then the select works, but the insert of course does not.

The problem stems from the fact that pg_class.relname does not include the schema name, but to run a query against the table you must have the schema name. I suggest your fix is to strip everything before and including the last dot in the table name (won't change anything for those not using schemas, but will strip "tstschma." from the above example), but use the table name passed to the method (ie. including the "tstschma.") when you go to do the insert.
 [2007-03-14 16:07 UTC] pentropia at gmail dot com
Iv'e noticed the same problem on php 5.2.1
 [2007-08-23 10:42 UTC] frank at geo-dienstleistung dot de
I can confirm this bug on php 5.2.1 too. It really makes this function pretty much useless.
 [2007-08-23 14:41 UTC] frank at geo-dienstleistung dot de
This seems to be true for more than only pg_insert() function. The same error rises when pg_convert() is called with schema in front of table name. So I suspect without testing, that pg_update() and pg_delete suffer from the same bug.
 [2008-10-16 00:46 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC