cvs: pear /DB/DB common.php
| From: | Fabien MARTY | Date: | Wed, 12 Jun 2002 15:03:17 +0000 |
| Subject: | cvs: pear /DB/DB common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4581@lists.php.net to get a copy of this message | ||
fab Wed Jun 12 11:03:17 2002 EDT
Modified files:
/pear/DB/DB common.php
Log:
a few changes in buildManipSQL() (thanks to Lukas)
Index: pear/DB/DB/common.php
diff -u pear/DB/DB/common.php:1.7 pear/DB/DB/common.php:1.8
--- pear/DB/DB/common.php:1.7 Tue Jun 11 11:57:27 2002
+++ pear/DB/DB/common.php Wed Jun 12 11:03:16 2002
@@ -16,7 +16,7 @@
// | Author: Stig Bakken <ssb@fast.no> |
// +----------------------------------------------------------------------+
//
-// $Id: common.php,v 1.7 2002/06/11 15:57:27 fab Exp $
+// $Id: common.php,v 1.8 2002/06/12 15:03:16 fab Exp $
//
// Base class for DB implementations.
//
@@ -478,7 +478,9 @@
*
* Example : buildManipSQL('table_sql', array('field1', 'field2',
'field3'), DB_AUTOQUERY_INSERT)
* will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES
(?,?,?)
- * NB : This belongs more to a SQL Builder class, but this is a simple facility
+ * NB : - This belongs more to a SQL Builder class, but this is a simple facility
+ * - Be carefull ! If you don't give a $where param with an UPDATE query, all
+ * the records of the table will be updated !
*
* @param string $table name of the table
* @param array $table_fields ordered array containing the fields names
@@ -510,9 +512,6 @@
return "INSERT INTO $table ($names) VALUES ($values)";
break;
case DB_AUTOQUERY_UPDATE:
- if (!$where) { // We need a WHERE statement (if you don't, use a stupid one like
1=1)
- $this->raiseError(DB_ERROR_NEED_MORE_DATA);
- }
$set = '';
while (list(, $value) = each($table_fields)) {
if ($first) {
@@ -522,7 +521,11 @@
}
$set .= "$value = ?";
}
- return "UPDATE $table SET $set WHERE $where";
+ $sql = "UPDATE $table SET $set";
+ if ($where) {
+ $sql .= " WHERE $sql";
+ }
+ return $sql;
break;
default:
$this->raiseError(DB_ERROR_SYNTAX);