[Phplib-commit] CVS: php-lib-stable/php db_mysql.inc,1.10,1.11
Brought to you by:
nhruby,
richardarcher
|
From: Layne W. <lay...@us...> - 2002-08-07 19:34:02
|
Update of /cvsroot/phplib/php-lib-stable/php
In directory usw-pr-cvs1:/tmp/cvs-serv25099/php
Modified Files:
db_mysql.inc
Log Message:
Fixed [ #542808 ] nextid()'s lock() in db_mysql.inc
Fixed [ #542811 ] nextid() uses mysql_query
In layout_html.inc removed an overlooked calltime pass by reference;
all other calls to defval() were correct
Index: db_mysql.inc
===================================================================
RCS file: /cvsroot/phplib/php-lib-stable/php/db_mysql.inc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** db_mysql.inc 25 Apr 2002 07:36:56 -0000 1.10
--- db_mysql.inc 7 Aug 2002 19:33:57 -0000 1.11
***************
*** 245,292 ****
/* public: sequence numbers */
function nextid($seq_name) {
! $this->connect();
!
! if ($this->lock($this->Seq_Table)) {
! /* get sequence number (locked) and increment */
! $q = sprintf("select nextid from %s where seq_name = '%s'",
! $this->Seq_Table,
! $seq_name);
! $id = @mysql_query($q, $this->Link_ID);
! if (!$id) {
! $this->halt('query failed in nextid: '.$q);
return 0;
}
! $res = @mysql_fetch_array($id);
!
! /* No current value, make one */
! if (!is_array($res)) {
! $currentid = 0;
! $q = sprintf("insert into %s values('%s', %s)",
$this->Seq_Table,
$seq_name,
$currentid);
! $id = @mysql_query($q, $this->Link_ID);
! if (!$id) {
! $this->halt('query failed in nextid: '.$q);
! return 0;
! }
! } else {
! $currentid = $res["nextid"];
! }
! $nextid = $currentid + 1;
! $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
! $this->Seq_Table,
! $nextid,
! $seq_name);
! $id = @mysql_query($q, $this->Link_ID);
! if (!$id) {
$this->halt('query failed in nextid: '.$q);
return 0;
}
- $this->unlock();
} else {
! $this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
return 0;
}
return $nextid;
}
--- 245,296 ----
/* public: sequence numbers */
function nextid($seq_name) {
! /* if no current lock, lock sequence table */
! if(!$this->locked) {
! if($this->lock($this->Seq_Table)) {
! $locked = true;
! } else {
! $this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
return 0;
}
! }
!
! /* get sequence number and increment */
! $q = sprintf("select nextid from %s where seq_name = '%s'",
! $this->Seq_Table,
! $seq_name);
! if(!$this->query($q)) {
! $this->halt('query failed in nextid: '.$q);
! return 0;
! }
!
! /* No current value, make one */
! if(!$this->next_record()) {
! $currentid = 0;
! $q = sprintf("insert into %s values('%s', %s)",
$this->Seq_Table,
$seq_name,
$currentid);
! if(!$this->query($q)) {
$this->halt('query failed in nextid: '.$q);
return 0;
}
} else {
! $currentid = $this->f("nextid");
! }
! $nextid = $currentid + 1;
! $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
! $this->Seq_Table,
! $nextid,
! $seq_name);
! if(!$this->query($q)) {
! $this->halt('query failed in nextid: '.$q);
return 0;
}
+
+ /* if nextid() locked the sequence table, unlock it */
+ if($locked) {
+ $this->unlock();
+ }
+
return $nextid;
}
|