DrizzleSchemaManager.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  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 MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Schema;
  20. use Doctrine\DBAL\Types\Type;
  21. /**
  22. * Schema manager for the Drizzle RDBMS.
  23. *
  24. * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
  25. */
  26. class DrizzleSchemaManager extends AbstractSchemaManager
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. protected function _getPortableTableColumnDefinition($tableColumn)
  32. {
  33. $dbType = strtolower($tableColumn['DATA_TYPE']);
  34. $type = $this->_platform->getDoctrineTypeMapping($dbType);
  35. $type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
  36. $tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
  37. $options = array(
  38. 'notnull' => !(bool) $tableColumn['IS_NULLABLE'],
  39. 'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'],
  40. 'default' => isset($tableColumn['COLUMN_DEFAULT']) ? $tableColumn['COLUMN_DEFAULT'] : null,
  41. 'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'],
  42. 'scale' => (int) $tableColumn['NUMERIC_SCALE'],
  43. 'precision' => (int) $tableColumn['NUMERIC_PRECISION'],
  44. 'comment' => isset($tableColumn['COLUMN_COMMENT']) && '' !== $tableColumn['COLUMN_COMMENT']
  45. ? $tableColumn['COLUMN_COMMENT']
  46. : null,
  47. );
  48. $column = new Column($tableColumn['COLUMN_NAME'], Type::getType($type), $options);
  49. if ( ! empty($tableColumn['COLLATION_NAME'])) {
  50. $column->setPlatformOption('collation', $tableColumn['COLLATION_NAME']);
  51. }
  52. return $column;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function _getPortableDatabaseDefinition($database)
  58. {
  59. return $database['SCHEMA_NAME'];
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. protected function _getPortableTableDefinition($table)
  65. {
  66. return $table['TABLE_NAME'];
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function _getPortableTableForeignKeyDefinition($tableForeignKey)
  72. {
  73. $columns = array();
  74. foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
  75. $columns[] = trim($value, ' `');
  76. }
  77. $refColumns = array();
  78. foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
  79. $refColumns[] = trim($value, ' `');
  80. }
  81. return new ForeignKeyConstraint(
  82. $columns,
  83. $tableForeignKey['REFERENCED_TABLE_NAME'],
  84. $refColumns,
  85. $tableForeignKey['CONSTRAINT_NAME'],
  86. array(
  87. 'onUpdate' => $tableForeignKey['UPDATE_RULE'],
  88. 'onDelete' => $tableForeignKey['DELETE_RULE'],
  89. )
  90. );
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
  96. {
  97. $indexes = array();
  98. foreach ($tableIndexes as $k) {
  99. $k['primary'] = (boolean) $k['primary'];
  100. $indexes[] = $k;
  101. }
  102. return parent::_getPortableTableIndexesList($indexes, $tableName);
  103. }
  104. }