Date: 05/06/00
- Next message: athompso: "[phplib-dev] cvs commit"
- Previous message: uw: "[phplib-dev] cvs commit"
- Next in thread: athompso: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: athompso
Date: Sun May 7 05:28:44 2000
Modified files:
php-lib/php/ct_sql.inc
Log message:
Copied in same fix from php-lib-stable before I forget again.
Added workaround for MySQL UPDATE affected_rows() gotcha.
Thanks to Massimo Santoli <saint <email protected>> for suggestion.
Index: php-lib/php/ct_sql.inc
diff -u php-lib/php/ct_sql.inc:1.24 php-lib/php/ct_sql.inc:1.25
--- php-lib/php/ct_sql.inc:1.24 Thu Apr 13 15:28:45 2000
+++ php-lib/php/ct_sql.inc Sun May 7 05:28:13 2000
@@ -7,7 +7,7 @@
##
## Copyright (c) 1998,1999 Sascha Schumann <sascha <email protected>>
##
-## $Id: ct_sql.inc,v 1.24 2000/04/13 13:28:45 kk Exp $
+## $Id: ct_sql.inc,v 1.25 2000/05/07 03:28:13 athompso Exp $
##
## PHPLIB Data Storage Container using a SQL database
##
@@ -81,6 +81,14 @@
$now,
$id,
$name);
+ $squery = sprintf("select count(*) from %s where p_valenc='%s' and p_valpos='%s' and p_val='%s' and p_changed='%s' and p_sid='%s' and p_name='%s'",
+ $this->database_table,
+ $this->encoding_mode,
+ '000000',
+ $str,
+ $now,
+ $id,
+ $name);
$iquery = sprintf("insert into %s ( p_sid, p_name, p_valenc, p_valpos, p_val, p_changed ) values ('%s', '%s', '%s', '%s', '%s', '%s')",
$this->database_table,
$id,
@@ -93,8 +101,22 @@
# This may look wierd, but SELECTing first and then doing the
# right thing would nonatomic (in MySQL, where we cannot SELECT
# FOR UPDATE). This is nonatomic, too, but keeps the window small.
+
+ # FIRST test to see if any rows were affected.
+ # Zero rows affected could mean either there were no matching rows
+ # whatsoever, OR that the update statement did match a row but made
+ # no changes to the table data (i.e. UPDATE tbl SET col = 'x', when
+ # "col" is _already_ set to 'x') so then,
+ # SECOND, query(SELECT...) on the sid to determine if the row is in
+ # fact there,
+ # THIRD, verify that there is at least one row present, and if there
+ # is not, then
+ # FOURTH, insert the row as we've determined that it does not exist.
+
$this->db->query($uquery);
if ( $this->db->affected_rows() == 0
+ && $this->db->query($squery)
+ && $this->db->f(1) == 0
&& !$this->db->query($iquery)) {
$ret = false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: athompso: "[phplib-dev] cvs commit"
- Previous message: uw: "[phplib-dev] cvs commit"
- Next in thread: athompso: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

