DrizzleSchemaManager.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. protected function _getPortableTableColumnDefinition($tableColumn)
  28. {
  29. $tableName = $tableColumn['COLUMN_NAME'];
  30. $dbType = strtolower($tableColumn['DATA_TYPE']);
  31. $type = $this->_platform->getDoctrineTypeMapping($dbType);
  32. $type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
  33. $tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
  34. $options = array(
  35. 'notnull' => !(bool)$tableColumn['IS_NULLABLE'],
  36. 'length' => (int)$tableColumn['CHARACTER_MAXIMUM_LENGTH'],
  37. 'default' => empty($tableColumn['COLUMN_DEFAULT']) ? null : $tableColumn['COLUMN_DEFAULT'],
  38. 'autoincrement' => (bool)$tableColumn['IS_AUTO_INCREMENT'],
  39. 'scale' => (int)$tableColumn['NUMERIC_SCALE'],
  40. 'precision' => (int)$tableColumn['NUMERIC_PRECISION'],
  41. 'comment' => (isset($tableColumn['COLUMN_COMMENT']) ? $tableColumn['COLUMN_COMMENT'] : null),
  42. );
  43. return new Column($tableName, \Doctrine\DBAL\Types\Type::getType($type), $options);
  44. }
  45. protected function _getPortableDatabaseDefinition($database)
  46. {
  47. return $database['SCHEMA_NAME'];
  48. }
  49. protected function _getPortableTableDefinition($table)
  50. {
  51. return $table['TABLE_NAME'];
  52. }
  53. public function _getPortableTableForeignKeyDefinition($tableForeignKey)
  54. {
  55. $columns = array();
  56. foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
  57. $columns[] = trim($value, ' `');
  58. }
  59. $ref_columns = array();
  60. foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
  61. $ref_columns[] = trim($value, ' `');
  62. }
  63. return new ForeignKeyConstraint(
  64. $columns,
  65. $tableForeignKey['REFERENCED_TABLE_NAME'],
  66. $ref_columns,
  67. $tableForeignKey['CONSTRAINT_NAME'],
  68. array(
  69. 'onUpdate' => $tableForeignKey['UPDATE_RULE'],
  70. 'onDelete' => $tableForeignKey['DELETE_RULE'],
  71. )
  72. );
  73. }
  74. protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
  75. {
  76. $indexes = array();
  77. foreach ($tableIndexes as $k) {
  78. $k['primary'] = (boolean)$k['primary'];
  79. $indexes[] = $k;
  80. }
  81. return parent::_getPortableTableIndexesList($indexes, $tableName);
  82. }
  83. }