revert static getParam move

This commit is contained in:
Philipp Holzer 2019-04-14 18:59:38 +02:00
parent c58a1b46b6
commit fe08ad66b3
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
2 changed files with 31 additions and 33 deletions

View File

@ -106,6 +106,22 @@ class DBA
return Database::cleanQuery($sql); return Database::cleanQuery($sql);
} }
/**
* @brief Convert parameter array to an universal form
* @param array $args Parameter array
* @return array universalized parameter array
*/
private static function getParam($args) {
unset($args[0]);
// When the second function parameter is an array then use this as the parameter array
if ((count($args) > 0) && (is_array($args[1]))) {
return $args[1];
} else {
return $args;
}
}
/** /**
* @brief Executes a prepared statement that returns data * @brief Executes a prepared statement that returns data
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid); * @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
@ -119,7 +135,9 @@ class DBA
*/ */
public static function p($sql) public static function p($sql)
{ {
return self::$dba->p($sql); $params = self::getParam(func_get_args());
return self::$dba->p($sql, $params);
} }
/** /**
@ -133,7 +151,9 @@ class DBA
*/ */
public static function e($sql) public static function e($sql)
{ {
return self::$dba->e($sql); $params = self::getParam(func_get_args());
return self::$dba->e($sql, $params);
} }
/** /**
@ -162,7 +182,9 @@ class DBA
*/ */
public static function fetchFirst($sql) public static function fetchFirst($sql)
{ {
return self::$dba->fetchFirst($sql); $params = self::getParam(func_get_args());
return self::$dba->fetchFirst($sql, $params);
} }
/** /**

View File

@ -400,25 +400,6 @@ class Database
return $sql; return $sql;
} }
/**
* @brief Convert parameter array to an universal form
*
* @param array $args Parameter array
*
* @return array universalized parameter array
*/
private static function getParam($args)
{
unset($args[0]);
// When the second function parameter is an array then use this as the parameter array
if ((count($args) > 0) && (is_array($args[1]))) {
return $args[1];
} else {
return $args;
}
}
/** /**
* @brief Executes a prepared statement that returns data * @brief Executes a prepared statement that returns data
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid); * @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
@ -427,17 +408,15 @@ class Database
* For all regular queries please use DBA::select or DBA::exists * For all regular queries please use DBA::select or DBA::exists
* *
* @param string $sql SQL statement * @param string $sql SQL statement
* @param array $params SQL parameters
* *
* @return bool|object statement object or result object * @return bool|object statement object or result object
* @throws \Exception * @throws \Exception
*/ */
public function p($sql) public function p($sql, array $params = [])
{ {
$stamp1 = microtime(true); $stamp1 = microtime(true);
$params = self::getParam(func_get_args());
// Renumber the array keys to be sure that they fit // Renumber the array keys to be sure that they fit
$i = 0; $i = 0;
$args = []; $args = [];
@ -660,17 +639,15 @@ class Database
* Please use DBA::delete, DBA::insert, DBA::update, ... instead * Please use DBA::delete, DBA::insert, DBA::update, ... instead
* *
* @param string $sql SQL statement * @param string $sql SQL statement
* @param array $params SQL parameters
* *
* @return boolean Was the query successfull? False is returned only if an error occurred * @return boolean Was the query successfull? False is returned only if an error occurred
* @throws \Exception * @throws \Exception
*/ */
public function e($sql) public function e($sql, array $params = [])
{ {
$stamp = microtime(true); $stamp = microtime(true);
$params = self::getParam(func_get_args());
// In a case of a deadlock we are repeating the query 20 times // In a case of a deadlock we are repeating the query 20 times
$timeout = 20; $timeout = 20;
@ -768,14 +745,13 @@ class Database
* @brief Fetches the first row * @brief Fetches the first row
* *
* @param string $sql SQL statement * @param string $sql SQL statement
* @param array $params SQL parameters
* *
* @return array first row of query * @return array first row of query
* @throws \Exception * @throws \Exception
*/ */
public function fetchFirst($sql) public function fetchFirst($sql, array $params = [])
{ {
$params = self::getParam(func_get_args());
$stmt = $this->p($sql, $params); $stmt = $this->p($sql, $params);
if (is_bool($stmt)) { if (is_bool($stmt)) {