1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Database;
9:
10: use Nette,
11: Nette\Database\Conventions\StaticConventions;
12:
13:
14: 15: 16: 17: 18:
19: class Context extends Nette\Object
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:
80: public function query($statement)
81: {
82: return $this->connection->query(func_get_args());
83: }
84:
85:
86: 87: 88: 89: 90:
91: public function queryArgs($statement, array $params)
92: {
93: return $this->connection->queryArgs($statement, $params);
94: }
95:
96:
97: 98: 99: 100:
101: public function table($table)
102: {
103: return new Table\Selection($this, $this->conventions, $table, $this->cacheStorage);
104: }
105:
106:
107:
108: public function getConnection()
109: {
110: return $this->connection;
111: }
112:
113:
114:
115: public function getStructure()
116: {
117: return $this->structure;
118: }
119:
120:
121:
122: public function getConventions()
123: {
124: return $this->conventions;
125: }
126:
127:
128:
129: public function getDatabaseReflection()
130: {
131: trigger_error(__METHOD__ . '() is deprecated; use getConventions() instead.', E_USER_DEPRECATED);
132: return $this->conventions;
133: }
134:
135:
136:
137:
138:
139: 140: 141: 142: 143: 144:
145: public function fetch($args)
146: {
147: return $this->connection->query(func_get_args())->fetch();
148: }
149:
150:
151: 152: 153: 154: 155: 156:
157: public function fetchField($args)
158: {
159: return $this->connection->query(func_get_args())->fetchField();
160: }
161:
162:
163: 164: 165: 166: 167: 168:
169: public function fetchPairs($args)
170: {
171: return $this->connection->query(func_get_args())->fetchPairs();
172: }
173:
174:
175: 176: 177: 178: 179: 180:
181: public function fetchAll($args)
182: {
183: return $this->connection->query(func_get_args())->fetchAll();
184: }
185:
186:
187: 188: 189:
190: public static function literal($value)
191: {
192: $args = func_get_args();
193: return new SqlLiteral(array_shift($args), $args);
194: }
195:
196: }
197: