Pgsql.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * Pgsql数据库驱动
  15. */
  16. class Pgsql extends Builder
  17. {
  18. /**
  19. * limit分析
  20. * @access protected
  21. * @param mixed $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. * @param string $key
  41. * @param array $options
  42. * @return string
  43. */
  44. protected function parseKey($key, $options = [])
  45. {
  46. $key = trim($key);
  47. if (strpos($key, '$.') && false === strpos($key, '(')) {
  48. // JSON字段支持
  49. list($field, $name) = explode('$.', $key);
  50. $key = $field . '->>\'' . $name . '\'';
  51. } elseif (strpos($key, '.')) {
  52. list($table, $key) = explode('.', $key, 2);
  53. if ('__TABLE__' == $table) {
  54. $table = $this->query->getTable();
  55. }
  56. if (isset($options['alias'][$table])) {
  57. $table = $options['alias'][$table];
  58. }
  59. }
  60. if (isset($table)) {
  61. $key = $table . '.' . $key;
  62. }
  63. return $key;
  64. }
  65. /**
  66. * 随机排序
  67. * @access protected
  68. * @return string
  69. */
  70. protected function parseRand()
  71. {
  72. return 'RANDOM()';
  73. }
  74. }