From: garvinhicking Date: Thu, 11 May 2006 08:17:22 +0000 (+0000) Subject: allow to return SQL instead of executing it X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3fa0df5adb5d200eddec79d37a879fe1931f0b67;p=s9y.git allow to return SQL instead of executing it --- diff --git a/include/db/db.inc.php b/include/db/db.inc.php index 7dd2783..ad942c5 100644 --- a/include/db/db.inc.php +++ b/include/db/db.inc.php @@ -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; + } } /**