Sqlite.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\db\builder;
  12. use think\db\Builder;
  13. /**
  14. * Sqlite数据库驱动
  15. */
  16. class Sqlite extends Builder
  17. {
  18. /**
  19. * limit
  20. * @access public
  21. * @return string
  22. */
  23. public function parseLimit($limit)
  24. {
  25. $limitStr = '';
  26. if (!empty($limit)) {
  27. $limit = explode(',', $limit);
  28. if (count($limit) > 1) {
  29. $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' ';
  30. } else {
  31. $limitStr .= ' LIMIT ' . $limit[0] . ' ';
  32. }
  33. }
  34. return $limitStr;
  35. }
  36. /**
  37. * 随机排序
  38. * @access protected
  39. * @return string
  40. */
  41. protected function parseRand()
  42. {
  43. return 'RANDOM()';
  44. }
  45. /**
  46. * 字段和表名处理
  47. * @access protected
  48. * @param string $key
  49. * @param array $options
  50. * @return string
  51. */
  52. protected function parseKey($key, $options = [])
  53. {
  54. $key = trim($key);
  55. if (strpos($key, '.')) {
  56. list($table, $key) = explode('.', $key, 2);
  57. if ('__TABLE__' == $table) {
  58. $table = $this->query->getTable();
  59. }
  60. if (isset($options['alias'][$table])) {
  61. $table = $options['alias'][$table];
  62. }
  63. }
  64. if (isset($table)) {
  65. $key = $table . '.' . $key;
  66. }
  67. return $key;
  68. }
  69. }