Sqlite.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 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. * @param string $limit
  22. * @return string
  23. */
  24. public function parseLimit($limit)
  25. {
  26. $limitStr = '';
  27. if (!empty($limit)) {
  28. $limit = explode(',', $limit);
  29. if (count($limit) > 1) {
  30. $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' ';
  31. } else {
  32. $limitStr .= ' LIMIT ' . $limit[0] . ' ';
  33. }
  34. }
  35. return $limitStr;
  36. }
  37. /**
  38. * 随机排序
  39. * @access protected
  40. * @return string
  41. */
  42. protected function parseRand()
  43. {
  44. return 'RANDOM()';
  45. }
  46. /**
  47. * 字段和表名处理
  48. * @access protected
  49. * @param mixed $key
  50. * @param array $options
  51. * @return string
  52. */
  53. protected function parseKey($key, $options = [], $strict = false)
  54. {
  55. if (is_numeric($key)) {
  56. return $key;
  57. } elseif ($key instanceof Expression) {
  58. return $key->getValue();
  59. }
  60. $key = trim($key);
  61. if (strpos($key, '.')) {
  62. list($table, $key) = explode('.', $key, 2);
  63. if ('__TABLE__' == $table) {
  64. $table = $this->query->getTable();
  65. }
  66. if (isset($options['alias'][$table])) {
  67. $table = $options['alias'][$table];
  68. }
  69. }
  70. if (isset($table)) {
  71. $key = $table . '.' . $key;
  72. }
  73. return $key;
  74. }
  75. }