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 / Sql / Sql.php
blob940ba464a14d9acee655b4c2830c89801147b2f6
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\Sql;
12 use Zend\Db\Adapter\AdapterInterface;
13 use Zend\Db\Adapter\Driver\StatementInterface;
14 use Zend\Db\Adapter\Platform\PlatformInterface;
16 class Sql
18 /** @var AdapterInterface */
19 protected $adapter = null;
21 /** @var string|array|TableIdentifier */
22 protected $table = null;
24 /** @var Platform\Platform */
25 protected $sqlPlatform = null;
27 public function __construct(AdapterInterface $adapter, $table = null, Platform\AbstractPlatform $sqlPlatform = null)
29 $this->adapter = $adapter;
30 if ($table) {
31 $this->setTable($table);
33 $this->sqlPlatform = ($sqlPlatform) ?: new Platform\Platform($adapter);
36 /**
37 * @return null|\Zend\Db\Adapter\AdapterInterface
39 public function getAdapter()
41 return $this->adapter;
44 public function hasTable()
46 return ($this->table != null);
49 public function setTable($table)
51 if (is_string($table) || is_array($table) || $table instanceof TableIdentifier) {
52 $this->table = $table;
53 } else {
54 throw new Exception\InvalidArgumentException('Table must be a string, array or instance of TableIdentifier.');
56 return $this;
59 public function getTable()
61 return $this->table;
64 public function getSqlPlatform()
66 return $this->sqlPlatform;
69 public function select($table = null)
71 if ($this->table !== null && $table !== null) {
72 throw new Exception\InvalidArgumentException(sprintf(
73 'This Sql object is intended to work with only the table "%s" provided at construction time.',
74 $this->table
75 ));
77 return new Select(($table) ?: $this->table);
80 public function insert($table = null)
82 if ($this->table !== null && $table !== null) {
83 throw new Exception\InvalidArgumentException(sprintf(
84 'This Sql object is intended to work with only the table "%s" provided at construction time.',
85 $this->table
86 ));
88 return new Insert(($table) ?: $this->table);
91 public function update($table = null)
93 if ($this->table !== null && $table !== null) {
94 throw new Exception\InvalidArgumentException(sprintf(
95 'This Sql object is intended to work with only the table "%s" provided at construction time.',
96 $this->table
97 ));
99 return new Update(($table) ?: $this->table);
102 public function delete($table = null)
104 if ($this->table !== null && $table !== null) {
105 throw new Exception\InvalidArgumentException(sprintf(
106 'This Sql object is intended to work with only the table "%s" provided at construction time.',
107 $this->table
110 return new Delete(($table) ?: $this->table);
114 * @param PreparableSqlInterface $sqlObject
115 * @param StatementInterface|null $statement
116 * @return StatementInterface
118 public function prepareStatementForSqlObject(PreparableSqlInterface $sqlObject, StatementInterface $statement = null)
120 $statement = ($statement) ?: $this->adapter->getDriver()->createStatement();
122 if ($this->sqlPlatform) {
123 $this->sqlPlatform->setSubject($sqlObject);
124 $this->sqlPlatform->prepareStatement($this->adapter, $statement);
125 } else {
126 $sqlObject->prepareStatement($this->adapter, $statement);
129 return $statement;
132 public function getSqlStringForSqlObject(SqlInterface $sqlObject, PlatformInterface $platform = null)
134 $platform = ($platform) ?: $this->adapter->getPlatform();
136 if ($this->sqlPlatform) {
137 $this->sqlPlatform->setSubject($sqlObject);
138 $sqlString = $this->sqlPlatform->getSqlString($platform);
139 } else {
140 $sqlString = $sqlObject->getSqlString($platform);
143 return $sqlString;