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
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

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

Interfaces

  • IConventions
  • IRow
  • IRowContainer
  • IStructure
  • ISupplementalDriver

Exceptions

  • ConnectionException
  • ConstraintViolationException
  • DriverException
  • ForeignKeyConstraintViolationException
  • NotNullConstraintViolationException
  • UniqueConstraintViolationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  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
 18: {
 19:     use Nette\SmartObject;
 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
 77:      * @return ResultSet
 78:      */
 79:     public function query($sql, ...$params)
 80:     {
 81:         return $this->connection->query($sql, ...$params);
 82:     }
 83: 
 84: 
 85:     /**
 86:      * @param  string
 87:      * @return ResultSet
 88:      */
 89:     public function queryArgs($sql, array $params)
 90:     {
 91:         return $this->connection->query($sql, ...$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:     /********************* shortcuts ****************d*g**/
127: 
128: 
129:     /**
130:      * Shortcut for query()->fetch()
131:      * @param  string
132:      * @return Row
133:      */
134:     public function fetch($sql, ...$params)
135:     {
136:         return $this->connection->query($sql, ...$params)->fetch();
137:     }
138: 
139: 
140:     /**
141:      * Shortcut for query()->fetchField()
142:      * @param  string
143:      * @return mixed
144:      */
145:     public function fetchField($sql, ...$params)
146:     {
147:         return $this->connection->query($sql, ...$params)->fetchField();
148:     }
149: 
150: 
151:     /**
152:      * Shortcut for query()->fetchPairs()
153:      * @param  string
154:      * @return array
155:      */
156:     public function fetchPairs($sql, ...$params)
157:     {
158:         return $this->connection->query($sql, ...$params)->fetchPairs();
159:     }
160: 
161: 
162:     /**
163:      * Shortcut for query()->fetchAll()
164:      * @param  string
165:      * @return array
166:      */
167:     public function fetchAll($sql, ...$params)
168:     {
169:         return $this->connection->query($sql, ...$params)->fetchAll();
170:     }
171: 
172: 
173:     /**
174:      * @return SqlLiteral
175:      */
176:     public static function literal($value, ...$params)
177:     {
178:         return new SqlLiteral($value, $params);
179:     }
180: }
181: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0