Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Connection
  • Context
  • Helpers
  • ResultSet
  • Row
  • SqlLiteral
  • SqlPreprocessor
  • Structure

Interfaces

  • IConventions
  • IReflection
  • IRow
  • IRowContainer
  • IStructure
  • ISupplementalDriver

Exceptions

  • ConnectionException
  • ConstraintViolationException
  • DriverException
  • ForeignKeyConstraintViolationException
  • NotNullConstraintViolationException
  • UniqueConstraintViolationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Database;
  9: 
 10: use Nette,
 11:     Nette\Database\Conventions\StaticConventions;
 12: 
 13: 
 14: /**
 15:  * Database context.
 16:  *
 17:  * @author     David Grudl
 18:  */
 19: class Context extends Nette\Object
 20: {
 21:     /** @var Connection */
 22:     private $connection;
 23: 
 24:     /** @var IStructure */
 25:     private $structure;
 26: 
 27:     /** @var IConventions */
 28:     private $conventions;
 29: 
 30:     /** @var Nette\Caching\IStorage */
 31:     private $cacheStorage;
 32: 
 33: 
 34:     public function __construct(Connection $connection, IStructure $structure, IConventions $conventions = NULL, Nette\Caching\IStorage $cacheStorage = NULL)
 35:     {
 36:         $this->connection = $connection;
 37:         $this->structure = $structure;
 38:         $this->conventions = $conventions ?: new StaticConventions;
 39:         $this->cacheStorage = $cacheStorage;
 40:     }
 41: 
 42: 
 43:     /** @return void */
 44:     public function beginTransaction()
 45:     {
 46:         $this->connection->beginTransaction();
 47:     }
 48: 
 49: 
 50:     /** @return void */
 51:     public function commit()
 52:     {
 53:         $this->connection->commit();
 54:     }
 55: 
 56: 
 57:     /** @return void */
 58:     public function rollBack()
 59:     {
 60:         $this->connection->rollBack();
 61:     }
 62: 
 63: 
 64:     /**
 65:      * @param  string  sequence object
 66:      * @return string
 67:      */
 68:     public function getInsertId($name = NULL)
 69:     {
 70:         return $this->connection->getInsertId($name);
 71:     }
 72: 
 73: 
 74:     /**
 75:      * Generates and executes SQL query.
 76:      * @param  string  statement
 77:      * @param  mixed   [parameters, ...]
 78:      * @return ResultSet
 79:      */
 80:     public function query($statement)
 81:     {
 82:         return $this->connection->query(func_get_args());
 83:     }
 84: 
 85: 
 86:     /**
 87:      * @param  string  statement
 88:      * @param  array
 89:      * @return ResultSet
 90:      */
 91:     public function queryArgs($statement, array $params)
 92:     {
 93:         return $this->connection->queryArgs($statement, $params);
 94:     }
 95: 
 96: 
 97:     /**
 98:      * @param  string
 99:      * @return Table\Selection
100:      */
101:     public function table($table)
102:     {
103:         return new Table\Selection($this, $this->conventions, $table, $this->cacheStorage);
104:     }
105: 
106: 
107:     /** @return Connection */
108:     public function getConnection()
109:     {
110:         return $this->connection;
111:     }
112: 
113: 
114:     /** @return IStructure */
115:     public function getStructure()
116:     {
117:         return $this->structure;
118:     }
119: 
120: 
121:     /** @return IConventions */
122:     public function getConventions()
123:     {
124:         return $this->conventions;
125:     }
126: 
127: 
128:     /** @deprecated */
129:     public function getDatabaseReflection()
130:     {
131:         trigger_error(__METHOD__ . '() is deprecated; use getConventions() instead.', E_USER_DEPRECATED);
132:         return $this->conventions;
133:     }
134: 
135: 
136:     /********************* shortcuts ****************d*g**/
137: 
138: 
139:     /**
140:      * Shortcut for query()->fetch()
141:      * @param  string  statement
142:      * @param  mixed   [parameters, ...]
143:      * @return Row
144:      */
145:     public function fetch($args)
146:     {
147:         return $this->connection->query(func_get_args())->fetch();
148:     }
149: 
150: 
151:     /**
152:      * Shortcut for query()->fetchField()
153:      * @param  string  statement
154:      * @param  mixed   [parameters, ...]
155:      * @return mixed
156:      */
157:     public function fetchField($args)
158:     {
159:         return $this->connection->query(func_get_args())->fetchField();
160:     }
161: 
162: 
163:     /**
164:      * Shortcut for query()->fetchPairs()
165:      * @param  string  statement
166:      * @param  mixed   [parameters, ...]
167:      * @return array
168:      */
169:     public function fetchPairs($args)
170:     {
171:         return $this->connection->query(func_get_args())->fetchPairs();
172:     }
173: 
174: 
175:     /**
176:      * Shortcut for query()->fetchAll()
177:      * @param  string  statement
178:      * @param  mixed   [parameters, ...]
179:      * @return array
180:      */
181:     public function fetchAll($args)
182:     {
183:         return $this->connection->query(func_get_args())->fetchAll();
184:     }
185: 
186: 
187:     /**
188:      * @return SqlLiteral
189:      */
190:     public static function literal($value)
191:     {
192:         $args = func_get_args();
193:         return new SqlLiteral(array_shift($args), $args);
194:     }
195: 
196: }
197: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0