cvs: php4 /pear/DB common.php

From: Date: Mon, 04 Dec 2000 18:28:17 +0000
Subject: cvs: php4 /pear/DB common.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2941@lists.php.net to get a copy of this message
sbergmann Mon Dec 4 10:28:17 2000 EDT Modified files: /php4/pear/DB common.php Log: Added PHPDoc compliant inline documentation for nextid(). Fixed a bug in nextid(). Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.26 php4/pear/DB/common.php:1.27 --- php4/pear/DB/common.php:1.26 Mon Dec 4 09:13:30 2000 +++ php4/pear/DB/common.php Mon Dec 4 10:28:17 2000 @@ -811,6 +811,23 @@ // }}} // {{{ nextid() + /** + * Returns the next number of a given sequence. + * + * This method needs the following table in the used database: + * + * CREATE TABLE db_sequence ( + * seq_name varchar(127) NOT NULL, + * nextid int(10) unsigned DEFAULT '0' NOT NULL, + * PRIMARY KEY (seq_name) + * ); + * + * @param string $seq_name name of the sequence + * @return int next number in $sequence + * @access private + * @author Sebastian Bergmann <sbergmann@php.net> + */ + function nextid( $seq_name ) { // lock db_sequence table @@ -819,26 +836,14 @@ // check, if this sequence already exists $result = $this->query( "select nextid from " . $this->seq_table . " where seq_name = '$seq_name'" ); - // catch db error - if( DB::isError( $result ) ) - { - return false; - } - // sequence already exists if( is_array( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) ) { // get next id for this sequence - $id = $row[ "nextid" ]; + $id = $row[ "nextid" ] + 1; // update next id for this sequence in db_sequence table $result = $this->query( "update " . $this->seq_table . " set nextid = nextid + 1 where seq_name = '$seq_name'" ); - - // catch db error - if( DB::isError( $result ) ) - { - return false; - } } // sequence doesn't exist, create it @@ -849,17 +854,12 @@ // create entry in db_sequence table $result = $this->query( "insert into " . $this->seq_table . " values( '$seq_name', '$id' )" ); - - // catch db error - if( DB::isError( $result ) ) - { - return false; - } } } else { + // table locking failed return false; }

« previous php.cvs (#2941) next »