Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 871 lines (802 sloc) 32.376 kb
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
1 <?php
d8b76a54 »
2008-08-16 continued refactorings.
2 /*
3 * $Id$
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information, see
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
19 * <http://www.doctrine-project.org>.
d8b76a54 »
2008-08-16 continued refactorings.
20 */
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
21
22e94ac5 »
2009-01-22 Enabling namespaces. Final restructurings.
22 namespace Doctrine\DBAL\Platforms;
4d7b8838 »
2008-09-12 Intermediate checkin. Refactoring towards namespaced structure.
23
7479a0cf »
2009-03-28 [2.0] Starting to improve functional tests. First basic functional qu…
24 use Doctrine\Common\DoctrineException;
25
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
26 /**
27 * The MySqlPlatform provides the behavior, features and SQL dialect of the
28 * MySQL database platform.
29 *
30 * @since 2.0
31 * @author Roman Borschel <roman@code-factory.org>
32 */
22e94ac5 »
2009-01-22 Enabling namespaces. Final restructurings.
33 class MySqlPlatform extends AbstractPlatform
7479a0cf »
2009-03-28 [2.0] Starting to improve functional tests. First basic functional qu…
34 {
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
35 /**
3cd4fc55 »
2008-08-02 Intermediate checkin.
36 * Creates a new MySqlPlatform instance.
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
37 */
38 public function __construct()
39 {
3cd4fc55 »
2008-08-02 Intermediate checkin.
40 parent::__construct();
41 }
42
43 /**
44 * Gets the character used for identifier quoting.
45 *
46 * @return string
47 * @override
48 */
49 public function getIdentifierQuoteCharacter()
50 {
51 return '`';
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
52 }
53
54 /**
3cd4fc55 »
2008-08-02 Intermediate checkin.
55 * Returns the regular expression operator.
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
56 *
57 * @return string
58 * @override
59 */
60 public function getRegexpExpression()
61 {
62 return 'RLIKE';
63 }
64
65 /**
66 * return string to call a function to get random value inside an SQL statement
67 *
68 * @return string to generate float between 0 and 1
69 */
70 public function getRandomExpression()
71 {
72 return 'RAND()';
73 }
74
75 /**
76 * Builds a pattern matching string.
77 *
78 * EXPERIMENTAL
79 *
80 * WARNING: this function is experimental and may change signature at
81 * any time until labelled as non-experimental.
82 *
83 * @param array $pattern even keys are strings, odd are patterns (% and _)
84 * @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future)
85 * @param string $field optional field name that is being matched against
86 * (might be required when emulating ILIKE)
87 *
88 * @return string SQL pattern
89 * @override
90 */
91 public function getMatchPatternExpression($pattern, $operator = null, $field = null)
92 {
93 $match = '';
94 if ( ! is_null($operator)) {
95 $field = is_null($field) ? '' : $field.' ';
96 $operator = strtoupper($operator);
97 switch ($operator) {
98 // case insensitive
99 case 'ILIKE':
100 $match = $field.'LIKE ';
101 break;
102 // case sensitive
103 case 'LIKE':
104 $match = $field.'LIKE BINARY ';
105 break;
106 default:
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
107 throw DoctrineException::updateMe('not a supported operator type:'. $operator);
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
108 }
109 }
110 $match.= "'";
111 foreach ($pattern as $key => $value) {
112 if ($key % 2) {
113 $match .= $value;
114 } else {
115 $match .= $this->conn->escapePattern($this->conn->escape($value));
116 }
117 }
118 $match.= "'";
119 $match.= $this->patternEscapeString();
3cd4fc55 »
2008-08-02 Intermediate checkin.
120
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
121 return $match;
122 }
123
124 /**
125 * Returns global unique identifier
126 *
127 * @return string to get global unique identifier
128 * @override
129 */
130 public function getGuidExpression()
131 {
132 return 'UUID()';
133 }
134
135 /**
136 * Returns a series of strings concatinated
137 *
138 * concat() accepts an arbitrary number of parameters. Each parameter
139 * must contain an expression or an array with expressions.
140 *
141 * @param string|array(string) strings that will be concatinated.
142 * @override
143 */
144 public function getConcatExpression()
145 {
146 $args = func_get_args();
147 return 'CONCAT(' . join(', ', (array) $args) . ')';
148 }
149
150 /**
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
151 * Gets the SQL snippet used to declare a VARCHAR column on the MySql platform.
152 *
153 * @params array $field
0f8e9e0b »
2008-08-22 refactorings. made basic one-one, one-many joins work.
154 */
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
155 public function getVarcharTypeDeclarationSql(array $field)
0f8e9e0b »
2008-08-22 refactorings. made basic one-one, one-many joins work.
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;
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
166 $fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
0f8e9e0b »
2008-08-22 refactorings. made basic one-one, one-many joins work.
167
168 return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
169 : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
170 }
171
172 /**
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
173 * Enter description here...
174 *
175 * @param array $field
176 */
177 public function getClobDeclarationSql(array $field)
178 {
179 if ( ! empty($field['length'])) {
180 $length = $field['length'];
181 if ($length <= 255) {
182 return 'TINYTEXT';
183 } else if ($length <= 65532) {
184 return 'TEXT';
185 } else if ($length <= 16777215) {
186 return 'MEDIUMTEXT';
187 }
188 }
189 return 'LONGTEXT';
190 }
e704cd0f »
2008-08-01 Continued refactorings. Started to refactor the DBAL layer.
191
192 /**
193 * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
194 * of a field declaration to be used in statements like CREATE TABLE.
195 *
196 * @param string $charset name of the charset
197 * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
198 * of a field declaration.
199 */
200 public function getCharsetFieldDeclaration($charset)
201 {
202 return 'CHARACTER SET ' . $charset;
203 }
204
205 /**
206 * Obtain DBMS specific SQL code portion needed to set the COLLATION
207 * of a field declaration to be used in statements like CREATE TABLE.
208 *
209 * @param string $collation name of the collation
210 * @return string DBMS specific SQL code portion needed to set the COLLATION
211 * of a field declaration.
212 */
213 public function getCollationFieldDeclaration($collation)
214 {
215 return 'COLLATE ' . $collation;
216 }
217
218 /**
219 * Whether the platform prefers identity columns for ID generation.
220 * MySql prefers "autoincrement" identity columns since sequences can only
221 * be emulated with a table.
222 *
223 * @return boolean
224 * @override
225 */
226 public function prefersIdentityColumns()
227 {
228 return true;
229 }
3cd4fc55 »
2008-08-02 Intermediate checkin.
230
231 /**
232 * Whether the platform supports identity columns.
233 * MySql supports this through AUTO_INCREMENT columns.
234 *
235 * @return boolean
236 * @override
237 */
238 public function supportsIdentityColumns()
239 {
240 return true;
241 }
242
243 /**
244 * Whether the platform supports savepoints. MySql does not.
245 *
246 * @return boolean
247 * @override
248 */
249 public function supportsSavepoints()
250 {
251 return false;
252 }
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
253
254 /**
255 * Enter description here...
256 *
257 * @return unknown
258 * @override
259 */
260 public function getShowDatabasesSql()
261 {
262 return 'SHOW DATABASES';
263 }
264
265 /**
266 * Enter description here...
267 *
268 * @todo Throw exception by default?
269 * @override
270 */
271 public function getListTablesSql()
272 {
273 return 'SHOW TABLES';
274 }
275
276 /**
277 * create a new database
278 *
279 * @param string $name name of the database that should be created
280 * @return string
281 * @override
282 */
283 public function getCreateDatabaseSql($name)
284 {
285 return 'CREATE DATABASE ' . $this->quoteIdentifier($name);
286 }
287
288 /**
289 * drop an existing database
290 *
291 * @param string $name name of the database that should be dropped
292 * @return string
293 * @override
294 */
295 public function getDropDatabaseSql($name)
296 {
297 return 'DROP DATABASE ' . $this->quoteIdentifier($name);
298 }
299
300 /**
301 * create a new table
302 *
303 * @param string $name Name of the database that should be created
304 * @param array $fields Associative array that contains the definition of each field of the new table
305 * The indexes of the array entries are the names of the fields of the table an
306 * the array entry values are associative arrays like those that are meant to be
307 * passed with the field definitions to get[Type]Declaration() functions.
308 * array(
309 * 'id' => array(
310 * 'type' => 'integer',
311 * 'unsigned' => 1
312 * 'notnull' => 1
313 * 'default' => 0
314 * ),
315 * 'name' => array(
316 * 'type' => 'text',
317 * 'length' => 12
318 * ),
319 * 'password' => array(
320 * 'type' => 'text',
321 * 'length' => 12
322 * )
323 * );
324 * @param array $options An associative array of table options:
325 * array(
326 * 'comment' => 'Foo',
327 * 'charset' => 'utf8',
328 * 'collate' => 'utf8_unicode_ci',
329 * 'type' => 'innodb',
330 * );
331 *
332 * @return void
333 * @override
334 */
335 public function getCreateTableSql($name, array $fields, array $options = array())
336 {
337 if ( ! $name) {
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
338 throw DoctrineException::updateMe('no valid table name specified');
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
339 }
340 if (empty($fields)) {
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
341 throw DoctrineException::updateMe('no fields specified for table "'.$name.'"');
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
342 }
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
343 $queryFields = $this->getColumnDeclarationListSql($fields);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
344
345 // build indexes for all foreign key fields (needed in MySQL!!)
346 if (isset($options['foreignKeys'])) {
347 foreach ($options['foreignKeys'] as $fk) {
348 $local = $fk['local'];
349 $found = false;
350 if (isset($options['indexes'])) {
351 foreach ($options['indexes'] as $definition) {
352 if (is_string($definition['fields'])) {
353 // Check if index already exists on the column
354 $found = ($local == $definition['fields']);
355 } else if (in_array($local, $definition['fields']) && count($definition['fields']) === 1) {
356 // Index already exists on the column
357 $found = true;
358 }
359 }
360 }
361 if (isset($options['primary']) && !empty($options['primary']) &&
362 in_array($local, $options['primary'])) {
363 // field is part of the PK and therefore already indexed
364 $found = true;
365 }
366
367 if ( ! $found) {
368 $options['indexes'][$local] = array('fields' => array($local => array()));
369 }
370 }
371 }
372
373 // add all indexes
374 if (isset($options['indexes']) && ! empty($options['indexes'])) {
375 foreach($options['indexes'] as $index => $definition) {
376 $queryFields .= ', ' . $this->getIndexDeclarationSql($index, $definition);
377 }
378 }
379
380 // attach all primary keys
381 if (isset($options['primary']) && ! empty($options['primary'])) {
ae7be288 »
2009-05-03 [2.0] Work on single table inheritance with more functional tests.
382 $keyColumns = array_unique(array_values($options['primary']));
34f4ee71 »
2009-01-12 First tests for basic collection implementation. First experimental u…
383 $keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
384 $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
385 }
386
387 $query = 'CREATE ';
388 if (!empty($options['temporary'])) {
389 $query .= 'TEMPORARY ';
390 }
391 $query.= 'TABLE ' . $this->quoteIdentifier($name, true) . ' (' . $queryFields . ')';
392
393 $optionStrings = array();
394
395 if (isset($options['comment'])) {
396 $optionStrings['comment'] = 'COMMENT = ' . $this->quote($options['comment'], 'text');
397 }
398 if (isset($options['charset'])) {
399 $optionStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
400 if (isset($options['collate'])) {
401 $optionStrings['charset'] .= ' COLLATE ' . $options['collate'];
402 }
403 }
404
405 $type = false;
406
407 // get the type of the table
408 if (isset($options['type'])) {
409 $type = $options['type'];
34f4ee71 »
2009-01-12 First tests for basic collection implementation. First experimental u…
410 }/* else {
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
411 $type = $this->getAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE);
34f4ee71 »
2009-01-12 First tests for basic collection implementation. First experimental u…
412 }*/
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
413
414 if ($type) {
415 $optionStrings[] = 'ENGINE = ' . $type;
416 }
417
418 if ( ! empty($optionStrings)) {
419 $query.= ' '.implode(' ', $optionStrings);
420 }
421 $sql[] = $query;
422
423 if (isset($options['foreignKeys'])) {
424 foreach ((array) $options['foreignKeys'] as $k => $definition) {
425 if (is_array($definition)) {
426 $sql[] = $this->getCreateForeignKeySql($name, $definition);
427 }
428 }
429 }
430
431 return $sql;
432 }
433
434 /**
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
435 * Gets the SQL to alter an existing table.
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
436 *
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
437 * @param string $name The name of the table that is intended to be changed.
438 * @param array $changes Associative array that contains the details of each type
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
439 * of change that is intended to be performed. The types of
440 * changes that are currently supported are defined as follows:
441 *
442 * name
443 *
444 * New name for the table.
445 *
446 * add
447 *
448 * Associative array with the names of fields to be added as
449 * indexes of the array. The value of each entry of the array
450 * should be set to another associative array with the properties
451 * of the fields to be added. The properties of the fields should
452 * be the same as defined by the Metabase parser.
453 *
454 *
455 * remove
456 *
457 * Associative array with the names of fields to be removed as indexes
458 * of the array. Currently the values assigned to each entry are ignored.
459 * An empty array should be used for future compatibility.
460 *
461 * rename
462 *
463 * Associative array with the names of fields to be renamed as indexes
464 * of the array. The value of each entry of the array should be set to
465 * another associative array with the entry named name with the new
466 * field name and the entry named Declaration that is expected to contain
467 * the portion of the field declaration already in DBMS specific SQL code
468 * as it is used in the CREATE TABLE statement.
469 *
470 * change
471 *
472 * Associative array with the names of the fields to be changed as indexes
473 * of the array. Keep in mind that if it is intended to change either the
474 * name of a field and any other properties, the change array entries
475 * should have the new names of the fields as array indexes.
476 *
477 * The value of each entry of the array should be set to another associative
478 * array with the properties of the fields to that are meant to be changed as
479 * array entries. These entries should be assigned to the new values of the
480 * respective properties. The properties of the fields should be the same
481 * as defined by the Metabase parser.
482 *
483 * Example
484 * array(
485 * 'name' => 'userlist',
486 * 'add' => array(
487 * 'quota' => array(
488 * 'type' => 'integer',
489 * 'unsigned' => 1
490 * )
491 * ),
492 * 'remove' => array(
493 * 'file_limit' => array(),
494 * 'time_limit' => array()
495 * ),
496 * 'change' => array(
497 * 'name' => array(
498 * 'length' => '20',
499 * 'definition' => array(
500 * 'type' => 'text',
501 * 'length' => 20,
502 * ),
503 * )
504 * ),
505 * 'rename' => array(
506 * 'sex' => array(
507 * 'name' => 'gender',
508 * 'definition' => array(
509 * 'type' => 'text',
510 * 'length' => 1,
511 * 'default' => 'M',
512 * ),
513 * )
514 * )
515 * )
516 *
517 * @param boolean $check indicates whether the function should just check if the DBMS driver
518 * can perform the requested table alterations if the value is true or
519 * actually perform them otherwise.
520 * @return boolean
521 * @override
522 */
523 public function getAlterTableSql($name, array $changes, $check = false)
524 {
525 if ( ! $name) {
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
526 throw DoctrineException::updateMe('no valid table name specified');
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
527 }
528 foreach ($changes as $changeName => $change) {
529 switch ($changeName) {
530 case 'add':
531 case 'remove':
532 case 'change':
533 case 'rename':
534 case 'name':
535 break;
536 default:
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
537 throw DoctrineException::updateMe('change type "' . $changeName . '" not yet supported');
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
538 }
539 }
540
541 if ($check) {
542 return true;
543 }
544
545 $query = '';
546 if ( ! empty($changes['name'])) {
547 $change_name = $this->quoteIdentifier($changes['name']);
548 $query .= 'RENAME TO ' . $change_name;
549 }
550
551 if ( ! empty($changes['add']) && is_array($changes['add'])) {
552 foreach ($changes['add'] as $fieldName => $field) {
553 if ($query) {
554 $query.= ', ';
555 }
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
556 $query.= 'ADD ' . $this->getColumnDeclarationSql($fieldName, $field);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
557 }
558 }
559
560 if ( ! empty($changes['remove']) && is_array($changes['remove'])) {
561 foreach ($changes['remove'] as $fieldName => $field) {
562 if ($query) {
563 $query .= ', ';
564 }
565 $fieldName = $this->quoteIdentifier($fieldName);
566 $query .= 'DROP ' . $fieldName;
567 }
568 }
569
570 $rename = array();
571 if ( ! empty($changes['rename']) && is_array($changes['rename'])) {
572 foreach ($changes['rename'] as $fieldName => $field) {
573 $rename[$field['name']] = $fieldName;
574 }
575 }
576
577 if ( ! empty($changes['change']) && is_array($changes['change'])) {
578 foreach ($changes['change'] as $fieldName => $field) {
579 if ($query) {
580 $query.= ', ';
581 }
582 if (isset($rename[$fieldName])) {
583 $oldFieldName = $rename[$fieldName];
584 unset($rename[$fieldName]);
585 } else {
586 $oldFieldName = $fieldName;
587 }
588 $oldFieldName = $this->quoteIdentifier($oldFieldName, true);
589 $query .= 'CHANGE ' . $oldFieldName . ' '
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
590 . $this->getColumnDeclarationSql($fieldName, $field['definition']);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
591 }
592 }
593
594 if ( ! empty($rename) && is_array($rename)) {
595 foreach ($rename as $renameName => $renamedField) {
596 if ($query) {
597 $query.= ', ';
598 }
599 $field = $changes['rename'][$renamedField];
600 $renamedField = $this->quoteIdentifier($renamedField, true);
601 $query .= 'CHANGE ' . $renamedField . ' '
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
602 . $this->getColumnDeclarationSql($field['name'], $field['definition']);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
603 }
604 }
605
606 if ( ! $query) {
607 return false;
608 }
609
610 $name = $this->quoteIdentifier($name, true);
611
612 return 'ALTER TABLE ' . $name . ' ' . $query;
613 }
614
615 /**
616 * Get the stucture of a field into an array
617 *
618 * @author Leoncx
619 * @param string $table name of the table on which the index is to be created
620 * @param string $name name of the index to be created
621 * @param array $definition associative array that defines properties of the index to be created.
622 * Currently, only one property named FIELDS is supported. This property
623 * is also an associative with the names of the index fields as array
624 * indexes. Each entry of this array is set to another type of associative
625 * array that specifies properties of the index that are specific to
626 * each field.
627 *
628 * Currently, only the sorting property is supported. It should be used
629 * to define the sorting direction of the index. It may be set to either
630 * ascending or descending.
631 *
632 * Not all DBMS support index sorting direction configuration. The DBMS
633 * drivers of those that do not support it ignore this property. Use the
634 * function supports() to determine whether the DBMS driver can manage indexes.
635 *
636 * Example
637 * array(
638 * 'fields' => array(
639 * 'user_name' => array(
640 * 'sorting' => 'ASC'
641 * 'length' => 10
642 * ),
643 * 'last_login' => array()
644 * )
645 * )
646 * @throws PDOException
647 * @return void
648 * @override
649 */
650 public function getCreateIndexSql($table, $name, array $definition)
651 {
652 $table = $table;
653 $name = $this->quoteIdentifier($name);
654 $type = '';
655 if (isset($definition['type'])) {
656 switch (strtolower($definition['type'])) {
657 case 'fulltext':
658 case 'unique':
659 $type = strtoupper($definition['type']) . ' ';
660 break;
661 default:
705199e8 »
2009-03-28 [2.0] Parser work. Added support for functions in SelectExpressions.
662 throw DoctrineException::updateMe('Unknown index type ' . $definition['type']);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
663 }
664 }
665 $query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
666 $query .= ' (' . $this->getIndexFieldDeclarationListSql($definition['fields']) . ')';
667
668 return $query;
669 }
670
671 /**
672 * Obtain DBMS specific SQL code portion needed to declare an integer type
673 * field to be used in statements like CREATE TABLE.
674 *
675 * @param string $name name the field to be declared.
676 * @param string $field associative array with the name of the properties
677 * of the field being declared as array indexes.
678 * Currently, the types of supported field
679 * properties are as follows:
680 *
681 * unsigned
682 * Boolean flag that indicates whether the field
683 * should be declared as unsigned integer if
684 * possible.
685 *
686 * default
687 * Integer value to be used as default for this
688 * field.
689 *
690 * notnull
691 * Boolean flag that indicates whether this field is
692 * constrained to not be set to null.
693 * @return string DBMS specific SQL code portion that should be used to
694 * declare the specified field.
695 * @override
696 */
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
697 public function getIntegerTypeDeclarationSql(array $field)
698 {
87fd08e4 »
2009-02-17 [2.0] Some fixes for ClassExporterTest.
699 return 'INT' . $this->_getCommonIntegerTypeDeclarationSql($field);
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
700 }
701
702 /** @override */
703 public function getBigIntTypeDeclarationSql(array $field)
704 {
87fd08e4 »
2009-02-17 [2.0] Some fixes for ClassExporterTest.
705 return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
706 }
707
708 /** @override */
34f4ee71 »
2009-01-12 First tests for basic collection implementation. First experimental u…
709 public function getSmallIntTypeDeclarationSql(array $field)
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
710 {
87fd08e4 »
2009-02-17 [2.0] Some fixes for ClassExporterTest.
711 return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
d9733637 »
2009-01-07 Finally first, very basic, running CRUD tests for Doctrine 2
712 }
713
714 /** @override */
715 protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
716 {
87fd08e4 »
2009-02-17 [2.0] Some fixes for ClassExporterTest.
717 $autoinc = '';
34f4ee71 »
2009-01-12 First tests for basic collection implementation. First experimental u…
718 if ( ! empty($columnDef['autoincrement'])) {
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
719 $autoinc = ' AUTO_INCREMENT';
720 }
34f4ee71 »
2009-01-12 First tests for basic collection implementation. First experimental u…
721 $unsigned = (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : '';
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
722
87fd08e4 »
2009-02-17 [2.0] Some fixes for ClassExporterTest.
723 return $unsigned . $autoinc;
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
724 }
725
726 /**
727 * Obtain DBMS specific SQL code portion needed to set an index
728 * declaration to be used in statements like CREATE TABLE.
729 *
730 * @param string $charset name of the index
731 * @param array $definition index definition
732 * @return string DBMS specific SQL code portion needed to set an index
733 * @override
734 */
735 public function getIndexDeclarationSql($name, array $definition)
736 {
737 $name = $this->formatter->getIndexName($name);
738 $type = '';
739 if (isset($definition['type'])) {
740 switch (strtolower($definition['type'])) {
741 case 'fulltext':
742 case 'unique':
743 $type = strtoupper($definition['type']) . ' ';
744 break;
745 default:
7479a0cf »
2009-03-28 [2.0] Starting to improve functional tests. First basic functional qu…
746 throw DoctrineException::updateMe('Unknown index type ' . $definition['type']);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
747 }
748 }
749
750 if ( ! isset($definition['fields'])) {
7479a0cf »
2009-03-28 [2.0] Starting to improve functional tests. First basic functional qu…
751 throw DoctrineException::updateMe('No index columns given.');
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
752 }
753 if ( ! is_array($definition['fields'])) {
754 $definition['fields'] = array($definition['fields']);
755 }
756
757 $query = $type . 'INDEX ' . $this->quoteIdentifier($name);
758
759 $query .= ' (' . $this->getIndexFieldDeclarationListSql($definition['fields']) . ')';
760
761 return $query;
762 }
763
764 /**
765 * getIndexFieldDeclarationList
766 * Obtain DBMS specific SQL code portion needed to set an index
767 * declaration to be used in statements like CREATE TABLE.
768 *
769 * @return string
770 * @override
771 */
772 public function getIndexFieldDeclarationListSql(array $fields)
773 {
774 $declFields = array();
775
776 foreach ($fields as $fieldName => $field) {
777 $fieldString = $this->quoteIdentifier($fieldName);
778
779 if (is_array($field)) {
780 if (isset($field['length'])) {
781 $fieldString .= '(' . $field['length'] . ')';
782 }
783
784 if (isset($field['sorting'])) {
785 $sort = strtoupper($field['sorting']);
786 switch ($sort) {
787 case 'ASC':
788 case 'DESC':
789 $fieldString .= ' ' . $sort;
790 break;
791 default:
7479a0cf »
2009-03-28 [2.0] Starting to improve functional tests. First basic functional qu…
792 throw DoctrineException::updateMe('Unknown index sorting option given.');
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
793 }
794 }
795 } else {
796 $fieldString = $this->quoteIdentifier($field);
797 }
798 $declFields[] = $fieldString;
799 }
800 return implode(', ', $declFields);
801 }
802
803 /**
804 * Return the FOREIGN KEY query section dealing with non-standard options
805 * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
806 *
807 * @param array $definition
808 * @return string
809 * @override
810 */
811 public function getAdvancedForeignKeyOptionsSql(array $definition)
812 {
813 $query = '';
814 if ( ! empty($definition['match'])) {
815 $query .= ' MATCH ' . $definition['match'];
816 }
817 if ( ! empty($definition['onUpdate'])) {
818 $query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSql($definition['onUpdate']);
819 }
820 if ( ! empty($definition['onDelete'])) {
821 $query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSql($definition['onDelete']);
822 }
823 return $query;
824 }
825
826 /**
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
827 * Gets the SQL to drop an index of a table.
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
828 *
829 * @param string $table name of table that should be used in method
830 * @param string $name name of the index to be dropped
831 * @override
832 */
833 public function getDropIndexSql($table, $name)
834 {
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
835 $table = $this->quoteIdentifier($table);
836 $name = $this->quoteIdentifier($name);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
837 return 'DROP INDEX ' . $name . ' ON ' . $table;
838 }
839
840 /**
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
841 * Gets the SQL to drop a table.
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
842 *
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
843 * @param string $table The name of table to drop.
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
844 * @override
845 */
846 public function getDropTableSql($table)
847 {
16c4efcc »
2009-05-03 [2.0] DBAL streamlining and starting to increase test coverage.
848 return 'DROP TABLE ' . $this->quoteIdentifier($table);
b5401ee1 »
2008-08-31 checkin of occasional work from the past weeks.
849 }
c3ad9559 »
2008-09-12 further cleanups
850
851 /**
852 * Enter description here...
853 *
854 * @param unknown_type $level
855 * @override
856 */
857 public function getSetTransactionIsolationSql($level)
858 {
859 return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
860 }
7426baf5 »
2009-05-27 [2.0] General work on Platform and SchemaManager classes
861
862 /**
863 * Get the platform name for this instance
864 *
865 * @return string
866 */
867 public function getName()
868 {
869 return 'mysql';
870 }
d458197e »
2009-02-20 [2.0] Another step towards finishing namespace refactoring
871 }
Something went wrong with that request. Please try again.