DrizzleSchemaManager.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  21. * Schema manager for the Drizzle RDBMS.
  22. *
  23. * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
  24. */
  25. class DrizzleSchemaManager extends AbstractSchemaManager
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function _getPortableTableColumnDefinition($tableColumn)
  31. {
  32. $tableName = $tableColumn['COLUMN_NAME'];
  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' => empty($tableColumn['COLUMN_DEFAULT']) ? null : $tableColumn['COLUMN_DEFAULT'],
  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'] : null),
  45. );
  46. return new Column($tableName, \Doctrine\DBAL\Types\Type::getType($type), $options);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. protected function _getPortableDatabaseDefinition($database)
  52. {
  53. return $database['SCHEMA_NAME'];
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. protected function _getPortableTableDefinition($table)
  59. {
  60. return $table['TABLE_NAME'];
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function _getPortableTableForeignKeyDefinition($tableForeignKey)
  66. {
  67. $columns = array();
  68. foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
  69. $columns[] = trim($value, ' `');
  70. }
  71. $ref_columns = array();
  72. foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
  73. $ref_columns[] = trim($value, ' `');
  74. }
  75. return new ForeignKeyConstraint(
  76. $columns,
  77. $tableForeignKey['REFERENCED_TABLE_NAME'],
  78. $ref_columns,
  79. $tableForeignKey['CONSTRAINT_NAME'],
  80. array(
  81. 'onUpdate' => $tableForeignKey['UPDATE_RULE'],
  82. 'onDelete' => $tableForeignKey['DELETE_RULE'],
  83. )
  84. );
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
  90. {
  91. $indexes = array();
  92. foreach ($tableIndexes as $k) {
  93. $k['primary'] = (boolean)$k['primary'];
  94. $indexes[] = $k;
  95. }
  96. return parent::_getPortableTableIndexesList($indexes, $tableName);
  97. }
  98. }