1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Database;
9:
10: use Nette;
11: use Nette\Database\Conventions\StaticConventions;
12:
13:
14: 15: 16:
17: class Context
18: {
19: use Nette\SmartObject;
20:
21:
22: private $connection;
23:
24:
25: private $structure;
26:
27:
28: private $conventions;
29:
30:
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:
44: public function beginTransaction()
45: {
46: $this->connection->beginTransaction();
47: }
48:
49:
50:
51: public function commit()
52: {
53: $this->connection->commit();
54: }
55:
56:
57:
58: public function rollBack()
59: {
60: $this->connection->rollBack();
61: }
62:
63:
64: 65: 66: 67:
68: public function getInsertId($name = null)
69: {
70: return $this->connection->getInsertId($name);
71: }
72:
73:
74: 75: 76: 77: 78:
79: public function query($sql, ...$params)
80: {
81: return $this->connection->query($sql, ...$params);
82: }
83:
84:
85: 86: 87: 88:
89: public function queryArgs($sql, array $params)
90: {
91: return $this->connection->query($sql, ...$params);
92: }
93:
94:
95: 96: 97: 98:
99: public function table($table)
100: {
101: return new Table\Selection($this, $this->conventions, $table, $this->cacheStorage);
102: }
103:
104:
105:
106: public function getConnection()
107: {
108: return $this->connection;
109: }
110:
111:
112:
113: public function getStructure()
114: {
115: return $this->structure;
116: }
117:
118:
119:
120: public function getConventions()
121: {
122: return $this->conventions;
123: }
124:
125:
126:
127:
128:
129: 130: 131: 132: 133:
134: public function fetch($sql, ...$params)
135: {
136: return $this->connection->query($sql, ...$params)->fetch();
137: }
138:
139:
140: 141: 142: 143: 144:
145: public function fetchField($sql, ...$params)
146: {
147: return $this->connection->query($sql, ...$params)->fetchField();
148: }
149:
150:
151: 152: 153: 154: 155:
156: public function fetchPairs($sql, ...$params)
157: {
158: return $this->connection->query($sql, ...$params)->fetchPairs();
159: }
160:
161:
162: 163: 164: 165: 166:
167: public function fetchAll($sql, ...$params)
168: {
169: return $this->connection->query($sql, ...$params)->fetchAll();
170: }
171:
172:
173: 174: 175:
176: public static function literal($value, ...$params)
177: {
178: return new SqlLiteral($value, $params);
179: }
180: }
181: