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($sql)
79: {
80: return $this->connection->query(func_get_args());
81: }
82:
83:
84: 85: 86: 87:
88: public function queryArgs($sql, array $params)
89: {
90: return $this->connection->queryArgs($sql, $params);
91: }
92:
93:
94: 95: 96: 97:
98: public function table($table)
99: {
100: return new Table\Selection($this, $this->conventions, $table, $this->cacheStorage);
101: }
102:
103:
104:
105: public function getConnection()
106: {
107: return $this->connection;
108: }
109:
110:
111:
112: public function getStructure()
113: {
114: return $this->structure;
115: }
116:
117:
118:
119: public function getConventions()
120: {
121: return $this->conventions;
122: }
123:
124:
125:
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:
134:
135:
136: 137: 138: 139: 140: 141:
142: public function fetch($args)
143: {
144: return $this->connection->query(func_get_args())->fetch();
145: }
146:
147:
148: 149: 150: 151: 152: 153:
154: public function fetchField($args)
155: {
156: return $this->connection->query(func_get_args())->fetchField();
157: }
158:
159:
160: 161: 162: 163: 164: 165:
166: public function fetchPairs($args)
167: {
168: return $this->connection->query(func_get_args())->fetchPairs();
169: }
170:
171:
172: 173: 174: 175: 176: 177:
178: public function fetchAll($args)
179: {
180: return $this->connection->query(func_get_args())->fetchAll();
181: }
182:
183:
184: 185: 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: