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

Request #9106 More accurate sequence name
Submitted: 2006-10-20 13:13 UTC
From: mcraig at leadehealth dot com Assigned: quipo
Status: Closed Package: MDB2 (version 1.2.2)
PHP Version: 4.4.3 OS: linux
Roadmaps: (Not assigned)    
Subscription  


 [2006-10-20 13:13 UTC] mcraig at leadehealth dot com (Matt Craig)
Description: ------------ This request is for the driver to do a little more introspection in getSequenceName in order to return a more accurate sequence name. For instance, right now it does not check the tableInfo for SERIAL sequences created by PostgreSQL. It just returns something like "<table>_seq", whereas it should have the ability to look for a column definition containing "nextval(.*)". Through something: // pgsql.php / override getSequenceName function getSequenceName($sqn) { $ti = $this->reverse->tableInfo($sqn); ... grab the col & parse the nextval(); if($found) return $seqnname; return parent::getSequenceName($sqn); } Expected result: ---------------- For example, I use DB_DataObject to access a table called "enrollment" with a sequence called "enrollment_id_seq" that was created by Postgres. My current version of DB_DataObject (via DB, actually) creates and returns a seqeuence named "enrollment_seq" so that when non-PHP programs access the table and use the real sequence there are id collisions. It would be great if MDB could return the real sequence to avoid these collisions.

Comments

 [2006-10-20 14:06 UTC] lsmith (Lukas Smith)
I would not want to make this the default behaviour, because tableInfo() is a very expensive call. i would suggest that people rather read this information themselves and then pass in the necessary information. the actual format of the sequence naming is user controllable via the "seqname_format" option. I took another look at how getSequenceName() is used and I see no way to make a sensible change. One solution would be to make it an option if tableInfo() should be checked, but I am not convinced this makes sense. One thing we could do is provide a convinience method in the extended module that gets the name of the key generating column in a given table with any formatting from "seqname_format" automatically stripped off. If you provide a patch for this I am willing to implement this. DB_DO would then need to call this method in order to determine the name of the sequence.
 [2006-10-25 11:54 UTC] lsmith (Lukas Smith)
Making this a top level MDB2 issue.
 [2006-10-30 17:15 UTC] lsmith (Lukas Smith)
Just found something interesting for postgresql: pg_get_serial_sequence(table_name, column_name) - get name of the sequence that a serial or bigserial column uses
 [2006-11-02 13:55 UTC] mcraig at leadehealth dot com
pg_get_serial_sequence does not seem to be included by default on the latest gentoo postgres 7.4.13, though it is in version 8. Also it still requires introspection to know exactly which column is expected to be the serial column.
 [2007-04-27 16:28 UTC] quipo (Lorenzo Alberton)
I've committed an improved getSequenceName() routine that should be able to retrieve the name of the real sequence associated with the table/field in case of SERIAL datatypes. Can you check it out and tell me if it solves your issues?