FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ModernDbManager.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 Authors: Steffen Weber, Andreas Würl
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 namespace Fossology\Lib\Db;
21 
22 use Monolog\Logger;
23 
25 {
26  function __construct(Logger $logger)
27  {
28  parent::__construct($logger);
29  }
30 
36  public function prepare($statementName, $sqlStatement)
37  {
38  if (array_key_exists($statementName, $this->preparedStatements)) {
39  if ($this->preparedStatements[$statementName] !== $sqlStatement) {
40  throw new \Exception("Existing Statement mismatch: $statementName");
41  }
42  return;
43  }
44  $startTime = microtime($get_as_float = true);
45  $res = $this->dbDriver->prepare($statementName, $sqlStatement);
46  $this->cumulatedTime[$statementName] = microtime($get_as_float = true) - $startTime;
47  $this->queryCount[$statementName] = 0;
48  $this->logger->addDebug("prepare '$statementName' took " . sprintf("%0.3fms", 1000 * $this->cumulatedTime[$statementName]));
49  $this->checkResult($res, "$sqlStatement -- $statementName");
50  $this->preparedStatements[$statementName] = $sqlStatement;
51  }
52 
59  public function execute($statementName, $params = array())
60  {
61  if (! array_key_exists($statementName, $this->preparedStatements)) {
62  throw new \Exception("Unknown Statement");
63  }
64  $startTime = microtime($get_as_float = true);
65  $res = $this->dbDriver->execute($statementName, $params);
66  $execTime = microtime($get_as_float = true) - $startTime;
67  $this->collectStatistics($statementName, $execTime);
68  $this->checkResult($res, "$statementName: " . $this->preparedStatements[$statementName] . ' -- -- ' . print_r($params, true));
69  return $res;
70  }
71 }
prepare($statementName, $sqlStatement)
execute($statementName, $params=array())
checkResult($result, $sqlStatement="")
Check the result for unexpected errors. If found, treat them as fatal.
Definition: DbManager.php:127
collectStatistics($statementName, $execTime)
Definition: DbManager.php:285