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