Pgsql.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 (isset($options['alias'][$table])) {
  54. $table = $options['alias'][$table];
  55. }
  56. }
  57. if (isset($table)) {
  58. $key = $table . '.' . $key;
  59. }
  60. return $key;
  61. }
  62. /**
  63. * 随机排序
  64. * @access protected
  65. * @return string
  66. */
  67. protected function parseRand()
  68. {
  69. return 'RANDOM()';
  70. }
  71. }