FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=16867&edit=1

ID: 16867
Updated by: php@gartneriet.dk
Reported By: php at gartneriet dot dk
Summary: PostgreSQL errors when using Native sequences
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: DB_DataObject
Package Version: 1.8.12
PHP Version: Irrelevant
-Assigned To:
+Assigned To: madsliejensen
Roadmap Versions:
New Comment:

-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: madsliejensen



Previous Comments:
------------------------------------------------------------------------

[2009-12-03 08:56:19] alan_k

that's some old code ;)

the config allows you to do this:

sequence_{tablename} = sequencekey_name

------------------------------------------------------------------------

[2009-12-03 08:07:32] madsliejensen

You're right - i missed that my sequences where named
<tablename>_<fieldname>_seq.

It seems like I could then make a sequenceKey()-method in the table's
DataObject, to return the name of the sequence to use. However, the
docblock for DB_DataObject::sequenceKey() say that its a private method,
and the manual page doesn't say anything about this method.
However, the docblock also say: 'Override this to return ....'

------------------------------------------------------------------------

[2009-12-03 00:30:57] alan_k

-Type: Bug
+Type: Documentation Problem
It's not documented (could probably do with a note in the manual
somwhere)
, but you need to create your tables like this.

CREATE TABLE reservations (
id integer DEFAULT nextval('reservations_seq'::text) NOT NULL

sequence name is tablename with _seq at the end.

------------------------------------------------------------------------

[2009-12-02 21:29:32] madsliejensen

Added #patch bug:16867;patch:pgsql-sequence-patch;revision:1259789372;.

------------------------------------------------------------------------

[2009-12-02 21:28:05] madsliejensen

Description:
------------
When a tables primary key is a native sequence, for postgreSQL,
DB_DataObject does a 'SELECT currval(<sequence-name>)' to get the key to
use when inserting a new row. (In DataObject.php line 1084)

However, you cannot call currval() without first having called
nextval(<sequence-name>), thus, there will be an error from postgreSQL.

The correct thing to do would be 'SELECT nextval(<sequence-name>)'
instead.

------------------------------------------------------------------------

Search Discussions

  • Alan at Feb 21, 2011 at 3:03 am
    Edit report at http://pear.php.net/bugs/bug.php?id=16867&edit=1

    ID: 16867
    Updated by: alan@akbkhome.com
    Reported By: php at gartneriet dot dk
    Summary: PostgreSQL errors when using Native sequences
    Status: Closed
    Type: Documentation Problem
    Package: DB_DataObject
    Package Version: 1.8.12
    PHP Version: Irrelevant
    Assigned To: madsliejensen
    Roadmap Versions:
    New Comment:

    doc comments have been fixed in SVN now.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-02-20 09:17:44] madsliejensen

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: madsliejensen


    ------------------------------------------------------------------------

    [2009-12-03 08:56:19] alan_k

    that's some old code ;)

    the config allows you to do this:

    sequence_{tablename} = sequencekey_name

    ------------------------------------------------------------------------

    [2009-12-03 08:07:32] madsliejensen

    You're right - i missed that my sequences where named
    <tablename>_<fieldname>_seq.

    It seems like I could then make a sequenceKey()-method in the table's
    DataObject, to return the name of the sequence to use. However, the
    docblock for DB_DataObject::sequenceKey() say that its a private method,
    and the manual page doesn't say anything about this method.
    However, the docblock also say: 'Override this to return ....'

    ------------------------------------------------------------------------

    [2009-12-03 00:30:57] alan_k

    -Type: Bug
    +Type: Documentation Problem
    It's not documented (could probably do with a note in the manual
    somwhere)
    , but you need to create your tables like this.

    CREATE TABLE reservations (
    id integer DEFAULT nextval('reservations_seq'::text) NOT NULL

    sequence name is tablename with _seq at the end.

    ------------------------------------------------------------------------

    [2009-12-02 21:29:32] madsliejensen

    Added #patch bug:16867;patch:pgsql-sequence-patch;revision:1259789372;.

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    http://pear.php.net/bugs/bug.php?id=16867

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedFeb 20, '11 at 8:15a
activeFeb 21, '11 at 3:03a
posts2
users2
websitepear.php.net

2 users in discussion

Php: 1 post Alan: 1 post

People

Translate

site design / logo © 2021 Grokbase