Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Adapter / Driver / Pdo / Feature / SqliteRowCounter.php
blob08f80b71b5fa9d2e39396b9698b5552a85bfa9db
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Db\Adapter\Driver\Pdo\Feature;
12 use Zend\Db\Adapter\Driver\Feature\AbstractFeature;
13 use Zend\Db\Adapter\Driver\Pdo;
15 /**
16 * SqliteRowCounter
18 class SqliteRowCounter extends AbstractFeature
21 /**
22 * @return string
24 public function getName()
26 return 'SqliteRowCounter';
29 /**
30 * @param \Zend\Db\Adapter\Driver\Pdo\Statement $statement
31 * @return int
33 public function getCountForStatement(Pdo\Statement $statement)
35 $countStmt = clone $statement;
36 $sql = $statement->getSql();
37 if ($sql == '' || stripos($sql, 'select') === false) {
38 return null;
40 $countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')';
41 $countStmt->prepare($countSql);
42 $result = $countStmt->execute();
43 $countRow = $result->getResource()->fetch(\PDO::FETCH_ASSOC);
44 unset($statement, $result);
45 return $countRow['count'];
48 /**
49 * @param $sql
50 * @return null|int
52 public function getCountForSql($sql)
54 if (!stripos($sql, 'select')) {
55 return null;
57 $countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')';
58 /** @var $pdo \PDO */
59 $pdo = $this->pdoDriver->getConnection()->getResource();
60 $result = $pdo->query($countSql);
61 $countRow = $result->fetch(\PDO::FETCH_ASSOC);
62 return $countRow['count'];
65 /**
66 * @param $context
67 * @return closure
69 public function getRowCountClosure($context)
71 $sqliteRowCounter = $this;
72 return function () use ($sqliteRowCounter, $context) {
73 /** @var $sqliteRowCounter SqliteRowCounter */
74 return ($context instanceof Pdo\Statement)
75 ? $sqliteRowCounter->getCountForStatement($context)
76 : $sqliteRowCounter->getCountForSql($context);