]> git.mjollnir.org Git - s9y.git/commitdiff
allow to return SQL instead of executing it
authorgarvinhicking <garvinhicking>
Thu, 11 May 2006 08:17:22 +0000 (08:17 +0000)
committergarvinhicking <garvinhicking>
Thu, 11 May 2006 08:17:22 +0000 (08:17 +0000)
include/db/db.inc.php

index 7dd278309da6560926a09969844a14fb8405a5c2..ad942c59cbabe59761bb8587495c287b8c02d209 100644 (file)
@@ -21,9 +21,10 @@ if (@include(S9Y_INCLUDE_PATH . "include/db/{$serendipity['dbType']}.inc.php"))
  * @param  string   Name of the DB table
  * @param  array    Input array that controls the "WHERE" condition part. Pass it an associative array like array('key1' => 'value1', 'key2' => 'value2') to get a statement like "WHERE key1 = value1 AND key2 = value2". Escaping is done automatically in this function.
  * @param  array    Input array that controls the "SET" condition part. Pass it an associative array like array('key1' => 'value1', 'key2' => 'value2') to get a statement like "SET key1 = value1, key2 = value2". Escaping is done automatically in this function.
+ * @param  string   What do do with the SQL query (execute, display)
  * @return array    Returns the result of the SQL query
  */
-function serendipity_db_update($table, $keys, $values)
+function serendipity_db_update($table, $keys, $values, $action = 'execute')
 {
     global $serendipity;
 
@@ -46,7 +47,12 @@ function serendipity_db_update($table, $keys, $values)
         $where = " WHERE $where";
     }
 
-    return serendipity_db_query("UPDATE {$serendipity['dbPrefix']}$table SET $set $where");
+    $q = "UPDATE {$serendipity['dbPrefix']}$table SET $set $where";
+    if ($action == 'execute') {
+        return serendipity_db_query($q);
+    } else {
+        return $q;
+    }
 }
 
 /**
@@ -57,9 +63,10 @@ function serendipity_db_update($table, $keys, $values)
  * @access  public
  * @param   string      Name of the SQL table
  * @param   array       Associative array of keys/values to insert into the table. Escaping is done automatically.
+ * @param  string   What do do with the SQL query (execute, display)
  * @return array    Returns the result of the SQL query
  */
-function serendipity_db_insert($table, $values)
+function serendipity_db_insert($table, $values, $action = 'execute')
 {
     global $serendipity;
 
@@ -72,7 +79,13 @@ function serendipity_db_insert($table, $values)
         $vals .= '\'' . serendipity_db_escape_string($v) . '\'';
     }
 
-    return serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}$table ($names) values ($vals)");
+    $q = "INSERT INTO {$serendipity['dbPrefix']}$table ($names) values ($vals)";
+    
+    if ($action == 'execute') {
+        return serendipity_db_query($q);
+    } else {
+        return $q;
+    }
 }
 
 /**