DBMySQL.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * This is used in order to connect to a MySQL database.
  11. *
  12. * @author Hans Lellelid <hans@xmpl.org> (Propel)
  13. * @author Jon S. Stevens <jon@clearink.com> (Torque)
  14. * @author Brett McLaughlin <bmclaugh@algx.net> (Torque)
  15. * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
  16. * @version $Revision: 1612 $
  17. * @package propel.runtime.adapter
  18. */
  19. class DBMySQL extends DBAdapter
  20. {
  21. /**
  22. * This method is used to ignore case.
  23. *
  24. * @param in The string to transform to upper case.
  25. * @return The upper case string.
  26. */
  27. public function toUpperCase($in)
  28. {
  29. return "UPPER(" . $in . ")";
  30. }
  31. /**
  32. * This method is used to ignore case.
  33. *
  34. * @param in The string whose case to ignore.
  35. * @return The string in a case that can be ignored.
  36. */
  37. public function ignoreCase($in)
  38. {
  39. return "UPPER(" . $in . ")";
  40. }
  41. /**
  42. * Returns SQL which concatenates the second string to the first.
  43. *
  44. * @param string String to concatenate.
  45. * @param string String to append.
  46. * @return string
  47. */
  48. public function concatString($s1, $s2)
  49. {
  50. return "CONCAT($s1, $s2)";
  51. }
  52. /**
  53. * Returns SQL which extracts a substring.
  54. *
  55. * @param string String to extract from.
  56. * @param int Offset to start from.
  57. * @param int Number of characters to extract.
  58. * @return string
  59. */
  60. public function subString($s, $pos, $len)
  61. {
  62. return "SUBSTRING($s, $pos, $len)";
  63. }
  64. /**
  65. * Returns SQL which calculates the length (in chars) of a string.
  66. *
  67. * @param string String to calculate length of.
  68. * @return string
  69. */
  70. public function strLength($s)
  71. {
  72. return "CHAR_LENGTH($s)";
  73. }
  74. /**
  75. * Locks the specified table.
  76. *
  77. * @param Connection $con The Propel connection to use.
  78. * @param string $table The name of the table to lock.
  79. * @throws PDOException No Statement could be created or
  80. * executed.
  81. */
  82. public function lockTable(PDO $con, $table)
  83. {
  84. $con->exec("LOCK TABLE " . $table . " WRITE");
  85. }
  86. /**
  87. * Unlocks the specified table.
  88. *
  89. * @param PDO $con The PDO connection to use.
  90. * @param string $table The name of the table to unlock.
  91. * @throws PDOException No Statement could be created or
  92. * executed.
  93. */
  94. public function unlockTable(PDO $con, $table)
  95. {
  96. $statement = $con->exec("UNLOCK TABLES");
  97. }
  98. /**
  99. * @see DBAdapter::quoteIdentifier()
  100. */
  101. public function quoteIdentifier($text)
  102. {
  103. return '`' . $text . '`';
  104. }
  105. /**
  106. * @see DBAdapter::useQuoteIdentifier()
  107. */
  108. public function useQuoteIdentifier()
  109. {
  110. return true;
  111. }
  112. /**
  113. * @see DBAdapter::applyLimit()
  114. */
  115. public function applyLimit(&$sql, $offset, $limit)
  116. {
  117. if ( $limit > 0 ) {
  118. $sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit;
  119. } else if ( $offset > 0 ) {
  120. $sql .= " LIMIT " . $offset . ", 18446744073709551615";
  121. }
  122. }
  123. /**
  124. * @see DBAdapter::random()
  125. */
  126. public function random($seed = null)
  127. {
  128. return 'rand('.((int) $seed).')';
  129. }
  130. }