DBSQLite.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 SQLite database.
  11. *
  12. * @author Hans Lellelid <hans@xmpl.org>
  13. * @version $Revision: 1612 $
  14. * @package propel.runtime.adapter
  15. */
  16. class DBSQLite extends DBAdapter
  17. {
  18. /**
  19. * For SQLite this method has no effect, since SQLite doesn't support specifying a character
  20. * set (or, another way to look at it, it doesn't require a single character set per DB).
  21. *
  22. * @param PDO A PDO connection instance.
  23. * @param string The charset encoding.
  24. * @throws PropelException If the specified charset doesn't match sqlite_libencoding()
  25. */
  26. public function setCharset(PDO $con, $charset)
  27. {
  28. }
  29. /**
  30. * This method is used to ignore case.
  31. *
  32. * @param in The string to transform to upper case.
  33. * @return The upper case string.
  34. */
  35. public function toUpperCase($in)
  36. {
  37. return 'UPPER(' . $in . ')';
  38. }
  39. /**
  40. * This method is used to ignore case.
  41. *
  42. * @param in The string whose case to ignore.
  43. * @return The string in a case that can be ignored.
  44. */
  45. public function ignoreCase($in)
  46. {
  47. return 'UPPER(' . $in . ')';
  48. }
  49. /**
  50. * Returns SQL which concatenates the second string to the first.
  51. *
  52. * @param string String to concatenate.
  53. * @param string String to append.
  54. * @return string
  55. */
  56. public function concatString($s1, $s2)
  57. {
  58. return "($s1 || $s2)";
  59. }
  60. /**
  61. * Returns SQL which extracts a substring.
  62. *
  63. * @param string String to extract from.
  64. * @param int Offset to start from.
  65. * @param int Number of characters to extract.
  66. * @return string
  67. */
  68. public function subString($s, $pos, $len)
  69. {
  70. return "substr($s, $pos, $len)";
  71. }
  72. /**
  73. * Returns SQL which calculates the length (in chars) of a string.
  74. *
  75. * @param string String to calculate length of.
  76. * @return string
  77. */
  78. public function strLength($s)
  79. {
  80. return "length($s)";
  81. }
  82. /**
  83. * @see DBAdapter::quoteIdentifier()
  84. */
  85. public function quoteIdentifier($text)
  86. {
  87. return '[' . $text . ']';
  88. }
  89. /**
  90. * @see DBAdapter::applyLimit()
  91. */
  92. public function applyLimit(&$sql, $offset, $limit)
  93. {
  94. if ( $limit > 0 ) {
  95. $sql .= " LIMIT " . $limit . ($offset > 0 ? " OFFSET " . $offset : "");
  96. } elseif ( $offset > 0 ) {
  97. $sql .= " LIMIT -1 OFFSET " . $offset;
  98. }
  99. }
  100. public function random($seed=NULL)
  101. {
  102. return 'random()';
  103. }
  104. }