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
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • 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
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://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
 75:      * @param  mixed   [parameters, ...]
 76:      * @return ResultSet
 77:      */
 78:     public function query($sql)
 79:     {
 80:         return $this->connection->query(func_get_args());
 81:     }
 82: 
 83: 
 84:     /**
 85:      * @param  string
 86:      * @return ResultSet
 87:      */
 88:     public function queryArgs($sql, array $params)
 89:     {
 90:         return $this->connection->queryArgs($sql, $params);
 91:     }
 92: 
 93: 
 94:     /**
 95:      * @param  string
 96:      * @return Table\Selection
 97:      */
 98:     public function table($table)
 99:     {
100:         return new Table\Selection($this, $this->conventions, $table, $this->cacheStorage);
101:     }
102: 
103: 
104:     /** @return Connection */
105:     public function getConnection()
106:     {
107:         return $this->connection;
108:     }
109: 
110: 
111:     /** @return IStructure */
112:     public function getStructure()
113:     {
114:         return $this->structure;
115:     }
116: 
117: 
118:     /** @return IConventions */
119:     public function getConventions()
120:     {
121:         return $this->conventions;
122:     }
123: 
124: 
125:     /** @deprecated */
126:     public function getDatabaseReflection()
127:     {
128:         trigger_error(__METHOD__ . '() is deprecated; use getConventions() instead.', E_USER_DEPRECATED);
129:         return $this->conventions;
130:     }
131: 
132: 
133:     /********************* shortcuts ****************d*g**/
134: 
135: 
136:     /**
137:      * Shortcut for query()->fetch()
138:      * @param  string
139:      * @param  mixed   [parameters, ...]
140:      * @return Row
141:      */
142:     public function fetch($args)
143:     {
144:         return $this->connection->query(func_get_args())->fetch();
145:     }
146: 
147: 
148:     /**
149:      * Shortcut for query()->fetchField()
150:      * @param  string
151:      * @param  mixed   [parameters, ...]
152:      * @return mixed
153:      */
154:     public function fetchField($args)
155:     {
156:         return $this->connection->query(func_get_args())->fetchField();
157:     }
158: 
159: 
160:     /**
161:      * Shortcut for query()->fetchPairs()
162:      * @param  string
163:      * @param  mixed   [parameters, ...]
164:      * @return array
165:      */
166:     public function fetchPairs($args)
167:     {
168:         return $this->connection->query(func_get_args())->fetchPairs();
169:     }
170: 
171: 
172:     /**
173:      * Shortcut for query()->fetchAll()
174:      * @param  string
175:      * @param  mixed   [parameters, ...]
176:      * @return array
177:      */
178:     public function fetchAll($args)
179:     {
180:         return $this->connection->query(func_get_args())->fetchAll();
181:     }
182: 
183: 
184:     /**
185:      * @return SqlLiteral
186:      */
187:     public static function literal($value)
188:     {
189:         $args = func_get_args();
190:         return new SqlLiteral(array_shift($args), $args);
191:     }
192: 
193: }
194: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0