/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/platform/MysqlPlatform.php

https://github.com/makerlabs/Symfohub · PHP · 120 lines · 56 code · 10 blank · 54 comment · 14 complexity · 701fb28faa718b31b638010dce66b20d MD5 · raw file

  1. <?php
  2. /*
  3. * $Id: MysqlPlatform.php 1262 2009-10-26 20:54:39Z francois $
  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 please see
  19. * <http://propel.phpdb.org>.
  20. */
  21. require_once 'propel/engine/platform/DefaultPlatform.php';
  22. /**
  23. * MySql Platform implementation.
  24. *
  25. * @author Hans Lellelid <hans@xmpl.org> (Propel)
  26. * @author Martin Poeschl <mpoeschl@marmot.at> (Torque)
  27. * @version $Revision: 1262 $
  28. * @package propel.engine.platform
  29. */
  30. class MysqlPlatform extends DefaultPlatform {
  31. /**
  32. * Initializes db specific domain mapping.
  33. */
  34. protected function initialize()
  35. {
  36. parent::initialize();
  37. $this->setSchemaDomainMapping(new Domain(PropelTypes::BOOLEAN, "TINYINT"));
  38. $this->setSchemaDomainMapping(new Domain(PropelTypes::NUMERIC, "DECIMAL"));
  39. $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARCHAR, "TEXT"));
  40. $this->setSchemaDomainMapping(new Domain(PropelTypes::BINARY, "BLOB"));
  41. $this->setSchemaDomainMapping(new Domain(PropelTypes::VARBINARY, "MEDIUMBLOB"));
  42. $this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARBINARY, "LONGBLOB"));
  43. $this->setSchemaDomainMapping(new Domain(PropelTypes::BLOB, "LONGBLOB"));
  44. $this->setSchemaDomainMapping(new Domain(PropelTypes::CLOB, "LONGTEXT"));
  45. $this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, "DATETIME"));
  46. }
  47. /**
  48. * @see Platform#getAutoIncrement()
  49. */
  50. public function getAutoIncrement()
  51. {
  52. return "AUTO_INCREMENT";
  53. }
  54. /**
  55. * @see Platform#getMaxColumnNameLength()
  56. */
  57. public function getMaxColumnNameLength()
  58. {
  59. return 64;
  60. }
  61. /**
  62. * @see Platform::supportsNativeDeleteTrigger()
  63. */
  64. public function supportsNativeDeleteTrigger()
  65. {
  66. $usingInnoDB = false;
  67. if (class_exists('DataModelBuilder', false))
  68. {
  69. $usingInnoDB = strtolower($this->getBuildProperty('mysqlTableType')) == 'innodb';
  70. }
  71. return $usingInnoDB || false;
  72. }
  73. /**
  74. * @see Platform#hasSize(String)
  75. */
  76. public function hasSize($sqlType)
  77. {
  78. return !("MEDIUMTEXT" == $sqlType || "LONGTEXT" == $sqlType
  79. || "BLOB" == $sqlType || "MEDIUMBLOB" == $sqlType
  80. || "LONGBLOB" == $sqlType);
  81. }
  82. /**
  83. * Escape the string for RDBMS.
  84. * @param string $text
  85. * @return string
  86. */
  87. public function disconnectedEscapeText($text)
  88. {
  89. if (function_exists('mysql_escape_string')) {
  90. return mysql_escape_string($text);
  91. } else {
  92. return addslashes($text);
  93. }
  94. }
  95. /**
  96. * @see Platform::quoteIdentifier()
  97. */
  98. public function quoteIdentifier($text)
  99. {
  100. return '`' . $text . '`';
  101. }
  102. /**
  103. * Gets the preferred timestamp formatter for setting date/time values.
  104. * @return string
  105. */
  106. public function getTimestampFormatter()
  107. {
  108. return 'Y-m-d H:i:s';
  109. }
  110. }