1 | <?php |
||
18 | class QueryFactory |
||
19 | { |
||
20 | const COMMON = 'common'; |
||
21 | |||
22 | /** |
||
23 | * |
||
24 | * What database are we building for? |
||
25 | * |
||
26 | * @param string |
||
27 | * |
||
28 | */ |
||
29 | protected $db; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * Build "common" query objects regardless of database type? |
||
34 | * |
||
35 | * @param bool |
||
36 | * |
||
37 | */ |
||
38 | protected $common = false; |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * The quote prefix/suffix to use for each type. |
||
43 | * |
||
44 | * @param array |
||
45 | * |
||
46 | */ |
||
47 | protected $quotes = array( |
||
48 | 'Common' => array('"', '"'), |
||
49 | 'Mysql' => array('`', '`'), |
||
50 | 'Pgsql' => array('"', '"'), |
||
51 | 'Sqlite' => array('"', '"'), |
||
52 | 'Sqlsrv' => array('[', ']'), |
||
53 | ); |
||
54 | |||
55 | /** |
||
56 | * |
||
57 | * The quote name prefix extracted from `$quotes`. |
||
58 | * |
||
59 | * @var string |
||
60 | * |
||
61 | */ |
||
62 | protected $quote_name_prefix; |
||
63 | |||
64 | /** |
||
65 | * |
||
66 | * The quote name suffix extracted from `$quotes`. |
||
67 | * |
||
68 | * @var string |
||
69 | * |
||
70 | */ |
||
71 | protected $quote_name_suffix; |
||
72 | |||
73 | /** |
||
74 | * |
||
75 | * A map of `table.col` names to last-insert-id names. |
||
76 | * |
||
77 | * @var array |
||
78 | * |
||
79 | */ |
||
80 | protected $last_insert_id_names = array(); |
||
81 | |||
82 | /** |
||
83 | * |
||
84 | * A Quoter for identifiers. |
||
85 | * |
||
86 | * @param Quoter |
||
87 | * |
||
88 | */ |
||
89 | protected $quoter; |
||
90 | |||
91 | /** |
||
92 | * |
||
93 | * A count of Query instances, used for determining $seq_bind_prefix. |
||
94 | * |
||
95 | * @var int |
||
96 | * |
||
97 | */ |
||
98 | protected $instance_count = 0; |
||
99 | |||
100 | /** |
||
101 | * |
||
102 | * Constructor. |
||
103 | * |
||
104 | * @param string $db The database type. |
||
105 | * |
||
106 | * @param string $common Pass the constant self::COMMON to force common |
||
107 | * query objects instead of db-specific ones. |
||
108 | * |
||
109 | */ |
||
110 | 387 | public function __construct( |
|
119 | |||
120 | /** |
||
121 | * |
||
122 | * Sets the last-insert-id names to be used for Insert queries.. |
||
123 | * |
||
124 | * @param array $last_insert_id_names A map of `table.col` names to |
||
125 | * last-insert-id names. |
||
126 | * |
||
127 | * @return null |
||
128 | * |
||
129 | */ |
||
130 | 66 | public function setLastInsertIdNames(array $last_insert_id_names) |
|
134 | |||
135 | /** |
||
136 | * |
||
137 | * Returns a new SELECT object. |
||
138 | * |
||
139 | * @return Common\SelectInterface |
||
140 | * |
||
141 | */ |
||
142 | 250 | public function newSelect() |
|
146 | |||
147 | /** |
||
148 | * |
||
149 | * Returns a new INSERT object. |
||
150 | * |
||
151 | * @return Common\InsertInterface |
||
152 | * |
||
153 | */ |
||
154 | 76 | public function newInsert() |
|
160 | |||
161 | /** |
||
162 | * |
||
163 | * Returns a new UPDATE object. |
||
164 | * |
||
165 | * @return Common\UpdateInterface |
||
166 | * |
||
167 | */ |
||
168 | 33 | public function newUpdate() |
|
172 | |||
173 | /** |
||
174 | * |
||
175 | * Returns a new DELETE object. |
||
176 | * |
||
177 | * @return Common\DeleteInterface |
||
178 | * |
||
179 | */ |
||
180 | 28 | public function newDelete() |
|
184 | |||
185 | /** |
||
186 | * |
||
187 | * Returns a new query object. |
||
188 | * |
||
189 | * @param string $query The query object type. |
||
190 | * |
||
191 | * @return AbstractQuery |
||
192 | * |
||
193 | */ |
||
194 | 387 | protected function newInstance($query) |
|
209 | |||
210 | /** |
||
211 | * |
||
212 | * Returns the Quoter object for queries; creates one if needed. |
||
213 | * |
||
214 | * @return Quoter |
||
215 | * |
||
216 | */ |
||
217 | 387 | protected function getQuoter() |
|
228 | |||
229 | /** |
||
230 | * |
||
231 | * Returns a new sequential-placeholder prefix for a query object. |
||
232 | * |
||
233 | * We need these to deconflict between bound values in subselect queries. |
||
234 | * |
||
235 | * @return string |
||
236 | * |
||
237 | */ |
||
238 | 387 | protected function newSeqBindPrefix() |
|
248 | } |
||
249 |