Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0b4

Bug #11624 getSequenceName returning incorrect results
Submitted: 2007-07-17 18:53 UTC
From: mystic414 Assigned: quipo
Status: Closed Package: MDB2_Driver_pgsql (version 1.4.1)
PHP Version: 5.2.3 OS: freebsd
Roadmaps: (Not assigned)    

 [2007-07-17 18:53 UTC] mystic414 (Adam Parod)
Description: ------------ I don't claim to understand the SQL query in the getSequenceName method, but I do know that it can return incorrect results. Running that query directly on my server returns two rows. 1: schema.table_field_seq 2: table_field_seq The first result is being returned by the method, when the second field is the needed result. I have identical tables in different schemas, and this method is returning the wrong schema! You need to eliminate the first result somehow, as the schema should be determined solely by the schema search path (which I do have set in my application).


 [2007-07-18 06:05 UTC] quipo (Lorenzo Alberton)
Can you post a script that shows what you experience?
 [2007-07-18 15:27 UTC] mystic414 (Adam Parod)
Here you go. This errors for me, rather than returning the lastInsertId. <?php /* DATABASE CREATION CREATE DATABASE test; CREATE SCHEMA schema1; CREATE SCHEMA schema2; CREATE SCHEMA schema3; CREATE TABLE schema1.mytable ( id SERIAL PRIMARY KEY, value TEXT ); CREATE TABLE schema2.mytable ( id SERIAL PRIMARY KEY, value TEXT ); CREATE TABLE schema3.mytable ( id SERIAL PRIMARY KEY, value TEXT ); */ require_once 'MDB2.php'; $username = ''; $password = ''; $dsn = "pgsql://$username:$password@unix(/tmp/)/test"; $options = array(); $mdb2 =& MDB2::connect($dsn, $options); if (PEAR::isError($mdb2)) { die($mdb2->getMessage()); } /** * schema2 is important... it will not be the first result * returned by getSequenceName */ $res =& $mdb2->query('SET search_path to schema2, public'); if (PEAR::isError($res)) { die($res->getMessage()); } $sql = "INSERT INTO mytable (value) VALUES ('value')"; $affected =& $mdb2->exec($sql); if (PEAR::isError($affected)) { die($affected->getMessage()); } $id = $mdb2->lastInsertId('mytable', 'id'); if (PEAR::isError($id)) { echo "<pre>"; print_r($id); exit; } echo $id; ?>
 [2007-07-18 15:31 UTC] mystic414 (Adam Parod)
Another bug in getSequenceName: list($table, $field) = explode('_', $sqn); will not return the correct $table and $field if either (or both) have an underscore in them, i.e. "my_table", "table_id".
 [2007-07-21 08:24 UTC] quipo (Lorenzo Alberton)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.