sqlite3.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2011 Robin Appelman icewind1991@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. require_once 'MDB2/Driver/Function/Common.php';
  23. /**
  24. * MDB2 SQLite driver for the function modules
  25. *
  26. * @package MDB2
  27. * @category Database
  28. * @author Lukas Smith <smith@pooteeweet.org>
  29. */
  30. class MDB2_Driver_Function_sqlite3 extends MDB2_Driver_Function_Common
  31. {
  32. // {{{ constructor
  33. /**
  34. * Constructor
  35. */
  36. function __construct($db_index)
  37. {
  38. parent::__construct($db_index);
  39. // create all sorts of UDFs
  40. }
  41. // {{{ now()
  42. /**
  43. * Return string to call a variable with the current timestamp inside an SQL statement
  44. * There are three special variables for current date and time.
  45. *
  46. * @return string to call a variable with the current timestamp
  47. * @access public
  48. */
  49. function now($type = 'timestamp')
  50. {
  51. switch ($type) {
  52. case 'time':
  53. return 'CURRENT_TIME';
  54. case 'date':
  55. return 'CURRENT_DATE';
  56. case 'timestamp':
  57. default:
  58. return 'CURRENT_TIMESTAMP';
  59. }
  60. }
  61. // }}}
  62. // {{{ unixtimestamp()
  63. /**
  64. * return string to call a function to get the unix timestamp from a iso timestamp
  65. *
  66. * @param string $expression
  67. *
  68. * @return string to call a variable with the timestamp
  69. * @access public
  70. */
  71. function unixtimestamp($expression)
  72. {
  73. return 'strftime("%s",'. $expression.', "utc")';
  74. }
  75. // }}}
  76. // {{{ substring()
  77. /**
  78. * return string to call a function to get a substring inside an SQL statement
  79. *
  80. * @return string to call a function to get a substring
  81. * @access public
  82. */
  83. function substring($value, $position = 1, $length = null)
  84. {
  85. if (!is_null($length)) {
  86. return "substr($value,$position,$length)";
  87. }
  88. return "substr($value,$position,length($value))";
  89. }
  90. // }}}
  91. // {{{ random()
  92. /**
  93. * return string to call a function to get random value inside an SQL statement
  94. *
  95. * @return return string to generate float between 0 and 1
  96. * @access public
  97. */
  98. function random()
  99. {
  100. return '((RANDOM()+2147483648)/4294967296)';
  101. }
  102. // }}}
  103. // {{{ replace()
  104. /**
  105. * return string to call a function to get a replacement inside an SQL statement.
  106. *
  107. * @return string to call a function to get a replace
  108. * @access public
  109. */
  110. function replace($str, $from_str, $to_str)
  111. {
  112. $db =& $this->getDBInstance();
  113. if (PEAR::isError($db)) {
  114. return $db;
  115. }
  116. $error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  117. 'method not implemented', __FUNCTION__);
  118. return $error;
  119. }
  120. // }}}
  121. }