Re: Re: cvs: php4 /pear DB.php /pear/DBcommon.phpmysql.php

From: Date: Tue, 05 Dec 2000 11:52:22 +0000
Subject: Re: Re: cvs: php4 /pear DB.php /pear/DBcommon.phpmysql.php
References: 1 2 3 4 5 6 7  Groups: php.pear 
Request: Send a blank email to php-pear+get-544@lists.php.net to get a copy of this message
Sebastian Bergmann wrote: > > "Stig S. Bakken" wrote: > > First of all, I think we should be careful about adding features to DB > > that are not portable by concept. > > I thought the way PHPLIB handles this was good practice, given second > thought I think you're right. > > > I've implemented a suggestion in CVS. > > I saw the commit message but can't do a "cvs update" at the moment, since > cvs.php.net doesn't answer, while a ping to toye.php.net succeedes. Okay, this is the stuff I committed to DB/mysql.php: // {{{ nextId() /** * Get the next value in a sequence. We emulate sequences * for MySQL. Will create the sequence if it does not exist. * * @access public * * @param $seq_name the name of the sequence * * @param $ondemand whether to create the sequence table on demand * (default is true) * * @return a sequence integer, or a DB error */ function nextId($seq_name, $ondemand = true) { $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); $repeat = 0; do { $result = $this->query("INSERT INTO db_seq_${sqn} VALUES(NULL)"); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { $repeat = 1; $result = $this->createSequence($seq_name); if (DB::isError($result)) { return $result; } } else { $repeat = 0; } } while ($repeat); if (DB::isError($result)) { return $result; } return mysql_insert_id($this->connection); } // }}} // {{{ createSequence() function createSequence($seq_name) { $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); return $this->query("CREATE TABLE db_seq_${sqn} ". "(id INTEGER AUTO_INCREMENT, PRIMARY KEY(id))"); } // }}} As you can see there is no overhead if the sequence table already exists (or if the second parameter is false). If this solution is good enough for you, I suggest that we remove DB_common::lock/unlock for now. > > Just changing everything like you did is rude, and I want to ask that > > you please refrain from doing changes like that in the future without > > even discussing it on the list first. > > I asked, see > > Message-ID: <3A2A6883.63661324@sebastian-bergmann.de> > Subject: [PHP-PEAR] PEAR::DB equivalent to DB_Sql->nextid() > > , but noone spoke up :-) > > > All you accomplish is to piss someone off. > > Which certainly wasn't my intention. Okay, case closed, let's agree on a standard and move on. :-) - Stig

« previous php.pear (#544) next »