Re: DB::nextId() produces undesirable/unexpected results
| From: | Stig S. Bakken | Date: | Fri, 25 Jan 2002 09:57:18 +0000 |
| Subject: | Re: DB::nextId() produces undesirable/unexpected results | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-4148@lists.php.net to get a copy of this message | ||
On Thu, 2002-01-24 at 19:12, Brian Abent wrote:
> Hello,
>
> I am using pgsql. When I call nextid() with the name of a sequence as the
> first parameter, and false as the second parameter, an error occurs. I
> checked the source in DB/pgsql.php and found that nextId() appends '_seq' to
> $seq_name without my permission.
>
> At first I thought this was a bug, because there is no mention of renaming
> $seq_name in the comments above nextId() : * @param string $seq_name the
> name of the sequence
>
> However, I checked oci8.php and found the same behavior so it must be
> intentional. This seems a bit presumptuous on the part of pear db. I
> explicitly passed a valid sequence name to a method that should (according
> to its comments) accept a valid sequence name. I suggest fixing(?) the
> behavior of nextId() (although many people probably rely on this
> functionality by now) or creating a new method that will be compatible with
> existing schemas. I would be happy to contribute to whatever solution the
> pear db team thinks is the best.
I understand your problem, but we can't change the defaults here without
breaking existing code. We could let people set a format string used
for sequence table names, defaulting to "%s_seq", while you would set it
to just "%s". How does that sound?
- Stig
> I suspect this behavior has something to do with allowing nextId() to create
> sequences by default -- therefore attempting to ensure consistent naming of
> sequences. This 'feature' seems unnecessary because any developer or DBA
> that has a clue about their database will have already created their
> sequences -- more than likely at the time they created their tables, defined
> their relationships, and wrote their triggers. While this behavior might
> make PHP/PEAR 'easier' for beginning developers - it alienates developers
> with existing schemas who would like to port applications to PEAR.
>
> One last observation: the first line in nextId is:
> $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name);
> Again, I don't think renaming explicit input is a good idea here. I do
> think validating input and returning a PEAR_Error is an appropriate
> solution. quick example:
>
> < $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name);
> ---
> > if (preg_match('/[^a-z0-9_]/i',$seq_name)) {
> > return new PEAR_Error('Invalid characters in nextId()');
> > }
> > $sqn = $seq_name;
>
> Again, I am happy to contribute code if necessary.
>
> Thanks,
> Brian Abent
>
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>