Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 619 lines (551 sloc) 20.127 kb
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
1 <?php
d8b76a5 continued refactorings.
romanb authored
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the LGPL. For more information, see
705199e [2.0] Parser work. Added support for functions in SelectExpressions.
romanb authored
17 * <http://www.doctrine-project.org>.
d8b76a5 continued refactorings.
romanb authored
18 */
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
19
22e94ac Enabling namespaces. Final restructurings.
romanb authored
20 namespace Doctrine\DBAL\Platforms;
4d7b883 Intermediate checkin. Refactoring towards namespaced structure.
romanb authored
21
07e7388 [2.0] DDC-92 - Completly removed DoctrineException in DBAL package
beberlei authored
22 use Doctrine\DBAL\DBALException,
dd6abf7 [2.0] DDC-169 - AbstractPlatform::getAlterTableSql() now accepts only a ...
beberlei authored
23 Doctrine\DBAL\Schema\TableDiff;
7479a0c [2.0] Starting to improve functional tests. First basic functional query...
romanb authored
24
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
25 /**
26 * The MySqlPlatform provides the behavior, features and SQL dialect of the
6a3aa84 [2.0] Made MySqlPlatform default to innodb table engine. Some cleanups w...
romanb authored
27 * MySQL database platform. This platform represents a MySQL 5.0 or greater platform that
28 * uses the InnoDB storage engine.
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
29 *
30 * @since 2.0
31 * @author Roman Borschel <roman@code-factory.org>
b9daf62 [2.0] DDC-313 - Removed lots of dead and unnecessary code
beberlei authored
32 * @author Benjamin Eberlei <kontakt@beberlei.de>
a53c2fb [2.0] Code cleanups. Preparations for DDC-193. Fixed DDC-399, type confi...
romanb authored
33 * @todo Rename: MySQLPlatform
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
34 */
22e94ac Enabling namespaces. Final restructurings.
romanb authored
35 class MySqlPlatform extends AbstractPlatform
b9daf62 [2.0] DDC-313 - Removed lots of dead and unnecessary code
beberlei authored
36 {
3cd4fc5 Intermediate checkin.
romanb authored
37 /**
38 * Gets the character used for identifier quoting.
39 *
40 * @return string
41 * @override
42 */
43 public function getIdentifierQuoteCharacter()
44 {
45 return '`';
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
46 }
47
48 /**
3cd4fc5 Intermediate checkin.
romanb authored
49 * Returns the regular expression operator.
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
50 *
51 * @return string
52 * @override
53 */
54 public function getRegexpExpression()
55 {
56 return 'RLIKE';
57 }
58
59 /**
60 * Returns global unique identifier
61 *
62 * @return string to get global unique identifier
63 * @override
64 */
65 public function getGuidExpression()
66 {
67 return 'UUID()';
68 }
69
70 /**
6bfbab9 [2.0] DDC-325 - Fixed LOCATE() support for all platforms.
beberlei authored
71 * returns the position of the first occurrence of substring $substr in string $str
72 *
73 * @param string $substr literal string to find
74 * @param string $str literal string
75 * @param int $pos position to start at, beginning of string by default
76 * @return integer
77 */
78 public function getLocateExpression($str, $substr, $startPos = false)
79 {
80 if ($startPos == false) {
81 return 'LOCATE(' . $substr . ', ' . $str . ')';
82 } else {
83 return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
84 }
85 }
86
87 /**
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
88 * Returns a series of strings concatinated
89 *
90 * concat() accepts an arbitrary number of parameters. Each parameter
91 * must contain an expression or an array with expressions.
92 *
93 * @param string|array(string) strings that will be concatinated.
94 * @override
95 */
96 public function getConcatExpression()
97 {
98 $args = func_get_args();
99 return 'CONCAT(' . join(', ', (array) $args) . ')';
100 }
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
101
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
102 public function getListDatabasesSQL()
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
103 {
104 return 'SHOW DATABASES';
105 }
106
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
107 public function getListTableConstraintsSQL($table)
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
108 {
8797921 [2.0] Removed AssociationMappings from ResultSetMapping for improved ca...
romanb authored
109 return 'SHOW INDEX FROM ' . $table;
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
110 }
111
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
112 public function getListTableIndexesSQL($table)
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
113 {
8797921 [2.0] Removed AssociationMappings from ResultSetMapping for improved ca...
romanb authored
114 return 'SHOW INDEX FROM ' . $table;
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
115 }
116
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
117 public function getListViewsSQL($database)
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
118 {
22edbce [2.0] DDC-312 - Refactored View support of all platforms a little - Ora...
beberlei authored
119 return "SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$database."'";
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
120 }
121
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
122 public function getListTableForeignKeysSQL($table, $database = null)
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
123 {
ac4c33c [2.0] DDC-214, DDC-303, DDC-304 - Fix several errors with Schema Inferen...
beberlei authored
124 $sql = "SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ".
125 "k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ".
126 "FROM information_schema.key_column_usage k /*!50116 ".
127 "INNER JOIN information_schema.referential_constraints c ON k.`CONSTRAINT_NAME` = c.constraint_name AND ".
128 " c.constraint_name = k.constraint_name AND ".
bf32775 [2.0] DDC-214 - Changed MysqlPlatform::geTListTableForeignKeySql() sligh...
beberlei authored
129 " c.table_name = '$table' */ WHERE k.table_name = '$table'";
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
130
131 if ( ! is_null($database)) {
acec85a [2.0] Fixed hardcoded database name.
romanb authored
132 $sql .= " AND table_schema = '$database'";
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
133 }
134
af48974 [2.0] DDC-169 - Converted introspection queries of all platforms to retu...
beberlei authored
135 $sql .= " AND `REFERENCED_COLUMN_NAME` is not NULL";
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
136
137 return $sql;
138 }
139
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
140 public function getCreateViewSQL($name, $sql)
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
141 {
142 return 'CREATE VIEW ' . $name . ' AS ' . $sql;
143 }
144
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
145 public function getDropViewSQL($name)
75e0c1e [2.0] More general work on the SchemaManager and Platform classes. Makin...
jwage authored
146 {
147 return 'DROP VIEW '. $name;
148 }
149
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
150 /**
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
151 * Gets the SQL snippet used to declare a VARCHAR column on the MySql platform.
152 *
153 * @params array $field
0f8e9e0 refactorings. made basic one-one, one-many joins work.
romanb authored
154 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
155 public function getVarcharTypeDeclarationSQL(array $field)
0f8e9e0 refactorings. made basic one-one, one-many joins work.
romanb authored
156 {
157 if ( ! isset($field['length'])) {
158 if (array_key_exists('default', $field)) {
159 $field['length'] = $this->getVarcharMaxLength();
160 } else {
161 $field['length'] = false;
162 }
163 }
164
165 $length = ($field['length'] <= $this->getVarcharMaxLength()) ? $field['length'] : false;
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
166 $fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
0f8e9e0 refactorings. made basic one-one, one-many joins work.
romanb authored
167
168 return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
b1d34fc [2.0] Work on SchemaTool and DBAL.
romanb authored
169 : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
0f8e9e0 refactorings. made basic one-one, one-many joins work.
romanb authored
170 }
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
171
435acc9 [2.0][DDC-24] Fixed (together with some small misc. refactorings).
romanb authored
172 /** @override */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
173 public function getClobTypeDeclarationSQL(array $field)
b5401ee checkin of occasional work from the past weeks.
romanb authored
174 {
175 if ( ! empty($field['length'])) {
176 $length = $field['length'];
177 if ($length <= 255) {
178 return 'TINYTEXT';
179 } else if ($length <= 65532) {
180 return 'TEXT';
181 } else if ($length <= 16777215) {
182 return 'MEDIUMTEXT';
183 }
184 }
185 return 'LONGTEXT';
186 }
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
187
188 /**
ada2c5c [2.0] Work on datetime dbal type and date portability
jwage authored
189 * @override
190 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
191 public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
ada2c5c [2.0] Work on datetime dbal type and date portability
jwage authored
192 {
7220cb2 DDC-118 - Fixed introduced regression and added tests for future
beberlei authored
193 if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) {
adbfbf5 [2.0] Fixes issue with optimistic timestamp locking (closes #2451)
jwage authored
194 return 'TIMESTAMP';
195 } else {
196 return 'DATETIME';
197 }
ada2c5c [2.0] Work on datetime dbal type and date portability
jwage authored
198 }
733c3c2 [2.0] Various necessary fixes and adjustments for oracle as well as fixe...
romanb authored
199
200 /**
201 * @override
202 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
203 public function getDateTypeDeclarationSQL(array $fieldDeclaration)
733c3c2 [2.0] Various necessary fixes and adjustments for oracle as well as fixe...
romanb authored
204 {
205 return 'DATE';
206 }
ada2c5c [2.0] Work on datetime dbal type and date portability
jwage authored
207
208 /**
78d4309 [2.0] Testing all dbal types and making sure they are fully implemented
jwage authored
209 * @override
210 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
211 public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
a784795 [2.0] Fixed DDC-63 and DDC-106. Oracle tests for SchemaManager need furt...
beberlei authored
212 {
213 return 'TIME';
214 }
215
216 /**
217 * @override
218 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
219 public function getBooleanTypeDeclarationSQL(array $field)
78d4309 [2.0] Testing all dbal types and making sure they are fully implemented
jwage authored
220 {
221 return 'TINYINT(1)';
222 }
223
224 /**
e704cd0 Continued refactorings. Started to refactor the DBAL layer.
romanb authored
225 * Obtain DBMS specific SQL code portion needed to set the COLLATION
226 * of a field declaration to be used in statements like CREATE TABLE.
227 *
228 * @param string $collation name of the collation
229 * @return string DBMS specific SQL code portion needed to set the COLLATION
230 * of a field declaration.
231 */
232 public function getCollationFieldDeclaration($collation)
233 {
234 return 'COLLATE ' . $collation;
235 }
236
237 /**
238 * Whether the platform prefers identity columns for ID generation.
239 * MySql prefers "autoincrement" identity columns since sequences can only
240 * be emulated with a table.
241 *
242 * @return boolean
243 * @override
244 */
245 public function prefersIdentityColumns()
246 {
247 return true;
248 }
3cd4fc5 Intermediate checkin.
romanb authored
249
250 /**
251 * Whether the platform supports identity columns.
252 * MySql supports this through AUTO_INCREMENT columns.
253 *
254 * @return boolean
255 * @override
256 */
257 public function supportsIdentityColumns()
258 {
259 return true;
260 }
261
262 /**
263 * Whether the platform supports savepoints. MySql does not.
264 *
265 * @return boolean
266 * @override
267 */
268 public function supportsSavepoints()
269 {
270 return false;
271 }
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
272
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
273 public function getShowDatabasesSQL()
b5401ee checkin of occasional work from the past weeks.
romanb authored
274 {
275 return 'SHOW DATABASES';
276 }
277
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
278 public function getListTablesSQL()
b5401ee checkin of occasional work from the past weeks.
romanb authored
279 {
e3314da [2.0] DC-169 - New method AbstractSchemaManager::createSchema() which cr...
beberlei authored
280 return 'SHOW FULL TABLES WHERE Table_type = "BASE TABLE"';
b5401ee checkin of occasional work from the past weeks.
romanb authored
281 }
746d9bc [2.0] Adding listTableColumns() support for mysql.
jwage authored
282
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
283 public function getListTableColumnsSQL($table)
746d9bc [2.0] Adding listTableColumns() support for mysql.
jwage authored
284 {
8797921 [2.0] Removed AssociationMappings from ResultSetMapping for improved ca...
romanb authored
285 return 'DESCRIBE ' . $table;
746d9bc [2.0] Adding listTableColumns() support for mysql.
jwage authored
286 }
287
b5401ee checkin of occasional work from the past weeks.
romanb authored
288 /**
289 * create a new database
290 *
291 * @param string $name name of the database that should be created
292 * @return string
293 * @override
294 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
295 public function getCreateDatabaseSQL($name)
b5401ee checkin of occasional work from the past weeks.
romanb authored
296 {
8797921 [2.0] Removed AssociationMappings from ResultSetMapping for improved ca...
romanb authored
297 return 'CREATE DATABASE ' . $name;
b5401ee checkin of occasional work from the past weeks.
romanb authored
298 }
299
300 /**
301 * drop an existing database
302 *
303 * @param string $name name of the database that should be dropped
304 * @return string
305 * @override
306 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
307 public function getDropDatabaseSQL($name)
b5401ee checkin of occasional work from the past weeks.
romanb authored
308 {
8797921 [2.0] Removed AssociationMappings from ResultSetMapping for improved ca...
romanb authored
309 return 'DROP DATABASE ' . $name;
b5401ee checkin of occasional work from the past weeks.
romanb authored
310 }
311
312 /**
313 * create a new table
314 *
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
315 * @param string $tableName Name of the database that should be created
316 * @param array $columns Associative array that contains the definition of each field of the new table
b5401ee checkin of occasional work from the past weeks.
romanb authored
317 * The indexes of the array entries are the names of the fields of the table an
318 * the array entry values are associative arrays like those that are meant to be
319 * passed with the field definitions to get[Type]Declaration() functions.
320 * array(
321 * 'id' => array(
322 * 'type' => 'integer',
323 * 'unsigned' => 1
324 * 'notnull' => 1
325 * 'default' => 0
326 * ),
327 * 'name' => array(
328 * 'type' => 'text',
329 * 'length' => 12
330 * ),
331 * 'password' => array(
332 * 'type' => 'text',
333 * 'length' => 12
334 * )
335 * );
336 * @param array $options An associative array of table options:
337 * array(
338 * 'comment' => 'Foo',
339 * 'charset' => 'utf8',
340 * 'collate' => 'utf8_unicode_ci',
341 * 'type' => 'innodb',
342 * );
343 *
344 * @return void
345 * @override
346 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
347 protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
b5401ee checkin of occasional work from the past weeks.
romanb authored
348 {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
349 $queryFields = $this->getColumnDeclarationListSQL($columns);
b5401ee checkin of occasional work from the past weeks.
romanb authored
350
b1d34fc [2.0] Work on SchemaTool and DBAL.
romanb authored
351 if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
9ad13c4 [2.0][DDC-236] Enhanced unique constraints to support names. Fixed gener...
guilhermeblanco authored
352 foreach ($options['uniqueConstraints'] as $index => $definition) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
353 $queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($index, $definition);
b1d34fc [2.0] Work on SchemaTool and DBAL.
romanb authored
354 }
b5401ee checkin of occasional work from the past weeks.
romanb authored
355 }
356
357 // add all indexes
358 if (isset($options['indexes']) && ! empty($options['indexes'])) {
359 foreach($options['indexes'] as $index => $definition) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
360 $queryFields .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
b5401ee checkin of occasional work from the past weeks.
romanb authored
361 }
362 }
363
364 // attach all primary keys
365 if (isset($options['primary']) && ! empty($options['primary'])) {
ae7be28 [2.0] Work on single table inheritance with more functional tests.
romanb authored
366 $keyColumns = array_unique(array_values($options['primary']));
b5401ee checkin of occasional work from the past weeks.
romanb authored
367 $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
368 }
369
370 $query = 'CREATE ';
371 if (!empty($options['temporary'])) {
372 $query .= 'TEMPORARY ';
373 }
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
374 $query.= 'TABLE ' . $tableName . ' (' . $queryFields . ')';
b5401ee checkin of occasional work from the past weeks.
romanb authored
375
376 $optionStrings = array();
377
378 if (isset($options['comment'])) {
379 $optionStrings['comment'] = 'COMMENT = ' . $this->quote($options['comment'], 'text');
380 }
381 if (isset($options['charset'])) {
382 $optionStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
383 if (isset($options['collate'])) {
384 $optionStrings['charset'] .= ' COLLATE ' . $options['collate'];
385 }
386 }
387
388 // get the type of the table
6a3aa84 [2.0] Made MySqlPlatform default to innodb table engine. Some cleanups w...
romanb authored
389 if (isset($options['engine'])) {
390 $optionStrings[] = 'ENGINE = ' . $engine;
391 } else {
392 // default to innodb
393 $optionStrings[] = 'ENGINE = InnoDB';
b5401ee checkin of occasional work from the past weeks.
romanb authored
394 }
6a3aa84 [2.0] Made MySqlPlatform default to innodb table engine. Some cleanups w...
romanb authored
395
b5401ee checkin of occasional work from the past weeks.
romanb authored
396 if ( ! empty($optionStrings)) {
397 $query.= ' '.implode(' ', $optionStrings);
398 }
399 $sql[] = $query;
400
401 if (isset($options['foreignKeys'])) {
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
402 foreach ((array) $options['foreignKeys'] as $definition) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
403 $sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
b5401ee checkin of occasional work from the past weeks.
romanb authored
404 }
405 }
406
407 return $sql;
408 }
409
410 /**
16c4efc [2.0] DBAL streamlining and starting to increase test coverage.
romanb authored
411 * Gets the SQL to alter an existing table.
b5401ee checkin of occasional work from the past weeks.
romanb authored
412 *
5fd6e68 @beberlei Commit current state of IBM DB2 driver, but it segfaults the hell out of...
beberlei authored
413 * @param TableDiff $diff
414 * @return array
b5401ee checkin of occasional work from the past weeks.
romanb authored
415 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
416 public function getAlterTableSQL(TableDiff $diff)
b5401ee checkin of occasional work from the past weeks.
romanb authored
417 {
dd6abf7 [2.0] DDC-169 - AbstractPlatform::getAlterTableSql() now accepts only a ...
beberlei authored
418 $queryParts = array();
419 if ($diff->newName !== false) {
420 $queryParts[] = 'RENAME TO ' . $diff->newName;
b5401ee checkin of occasional work from the past weeks.
romanb authored
421 }
422
dd6abf7 [2.0] DDC-169 - AbstractPlatform::getAlterTableSql() now accepts only a ...
beberlei authored
423 foreach ($diff->addedColumns AS $fieldName => $column) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
424 $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
b5401ee checkin of occasional work from the past weeks.
romanb authored
425 }
426
dd6abf7 [2.0] DDC-169 - AbstractPlatform::getAlterTableSql() now accepts only a ...
beberlei authored
427 foreach ($diff->removedColumns AS $column) {
428 $queryParts[] = 'DROP ' . $column->getName();
b5401ee checkin of occasional work from the past weeks.
romanb authored
429 }
430
dd6abf7 [2.0] DDC-169 - AbstractPlatform::getAlterTableSql() now accepts only a ...
beberlei authored
431 foreach ($diff->changedColumns AS $columnDiff) {
432 /* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
433 $column = $columnDiff->column;
434 $queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' '
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
435 . $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
b5401ee checkin of occasional work from the past weeks.
romanb authored
436 }
437
dd6abf7 [2.0] DDC-169 - AbstractPlatform::getAlterTableSql() now accepts only a ...
beberlei authored
438 foreach ($diff->renamedColumns AS $oldColumnName => $column) {
439 $queryParts[] = 'CHANGE ' . $oldColumnName . ' '
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
440 . $this->getColumnDeclarationSQL($column->getName(), $column->toArray());
b5401ee checkin of occasional work from the past weeks.
romanb authored
441 }
442
34119d3 [2.0] DDC-169 - Fix order that column and index/fk changes are applied i...
beberlei authored
443 $sql = array();
8a46eb0 [2.0] DDC-169 - Finished ALTER Table TableDiff refactoring, adding code ...
beberlei authored
444 if (count($queryParts) > 0) {
445 $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts);
b5401ee checkin of occasional work from the past weeks.
romanb authored
446 }
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
447 $sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
8a46eb0 [2.0] DDC-169 - Finished ALTER Table TableDiff refactoring, adding code ...
beberlei authored
448 return $sql;
b5401ee checkin of occasional work from the past weeks.
romanb authored
449 }
450
451 /**
452 * Obtain DBMS specific SQL code portion needed to declare an integer type
453 * field to be used in statements like CREATE TABLE.
454 *
455 * @param string $name name the field to be declared.
456 * @param string $field associative array with the name of the properties
457 * of the field being declared as array indexes.
458 * Currently, the types of supported field
459 * properties are as follows:
460 *
461 * unsigned
462 * Boolean flag that indicates whether the field
463 * should be declared as unsigned integer if
464 * possible.
465 *
466 * default
467 * Integer value to be used as default for this
468 * field.
469 *
470 * notnull
471 * Boolean flag that indicates whether this field is
472 * constrained to not be set to null.
473 * @return string DBMS specific SQL code portion that should be used to
474 * declare the specified field.
475 * @override
476 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
477 public function getIntegerTypeDeclarationSQL(array $field)
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
478 {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
479 return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
480 }
481
482 /** @override */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
483 public function getBigIntTypeDeclarationSQL(array $field)
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
484 {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
485 return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
486 }
487
488 /** @override */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
489 public function getSmallIntTypeDeclarationSQL(array $field)
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
490 {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
491 return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
d973363 Finally first, very basic, running CRUD tests for Doctrine 2
romanb authored
492 }
493
494 /** @override */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
495 protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
b5401ee checkin of occasional work from the past weeks.
romanb authored
496 {
87fd08e [2.0] Some fixes for ClassExporterTest.
romanb authored
497 $autoinc = '';
34f4ee7 First tests for basic collection implementation. First experimental use ...
romanb authored
498 if ( ! empty($columnDef['autoincrement'])) {
b5401ee checkin of occasional work from the past weeks.
romanb authored
499 $autoinc = ' AUTO_INCREMENT';
500 }
34f4ee7 First tests for basic collection implementation. First experimental use ...
romanb authored
501 $unsigned = (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : '';
b5401ee checkin of occasional work from the past weeks.
romanb authored
502
87fd08e [2.0] Some fixes for ClassExporterTest.
romanb authored
503 return $unsigned . $autoinc;
b5401ee checkin of occasional work from the past weeks.
romanb authored
504 }
505
506 /**
507 * Return the FOREIGN KEY query section dealing with non-standard options
508 * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
509 *
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
510 * @param ForeignKeyConstraint $foreignKey
b5401ee checkin of occasional work from the past weeks.
romanb authored
511 * @return string
512 * @override
513 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
514 public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
b5401ee checkin of occasional work from the past weeks.
romanb authored
515 {
516 $query = '';
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
517 if ($foreignKey->hasOption('match')) {
518 $query .= ' MATCH ' . $foreignKey->getOption('match');
b5401ee checkin of occasional work from the past weeks.
romanb authored
519 }
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
520 $query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
b5401ee checkin of occasional work from the past weeks.
romanb authored
521 return $query;
522 }
523
524 /**
16c4efc [2.0] DBAL streamlining and starting to increase test coverage.
romanb authored
525 * Gets the SQL to drop an index of a table.
b5401ee checkin of occasional work from the past weeks.
romanb authored
526 *
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
527 * @param Index $index name of the index to be dropped
528 * @param string|Table $table name of table that should be used in method
b5401ee checkin of occasional work from the past weeks.
romanb authored
529 * @override
530 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
531 public function getDropIndexSQL($index, $table=null)
b5401ee checkin of occasional work from the past weeks.
romanb authored
532 {
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
533 if($index instanceof \Doctrine\DBAL\Schema\Index) {
534 $index = $index->getName();
535 } else if(!is_string($index)) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
536 throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
537 }
538
539 if($table instanceof \Doctrine\DBAL\Schema\Table) {
540 $table = $table->getName();
541 } else if(!is_string($table)) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
542 throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
8562c80 [2.0] DDC-169 - Changed AbstractPlatform and AbstractSchemaManager and c...
beberlei authored
543 }
544
545 return 'DROP INDEX ' . $index . ' ON ' . $table;
b5401ee checkin of occasional work from the past weeks.
romanb authored
546 }
547
548 /**
16c4efc [2.0] DBAL streamlining and starting to increase test coverage.
romanb authored
549 * Gets the SQL to drop a table.
b5401ee checkin of occasional work from the past weeks.
romanb authored
550 *
16c4efc [2.0] DBAL streamlining and starting to increase test coverage.
romanb authored
551 * @param string $table The name of table to drop.
b5401ee checkin of occasional work from the past weeks.
romanb authored
552 * @override
553 */
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
554 public function getDropTableSQL($table)
b5401ee checkin of occasional work from the past weeks.
romanb authored
555 {
bf0ef0d [2.0] DDC-169 - Fix several complications in update and drop schema code...
beberlei authored
556 if ($table instanceof \Doctrine\DBAL\Schema\Table) {
557 $table = $table->getName();
558 } else if(!is_string($table)) {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
559 throw new \InvalidArgumentException('MysqlPlatform::getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
bf0ef0d [2.0] DDC-169 - Fix several complications in update and drop schema code...
beberlei authored
560 }
561
8797921 [2.0] Removed AssociationMappings from ResultSetMapping for improved ca...
romanb authored
562 return 'DROP TABLE ' . $table;
b5401ee checkin of occasional work from the past weeks.
romanb authored
563 }
f994680 [2.0] More general work on the Platform and SchemaManager classes(primar...
jwage authored
564
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
565 public function getSetTransactionIsolationSQL($level)
c3ad955 further cleanups
romanb authored
566 {
df6ca60 [2.0][DDC-92] Fixed. Patch provided by Christian Heinrich. [DDC-274] Sta...
romanb authored
567 return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
c3ad955 further cleanups
romanb authored
568 }
7426baf [2.0] General work on Platform and SchemaManager classes
jwage authored
569
570 /**
b1d34fc [2.0] Work on SchemaTool and DBAL.
romanb authored
571 * Get the platform name for this instance.
7426baf [2.0] General work on Platform and SchemaManager classes
jwage authored
572 *
573 * @return string
574 */
575 public function getName()
576 {
577 return 'mysql';
578 }
ba99f53 [2.0] DDC-169 - Fix implicit/explicit index creation differences between...
beberlei authored
579
580 public function createsExplicitIndexForForeignKeys()
581 {
582 return true;
583 }
e6a44b1 @beberlei [DDC-178] First approach to Locking support
beberlei authored
584
585 public function getReadLockSQL()
586 {
587 return 'LOCK IN SHARE MODE';
588 }
626a334 @beberlei Added registerDoctrineMappingType() and getDoctrineMappingType() methods...
beberlei authored
589
590 protected function initializeDoctrineTypeMappings()
591 {
592 $this->doctrineTypeMapping = array(
593 'tinyint' => 'boolean',
594 'smallint' => 'smallint',
595 'mediumint' => 'integer',
596 'int' => 'integer',
597 'integer' => 'integer',
598 'bigint' => 'bigint',
599 'tinytext' => 'text',
600 'mediumtext' => 'text',
601 'longtext' => 'text',
602 'text' => 'text',
603 'varchar' => 'string',
604 'string' => 'string',
605 'char' => 'string',
606 'date' => 'date',
607 'datetime' => 'datetime',
608 'timestamp' => 'datetime',
609 'time' => 'time',
610 'float' => 'decimal',
611 'double' => 'decimal',
612 'real' => 'decimal',
613 'decimal' => 'decimal',
614 'numeric' => 'decimal',
615 'year' => 'date',
616 );
617 }
a784795 [2.0] Fixed DDC-63 and DDC-106. Oracle tests for SchemaManager need furt...
beberlei authored
618 }
Something went wrong with that request. Please try again.