26 function __construct(Logger $logger)
28 parent::__construct($logger);
36 public function prepare($statementName, $sqlStatement)
38 if (array_key_exists($statementName, $this->preparedStatements)) {
39 if ($this->preparedStatements[$statementName] !== $sqlStatement) {
40 throw new \Exception(
"Existing Statement mismatch: $statementName");
44 $this->cumulatedTime[$statementName] = 0;
45 $this->queryCount[$statementName] = 0;
46 $this->preparedStatements[$statementName] = $sqlStatement;
55 public function execute($statementName, $params = array())
57 if (! array_key_exists($statementName, $this->preparedStatements)) {
58 throw new \Exception(
"Unknown Statement");
60 $startTime = microtime(
true);
62 $res = $this->dbDriver->query($statement);
63 $execTime = microtime(
true) - $startTime;
65 $this->logger->addDebug(
"execution of '$statementName' took " . $this->
formatMilliseconds($execTime));
66 $this->
checkResult($res,
"$statementName :: $statement");
78 $sql = $this->preparedStatements[$statementName];
80 foreach ($params as $var) {
83 throw new \Exception(
'given argument for $' . $cnt .
' is null');
86 $masked = $this->dbDriver->booleanToDb($var);
87 }
else if (is_numeric($var)) {
90 $masked =
"'". $this->dbDriver->escapeString($var).
"'";
92 $sqlRep = preg_replace(
'/(\$'.$cnt.
')([^\d]|$)/',
"$masked$2", $sql);
93 if ($sqlRep == $sql) {
94 throw new \Exception(
'$' . $cnt .
' not found in prepared statement');
98 if (preg_match(
'/(\$[\d]+)([^\d]|$)/', $sql, $match)) {
99 $this->logger->addDebug($match[1].
" in '$statementName not resolved");
formatMilliseconds($seconds)
execute($statementName, $params=array())
prepare($statementName, $sqlStatement)
checkResult($result, $sqlStatement="")
Check the result for unexpected errors. If found, treat them as fatal.
evaluateStatement($statementName, $params)
collectStatistics($statementName, $execTime)