DBPostgres.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 to connect to PostgresQL databases.
  11. *
  12. * <a href="http://www.pgsql.org">http://www.pgsql.org</a>
  13. *
  14. * @author Hans Lellelid <hans@xmpl.org> (Propel)
  15. * @author Hakan Tandogan <hakan42@gmx.de> (Torque)
  16. * @version $Revision: 1612 $
  17. * @package propel.runtime.adapter
  18. */
  19. class DBPostgres extends DBAdapter
  20. {
  21. /**
  22. * This method is used to ignore case.
  23. *
  24. * @param string $in The string to transform to upper case.
  25. * @return string 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 "($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 from $pos" . ($len > -1 ? "for $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. * @see DBAdapter::getIdMethod()
  76. */
  77. protected function getIdMethod()
  78. {
  79. return DBAdapter::ID_METHOD_SEQUENCE;
  80. }
  81. /**
  82. * Gets ID for specified sequence name.
  83. */
  84. public function getId(PDO $con, $name = null)
  85. {
  86. if ($name === null) {
  87. throw new PropelException("Unable to fetch next sequence ID without sequence name.");
  88. }
  89. $stmt = $con->query("SELECT nextval(".$con->quote($name).")");
  90. $row = $stmt->fetch(PDO::FETCH_NUM);
  91. return $row[0];
  92. }
  93. /**
  94. * Returns timestamp formatter string for use in date() function.
  95. * @return string
  96. */
  97. public function getTimestampFormatter()
  98. {
  99. return "Y-m-d H:i:s O";
  100. }
  101. /**
  102. * Returns timestamp formatter string for use in date() function.
  103. * @return string
  104. */
  105. public function getTimeFormatter()
  106. {
  107. return "H:i:s O";
  108. }
  109. /**
  110. * @see DBAdapter::applyLimit()
  111. */
  112. public function applyLimit(&$sql, $offset, $limit)
  113. {
  114. if ( $limit > 0 ) {
  115. $sql .= " LIMIT ".$limit;
  116. }
  117. if ( $offset > 0 ) {
  118. $sql .= " OFFSET ".$offset;
  119. }
  120. }
  121. /**
  122. * @see DBAdapter::random()
  123. */
  124. public function random($seed=NULL)
  125. {
  126. return 'random()';
  127. }
  128. }