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 extends Nette\Object
18: {
19:
20: private $connection;
21:
22:
23: private $structure;
24:
25:
26: private $conventions;
27:
28:
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:
42: public function beginTransaction()
43: {
44: $this->connection->beginTransaction();
45: }
46:
47:
48:
49: public function commit()
50: {
51: $this->connection->commit();
52: }
53:
54:
55:
56: public function rollBack()
57: {
58: $this->connection->rollBack();
59: }
60:
61:
62: 63: 64: 65:
66: public function getInsertId($name = NULL)
67: {
68: return $this->connection->getInsertId($name);
69: }
70:
71:
72: 73: 74: 75: 76: 77:
78: public function query($statement)
79: {
80: return $this->connection->query(func_get_args());
81: }
82:
83:
84: 85: 86: 87: 88:
89: public function queryArgs($statement, array $params)
90: {
91: return $this->connection->queryArgs($statement, $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: public function getDatabaseReflection()
128: {
129: trigger_error(__METHOD__ . '() is deprecated; use getConventions() instead.', E_USER_DEPRECATED);
130: return $this->conventions;
131: }
132:
133:
134:
135:
136:
137: 138: 139: 140: 141: 142:
143: public function fetch($args)
144: {
145: return $this->connection->query(func_get_args())->fetch();
146: }
147:
148:
149: 150: 151: 152: 153: 154:
155: public function fetchField($args)
156: {
157: return $this->connection->query(func_get_args())->fetchField();
158: }
159:
160:
161: 162: 163: 164: 165: 166:
167: public function fetchPairs($args)
168: {
169: return $this->connection->query(func_get_args())->fetchPairs();
170: }
171:
172:
173: 174: 175: 176: 177: 178:
179: public function fetchAll($args)
180: {
181: return $this->connection->query(func_get_args())->fetchAll();
182: }
183:
184:
185: 186: 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: