Update of /cvsroot/stack/stack-dev/lib/database
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv31600/lib/database
Modified Files:
Tag: STACK2_2
StackDBADOdb.php StackDBCache.php StackDB.php
Log Message:
Fail safely if cache state insert is not successful.
Index: StackDBCache.php
===================================================================
RCS file: /cvsroot/stack/stack-dev/lib/database/StackDBCache.php,v
retrieving revision 1.18.2.10
retrieving revision 1.18.2.11
diff -C2 -d -r1.18.2.10 -r1.18.2.11
*** StackDBCache.php 20 Aug 2010 17:27:02 -0000 1.18.2.10
--- StackDBCache.php 31 Aug 2010 15:07:05 -0000 1.18.2.11
***************
*** 50,57 ****
// add a transition using the new state id
! $transition = $this->addTransition($lastNode, $stateID, $post, $event);
! // add attempt_meta information
! if($userEvent) $this->addMeta($stateID, $state);
}
--- 50,59 ----
// add a transition using the new state id
! if($stateID !== NULL) { // state added successfully: go ahead and reference it!
! $transition = $this->addTransition($lastNode, $stateID, $post, $event);
! // add attempt_meta information
! if($userEvent) $this->addMeta($stateID, $state);
! }
}
***************
*** 59,63 ****
$this->query("UNLOCK TABLES");
! return $transition; // either the new or recent prior one
}
--- 61,65 ----
$this->query("UNLOCK TABLES");
! return $transition; // either the new or recent prior one (or NULL on failure)
}
***************
*** 78,88 ****
", NOW())";
! $this->query($sql);
! // NOTE: if this fails it will mess the transition table because of 'last index' method below.
! $this->logger->debug("SQL debug: ".$sql);
!
// would be nice to be able to obtain the index for the last insert (like mysql_insert_id) without this extra call but would require extending the StackDB interface
! $this->query("SELECT id FROM display_cache ORDER BY id DESC LIMIT 1"); // safe for multi-threading?
if($this->noRows()<=0) { // no rows in display_cache?
--- 80,92 ----
", NOW())";
! //$this->logger->debug("SQL:".$sql);
! $result = $this->query($sql);
! if(empty($result)) { // insert failed!
! $this->logger->critical("Failed to store a question state!");
! return NULL; // don't add a transition!
! }
// would be nice to be able to obtain the index for the last insert (like mysql_insert_id) without this extra call but would require extending the StackDB interface
! $this->query("SELECT id FROM display_cache ORDER BY id DESC LIMIT 1"); // safe for multi-threading if higher-level lock maintained
if($this->noRows()<=0) { // no rows in display_cache?
Index: StackDBADOdb.php
===================================================================
RCS file: /cvsroot/stack/stack-dev/lib/database/StackDBADOdb.php,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -C2 -d -r1.8 -r1.8.2.1
*** StackDBADOdb.php 3 Feb 2010 11:22:29 -0000 1.8
--- StackDBADOdb.php 31 Aug 2010 15:07:05 -0000 1.8.2.1
***************
*** 325,330 ****
}
! public function insert_id() {
! return Insert_ID();
// PO_Insert_ID() is a more portable but untested alternative.
}
--- 325,330 ----
}
! public function last_insert_id() {
! return $this->conn->Insert_ID();
// PO_Insert_ID() is a more portable but untested alternative.
}
Index: StackDB.php
===================================================================
RCS file: /cvsroot/stack/stack-dev/lib/database/StackDB.php,v
retrieving revision 1.5
retrieving revision 1.5.10.1
diff -C2 -d -r1.5 -r1.5.10.1
*** StackDB.php 27 Aug 2009 16:23:00 -0000 1.5
--- StackDB.php 31 Aug 2010 15:07:05 -0000 1.5.10.1
***************
*** 78,81 ****
--- 78,83 ----
public function allResults($field = NULL);
+
+ public function last_insert_id();
}
|