AbstractSchemaManager.php 21.6 KB
Newer Older
romanb's avatar
romanb committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
romanb's avatar
romanb committed
20 21
 */

22
namespace Doctrine\DBAL\Schema;
romanb's avatar
romanb committed
23

24 25 26
use Doctrine\DBAL\Types;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
27

romanb's avatar
romanb committed
28
/**
29
 * Base class for schema managers. Schema managers are used to inspect and/or
30
 * modify the database schema/structure.
romanb's avatar
romanb committed
31 32 33 34
 *
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @author      Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
35
 * @author      Roman Borschel <roman@code-factory.org>
36
 * @author      Jonathan H. Wage <jonwage@gmail.com>
37
 * @author      Benjamin Eberlei <kontakt@beberlei.de>
romanb's avatar
romanb committed
38 39 40
 * @version     $Revision$
 * @since       2.0
 */
41
abstract class AbstractSchemaManager
romanb's avatar
romanb committed
42
{
43 44 45
    /**
     * Holds instance of the Doctrine connection for this schema manager
     *
46
     * @var \Doctrine\DBAL\Connection
47
     */
romanb's avatar
romanb committed
48 49
    protected $_conn;

50 51 52
    /**
     * Holds instance of the database platform used for this schema manager
     *
53
     * @var \Doctrine\DBAL\Platforms\AbstractPlatform
54 55 56 57 58 59
     */
    protected $_platform;

    /**
     * Constructor. Accepts the Connection instance to manage the schema for
     *
60
     * @param \Doctrine\DBAL\Connection $conn
61
     */
62
    public function __construct(\Doctrine\DBAL\Connection $conn)
63 64
    {
        $this->_conn = $conn;
65
        $this->_platform = $this->_conn->getDatabasePlatform();
66 67
    }

68 69 70 71 72 73 74 75 76 77
    /**
     * Return associated platform.
     *
     * @return \Doctrine\DBAL\Platform\AbstractPlatform
     */
    public function getDatabasePlatform()
    {
        return $this->_platform;
    }

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    /**
     * Try any method on the schema manager. Normally a method throws an 
     * exception when your DBMS doesn't support it or if an error occurs.
     * This method allows you to try and method on your SchemaManager
     * instance and will return false if it does not work or is not supported.
     *
     * <code>
     * $result = $sm->tryMethod('dropView', 'view_name');
     * </code>
     *
     * @return mixed
     */
    public function tryMethod()
    {
        $args = func_get_args();
        $method = $args[0];
        unset($args[0]);
        $args = array_values($args);

        try {
            return call_user_func_array(array($this, $method), $args);
        } catch (\Exception $e) {
            return false;
        }
    }

romanb's avatar
romanb committed
104
    /**
105
     * List the available databases for this connection
romanb's avatar
romanb committed
106
     *
107
     * @return array $databases
romanb's avatar
romanb committed
108 109 110
     */
    public function listDatabases()
    {
111
        $sql = $this->_platform->getListDatabasesSQL();
112 113 114 115

        $databases = $this->_conn->fetchAll($sql);

        return $this->_getPortableDatabasesList($databases);
romanb's avatar
romanb committed
116 117 118
    }

    /**
119
     * List the available sequences for this connection
romanb's avatar
romanb committed
120
     *
121
     * @return Sequence[]
romanb's avatar
romanb committed
122
     */
123
    public function listSequences($database = null)
romanb's avatar
romanb committed
124
    {
125 126 127
        if (is_null($database)) {
            $database = $this->_conn->getDatabase();
        }
128
        $sql = $this->_platform->getListSequencesSQL($database);
129 130 131 132

        $sequences = $this->_conn->fetchAll($sql);

        return $this->_getPortableSequencesList($sequences);
romanb's avatar
romanb committed
133 134 135
    }

    /**
136
     * List the columns for a given table.
romanb's avatar
romanb committed
137
     *
138 139 140 141 142 143 144
     * In contrast to other libraries and to the old version of Doctrine,
     * this column definition does try to contain the 'primary' field for
     * the reason that it is not portable accross different RDBMS. Use
     * {@see listTableIndexes($tableName)} to retrieve the primary key
     * of a table. We're a RDBMS specifies more details these are held
     * in the platformDetails array.
     *
145
     * @param string $table The name of the table.
146
     * @return Column[]
romanb's avatar
romanb committed
147 148 149
     */
    public function listTableColumns($table)
    {
150
        $sql = $this->_platform->getListTableColumnsSQL($table);
151 152 153 154

        $tableColumns = $this->_conn->fetchAll($sql);

        return $this->_getPortableTableColumnList($tableColumns);
romanb's avatar
romanb committed
155 156 157
    }

    /**
158
     * List the indexes for a given table returning an array of Index instances.
romanb's avatar
romanb committed
159
     *
160 161
     * Keys of the portable indexes list are all lower-cased.
     *
162
     * @param string $table The name of the table
163
     * @return Index[] $tableIndexes
romanb's avatar
romanb committed
164 165 166
     */
    public function listTableIndexes($table)
    {
167
        $sql = $this->_platform->getListTableIndexesSQL($table);
168 169 170

        $tableIndexes = $this->_conn->fetchAll($sql);

171
        return $this->_getPortableTableIndexesList($tableIndexes, $table);
romanb's avatar
romanb committed
172 173 174
    }

    /**
175
     * Return a list of all tables in the current database
romanb's avatar
romanb committed
176
     *
177
     * @return array
romanb's avatar
romanb committed
178
     */
179
    public function listTableNames()
romanb's avatar
romanb committed
180
    {
181
        $sql = $this->_platform->getListTablesSQL();
182 183 184

        $tables = $this->_conn->fetchAll($sql);

185 186 187 188 189 190 191 192 193 194 195
        return $this->_getPortableTablesList($tables);
    }

    /**
     * List the tables for this connection
     *
     * @return Table[]
     */
    public function listTables()
    {
        $tableNames = $this->listTableNames();
196

197
        $tables = array();
198
        foreach ($tableNames AS $tableName) {
199
            $tables[] = $this->listTableDetails($tableName);
200 201 202
        }

        return $tables;
romanb's avatar
romanb committed
203 204
    }

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    /**
     * @param  string $tableName
     * @return Table
     */
    public function listTableDetails($tableName)
    {
        $columns = $this->listTableColumns($tableName);
        $foreignKeys = array();
        if ($this->_platform->supportsForeignKeyConstraints()) {
            $foreignKeys = $this->listTableForeignKeys($tableName);
        }
        $indexes = $this->listTableIndexes($tableName);

        $idGeneratorType = Table::ID_NONE;
        foreach ($columns AS $column) {
            if ($column->hasPlatformOption('autoincrement') && $column->getPlatformOption('autoincrement')) {
                $idGeneratorType = Table::ID_IDENTITY;
            }
        }

        return new Table($tableName, $columns, $indexes, $foreignKeys, $idGeneratorType, array());
    }

romanb's avatar
romanb committed
228
    /**
229
     * List the views this connection has
romanb's avatar
romanb committed
230
     *
231
     * @return View[]
romanb's avatar
romanb committed
232
     */
233
    public function listViews()
romanb's avatar
romanb committed
234
    {
235
        $database = $this->_conn->getDatabase();
236
        $sql = $this->_platform->getListViewsSQL($database);
237 238 239
        $views = $this->_conn->fetchAll($sql);

        return $this->_getPortableViewsList($views);
romanb's avatar
romanb committed
240 241
    }

242 243 244 245
    /**
     * List the foreign keys for the given table
     *
     * @param string $table  The name of the table
246
     * @return ForeignKeyConstraint[]
247 248 249 250 251 252
     */
    public function listTableForeignKeys($table, $database = null)
    {
        if (is_null($database)) {
            $database = $this->_conn->getDatabase();
        }
253
        $sql = $this->_platform->getListTableForeignKeysSQL($table, $database);
254 255 256 257 258
        $tableForeignKeys = $this->_conn->fetchAll($sql);

        return $this->_getPortableTableForeignKeysList($tableForeignKeys);
    }

259 260
    /* drop*() Methods */

romanb's avatar
romanb committed
261
    /**
262 263 264
     * Drops a database.
     * 
     * NOTE: You can not drop the database this SchemaManager is currently connected to.
romanb's avatar
romanb committed
265
     *
266
     * @param string $database The name of the database to drop
romanb's avatar
romanb committed
267
     */
268
    public function dropDatabase($database)
romanb's avatar
romanb committed
269
    {
270
        $this->_execSql($this->_platform->getDropDatabaseSQL($database));
romanb's avatar
romanb committed
271 272 273
    }

    /**
274
     * Drop the given table
romanb's avatar
romanb committed
275
     *
276
     * @param string $table The name of the table to drop
romanb's avatar
romanb committed
277 278 279
     */
    public function dropTable($table)
    {
280
        $this->_execSql($this->_platform->getDropTableSQL($table));
romanb's avatar
romanb committed
281 282 283
    }

    /**
284
     * Drop the index from the given table
romanb's avatar
romanb committed
285
     *
286 287
     * @param Index|string $index  The name of the index
     * @param string|Table $table The name of the table
romanb's avatar
romanb committed
288
     */
289
    public function dropIndex($index, $table)
romanb's avatar
romanb committed
290
    {
291 292 293 294
        if($index instanceof Index) {
            $index = $index->getName();
        }

295
        $this->_execSql($this->_platform->getDropIndexSQL($index, $table));
romanb's avatar
romanb committed
296 297 298
    }

    /**
299
     * Drop the constraint from the given table
romanb's avatar
romanb committed
300
     *
301
     * @param Constraint $constraint
302
     * @param string $table   The name of the table
romanb's avatar
romanb committed
303
     */
304
    public function dropConstraint(Constraint $constraint, $table)
romanb's avatar
romanb committed
305
    {
306
        $this->_execSql($this->_platform->getDropConstraintSQL($constraint, $table));
romanb's avatar
romanb committed
307 308 309
    }

    /**
romanb's avatar
romanb committed
310
     * Drops a foreign key from a table.
romanb's avatar
romanb committed
311
     *
312 313
     * @param ForeignKeyConstraint|string $table The name of the table with the foreign key.
     * @param Table|string $name  The name of the foreign key.
314
     * @return boolean $result
romanb's avatar
romanb committed
315
     */
316
    public function dropForeignKey($foreignKey, $table)
romanb's avatar
romanb committed
317
    {
318
        $this->_execSql($this->_platform->getDropForeignKeySQL($foreignKey, $table));
romanb's avatar
romanb committed
319 320 321
    }

    /**
romanb's avatar
romanb committed
322
     * Drops a sequence with a given name.
romanb's avatar
romanb committed
323
     *
romanb's avatar
romanb committed
324
     * @param string $name The name of the sequence to drop.
romanb's avatar
romanb committed
325
     */
326
    public function dropSequence($name)
romanb's avatar
romanb committed
327
    {
328
        $this->_execSql($this->_platform->getDropSequenceSQL($name));
romanb's avatar
romanb committed
329 330
    }

331 332 333 334 335 336 337 338
    /**
     * Drop a view
     *
     * @param string $name The name of the view
     * @return boolean $result
     */
    public function dropView($name)
    {
339
        $this->_execSql($this->_platform->getDropViewSQL($name));
340 341 342 343
    }

    /* create*() Methods */

romanb's avatar
romanb committed
344
    /**
romanb's avatar
romanb committed
345
     * Creates a new database.
romanb's avatar
romanb committed
346
     *
romanb's avatar
romanb committed
347
     * @param string $database The name of the database to create.
romanb's avatar
romanb committed
348
     */
romanb's avatar
romanb committed
349
    public function createDatabase($database)
romanb's avatar
romanb committed
350
    {
351
        $this->_execSql($this->_platform->getCreateDatabaseSQL($database));
romanb's avatar
romanb committed
352 353 354
    }

    /**
romanb's avatar
romanb committed
355
     * Create a new table.
romanb's avatar
romanb committed
356
     *
357
     * @param Table $table
358
     * @param int $createFlags
romanb's avatar
romanb committed
359
     */
360
    public function createTable(Table $table)
romanb's avatar
romanb committed
361
    {
362
        $createFlags = AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS;
363
        $this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
romanb's avatar
romanb committed
364 365 366
    }

    /**
367
     * Create a new sequence
romanb's avatar
romanb committed
368
     *
369
     * @param Sequence $sequence
370
     * @throws Doctrine\DBAL\ConnectionException     if something fails at database level
romanb's avatar
romanb committed
371
     */
372
    public function createSequence($sequence)
romanb's avatar
romanb committed
373
    {
374
        $this->_execSql($this->_platform->getCreateSequenceSQL($sequence));
romanb's avatar
romanb committed
375 376 377
    }

    /**
378
     * Create a constraint on a table
romanb's avatar
romanb committed
379
     *
380 381 382 383
     * @param Constraint $constraint
     * @param string|Table $table
     */
    public function createConstraint(Constraint $constraint, $table)
romanb's avatar
romanb committed
384
    {
385
        $this->_execSql($this->_platform->getCreateConstraintSQL($constraint, $table));
romanb's avatar
romanb committed
386 387 388
    }

    /**
389
     * Create a new index on a table
romanb's avatar
romanb committed
390
     *
391
     * @param Index     $index
romanb's avatar
romanb committed
392 393
     * @param string    $table         name of the table on which the index is to be created
     */
394
    public function createIndex(Index $index, $table)
romanb's avatar
romanb committed
395
    {
396
        $this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
romanb's avatar
romanb committed
397 398 399
    }

    /**
400
     * Create a new foreign key
romanb's avatar
romanb committed
401
     *
402 403
     * @param ForeignKeyConstraint  $foreignKey    ForeignKey instance
     * @param string|Table          $table         name of the table on which the foreign key is to be created
romanb's avatar
romanb committed
404
     */
405
    public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
romanb's avatar
romanb committed
406
    {
407
        $this->_execSql($this->_platform->getCreateForeignKeySQL($foreignKey, $table));
romanb's avatar
romanb committed
408 409
    }

410 411 412
    /**
     * Create a new view
     *
413
     * @param View $view
414
     */
415
    public function createView(View $view)
416
    {
417
        $this->_execSql($this->_platform->getCreateViewSQL($view->getName(), $view->getSql()));
418 419
    }

420 421
    /* dropAndCreate*() Methods */

422
    /**
423 424
     * Drop and create a constraint
     *
425 426
     * @param Constraint    $constraint
     * @param string        $table
427 428 429
     * @see dropConstraint()
     * @see createConstraint()
     */
430
    public function dropAndCreateConstraint(Constraint $constraint, $table)
431
    {
432 433
        $this->tryMethod('dropConstraint', $constraint, $table);
        $this->createConstraint($constraint, $table);
434 435 436 437 438
    }

    /**
     * Drop and create a new index on a table
     *
439 440
     * @param string|Table $table         name of the table on which the index is to be created
     * @param Index $index
441
     */
442
    public function dropAndCreateIndex(Index $index, $table)
443
    {
444 445
        $this->tryMethod('dropIndex', $index->getName(), $table);
        $this->createIndex($index, $table);
446 447 448 449 450
    }

    /**
     * Drop and create a new foreign key
     *
451 452
     * @param ForeignKeyConstraint  $foreignKey    associative array that defines properties of the foreign key to be created.
     * @param string|Table          $table         name of the table on which the foreign key is to be created
453
     */
454
    public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
455
    {
456 457
        $this->tryMethod('dropForeignKey', $foreignKey, $table);
        $this->createForeignKey($foreignKey, $table);
458 459 460 461 462
    }

    /**
     * Drop and create a new sequence
     *
463
     * @param Sequence $sequence
464 465
     * @throws Doctrine\DBAL\ConnectionException     if something fails at database level
     */
466
    public function dropAndCreateSequence(Sequence $sequence)
467 468 469 470 471 472 473 474
    {
        $this->tryMethod('createSequence', $seqName, $start, $allocationSize);
        $this->createSequence($seqName, $start, $allocationSize);
    }

    /**
     * Drop and create a new table.
     *
475
     * @param Table $table
476
     */
477
    public function dropAndCreateTable(Table $table)
478
    {
479 480
        $this->tryMethod('dropTable', $table->getName());
        $this->createTable($table);
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
    }

    /**
     * Drop and creates a new database.
     *
     * @param string $database The name of the database to create.
     */
    public function dropAndCreateDatabase($database)
    {
        $this->tryMethod('dropDatabase', $database);
        $this->createDatabase($database);
    }

    /**
     * Drop and create a new view
496
     *
497
     * @param View $view
498
     */
499
    public function dropAndCreateView(View $view)
500
    {
501 502
        $this->tryMethod('dropView', $view->getName());
        $this->createView($view);
503 504
    }

505 506
    /* alterTable() Methods */

romanb's avatar
romanb committed
507
    /**
508
     * Alter an existing tables schema
romanb's avatar
romanb committed
509
     *
510 511 512 513
     * @param TableDiff $tableDiff
     */
    public function alterTable(TableDiff $tableDiff)
    {
514
        $queries = $this->_platform->getAlterTableSQL($tableDiff);
515 516 517 518
        if (is_array($queries) && count($queries)) {
            foreach ($queries AS $ddlQuery) {
                $this->_execSql($ddlQuery);
            }
519
        }
520 521
    }

522 523 524 525 526 527 528 529
    /**
     * Rename a given table to another name
     *
     * @param string $name     The current name of the table
     * @param string $newName  The new name of the table
     */
    public function renameTable($name, $newName)
    {
530 531 532
        $tableDiff = new TableDiff($name);
        $tableDiff->newName = $newName;
        $this->alterTable($tableDiff);
533 534
    }

535 536 537 538 539
    /**
     * Methods for filtering return values of list*() methods to convert
     * the native DBMS data definition to a portable Doctrine definition
     */

540 541
    protected function _getPortableDatabasesList($databases)
    {
542
        $list = array();
543
        foreach ($databases as $key => $value) {
544 545 546
            if ($value = $this->_getPortableDatabaseDefinition($value)) {
                $list[] = $value;
            }
547
        }
548
        return $list;
549 550
    }

551 552 553 554 555
    protected function _getPortableDatabaseDefinition($database)
    {
        return $database;
    }

556 557
    protected function _getPortableFunctionsList($functions)
    {
558
        $list = array();
559
        foreach ($functions as $key => $value) {
560 561 562
            if ($value = $this->_getPortableFunctionDefinition($value)) {
                $list[] = $value;
            }
563
        }
564
        return $list;
565 566
    }

567 568 569 570 571
    protected function _getPortableFunctionDefinition($function)
    {
        return $function;
    }

572 573
    protected function _getPortableTriggersList($triggers)
    {
574
        $list = array();
575
        foreach ($triggers as $key => $value) {
576 577 578
            if ($value = $this->_getPortableTriggerDefinition($value)) {
                $list[] = $value;
            }
579
        }
580
        return $list;
581 582
    }

583 584 585 586 587
    protected function _getPortableTriggerDefinition($trigger)
    {
        return $trigger;
    }

588 589
    protected function _getPortableSequencesList($sequences)
    {
590
        $list = array();
591
        foreach ($sequences as $key => $value) {
592 593 594
            if ($value = $this->_getPortableSequenceDefinition($value)) {
                $list[] = $value;
            }
595
        }
596
        return $list;
597 598
    }

599 600 601 602
    /**
     * @param array $sequence
     * @return Sequence
     */
603 604
    protected function _getPortableSequenceDefinition($sequence)
    {
605
        throw DBALException::notSupported('Sequences');
606 607
    }

608 609 610 611 612 613 614 615
    /**
     * Independent of the database the keys of the column list result are lowercased.
     *
     * The name of the created column instance however is kept in its case.
     *
     * @param  array $tableColumns
     * @return array
     */
616 617
    protected function _getPortableTableColumnList($tableColumns)
    {
618
        $list = array();
619 620
        foreach ($tableColumns as $key => $column) {
            if ($column = $this->_getPortableTableColumnDefinition($column)) {
621 622
                $name = strtolower($column->getName());
                $list[$name] = $column;
623
            }
624
        }
625
        return $list;
626 627
    }

628 629 630 631 632 633 634
    /**
     * Get Table Column Definition
     *
     * @param array $tableColumn
     * @return Column
     */
    abstract protected function _getPortableTableColumnDefinition($tableColumn);
635

636 637 638
    /**
     * Aggregate and group the index results according to the required data result.
     *
639
     * @param  array $tableIndexRows
640 641 642
     * @param  string $tableName
     * @return array
     */
643
    protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null)
644
    {
645
        $result = array();
646
        foreach($tableIndexRows AS $tableIndex) {
647 648 649 650
            $indexName = $keyName = $tableIndex['key_name'];
            if($tableIndex['primary']) {
                $keyName = 'primary';
            }
651
            $keyName = strtolower($keyName);
652 653 654 655 656 657 658 659 660 661

            if(!isset($result[$keyName])) {
                $result[$keyName] = array(
                    'name' => $indexName,
                    'columns' => array($tableIndex['column_name']),
                    'unique' => $tableIndex['non_unique'] ? false : true,
                    'primary' => $tableIndex['primary'],
                );
            } else {
                $result[$keyName]['columns'][] = $tableIndex['column_name'];
662
            }
663
        }
664

665 666 667 668 669 670
        $indexes = array();
        foreach($result AS $indexKey => $data) {
            $indexes[$indexKey] = new Index($data['name'], $data['columns'], $data['unique'], $data['primary']);
        }

        return $indexes;
671 672
    }

673 674
    protected function _getPortableTablesList($tables)
    {
675
        $list = array();
676
        foreach ($tables as $key => $value) {
677 678 679
            if ($value = $this->_getPortableTableDefinition($value)) {
                $list[] = $value;
            }
680
        }
681
        return $list;
682 683
    }

684 685 686 687 688
    protected function _getPortableTableDefinition($table)
    {
        return $table;
    }

689 690
    protected function _getPortableUsersList($users)
    {
691
        $list = array();
692
        foreach ($users as $key => $value) {
693 694 695
            if ($value = $this->_getPortableUserDefinition($value)) {
                $list[] = $value;
            }
696
        }
697
        return $list;
698 699
    }

700 701 702 703 704
    protected function _getPortableUserDefinition($user)
    {
        return $user;
    }

705 706
    protected function _getPortableViewsList($views)
    {
707
        $list = array();
708
        foreach ($views as $key => $value) {
709 710 711
            if ($view = $this->_getPortableViewDefinition($value)) {
                $viewName = strtolower($view->getName());
                $list[$viewName] = $view;
712
            }
713
        }
714
        return $list;
715 716
    }

717 718
    protected function _getPortableViewDefinition($view)
    {
719
        return false;
720 721
    }

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
    protected function _getPortableTableForeignKeysList($tableForeignKeys)
    {
        $list = array();
        foreach ($tableForeignKeys as $key => $value) {
            if ($value = $this->_getPortableTableForeignKeyDefinition($value)) {
                $list[] = $value;
            }
        }
        return $list;
    }

    protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
    {
        return $tableForeignKey;
    }
737

romanb's avatar
romanb committed
738
    protected function _execSql($sql)
739 740
    {
        foreach ((array) $sql as $query) {
741
            $this->_conn->executeUpdate($query);
romanb's avatar
romanb committed
742 743
        }
    }
744 745 746 747 748 749 750 751 752 753 754 755 756 757

    /**
     * Create a schema instance for the current database.
     * 
     * @return Schema
     */
    public function createSchema()
    {
        $sequences = array();
        if($this->_platform->supportsSequences()) {
            $sequences = $this->listSequences();
        }
        $tables = $this->listTables();

758
        return new Schema($tables, $sequences, $this->createSchemaConfig());
759 760 761 762 763 764 765 766 767 768 769 770 771 772
    }

    /**
     * Create the configuration for this schema.
     *
     * @return SchemaConfig
     */
    public function createSchemaConfig()
    {
        $schemaConfig = new SchemaConfig();
        $schemaConfig->setExplicitForeignKeyIndexes($this->_platform->createsExplicitIndexForForeignKeys());
        $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());

        return $schemaConfig;
773
    }
774
}