From: Reini U. <ru...@x-...> - 2005-03-04 15:14:24
|
Arnaud Fontaine schrieb: > -----BEGIN PGP SIGNED MESSAGE----- > Since there is still prob. with sessions when using any SQL backend, I > took a look at the code and found that, in order to check if there is > already a session, DbSession performs an UPDATE and check if 1 line has > been affected. If not, it performs an INSERT. > > Ok .. it's supposed to be more efficient that good old > SELECT/UPDATE/INSERT method ... > > But for some reasons, it doesn't always work : in some cases, the > AffectedRows method returns 0 even if there is a session already there. > Then the INSERT fails ... > > So, unless you have a better idea, lets go back to the good old method. > Here is a diff ... That's already in CVS. DbSession.php,v 1.33 2005/02/27 fix for case-sensitive filesystems with php4 DbSession.php,v 1.32 2005/02/27 Enable USE_SAFE_DBSESSION if you get INSERT duplicate id warnings. With USE_SAFE_DBSESSION: DELETE sess_id INSERT sess_id Without USE_SAFE_DBSESSION: UPDATE sess_id If ! AffectedRows INSERT sess_id > crao@raptor:~/web/phpwiki$ cvs diff lib/DbSession.php > Index: lib/DbSession.php > =================================================================== > RCS file: /cvsroot/phpwiki/phpwiki/lib/DbSession.php,v > retrieving revision 1.30 > diff -r1.30 DbSession.php > 204c204,208 > < $res = $dbh->query("UPDATE $table" > - --- > | $res = $dbh->GetRow("SELECT sess_id FROM $table WHERE > sess_id=$qid"); > | > | if ($res) { > | > | $res = $dbh->query("UPDATE $table" > 207,209c211,213 > < $result = $dbh->AffectedRows(); > < if ( $result === false or $result < 1 ) { // 0 cannot happen, > - -1 (failure) on mysql > < $res = $dbh->query("INSERT INTO $table" > - --- > | } else { > | > | $res = $dbh->query("INSERT INTO $table" > 212c216 > < } > - --- > | } > 419c423,425 > < $rs = $dbh->Execute("UPDATE $table" > - --- > | $res = $dbh->GetRow("SELECT sess_id FROM $table WHERE > sess_id=$qid"); > | if($res) { > | $rs = $dbh->Execute("UPDATE $table" > 422,423c428 > < $result = $dbh->Affected_Rows(); > < if ( $result === false or $result < 1 ) { // false or int > 0 > - --- > | } else { -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban http://phpwiki.org |