Pgsql.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * Pgsql数据库驱动
  15. */
  16. class Pgsql extends Builder
  17. {
  18. protected $insertSql = 'INSERT INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%';
  19. protected $insertAllSql = 'INSERT INTO %TABLE% (%FIELD%) %DATA% %COMMENT%';
  20. /**
  21. * limit分析
  22. * @access protected
  23. * @param mixed $limit
  24. * @return string
  25. */
  26. public function parseLimit($limit)
  27. {
  28. $limitStr = '';
  29. if (!empty($limit)) {
  30. $limit = explode(',', $limit);
  31. if (count($limit) > 1) {
  32. $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' ';
  33. } else {
  34. $limitStr .= ' LIMIT ' . $limit[0] . ' ';
  35. }
  36. }
  37. return $limitStr;
  38. }
  39. /**
  40. * 字段和表名处理
  41. * @access protected
  42. * @param string $key
  43. * @param array $options
  44. * @return string
  45. */
  46. protected function parseKey($key, $options = [], $strict = false)
  47. {
  48. $key = trim($key);
  49. if (strpos($key, '$.') && false === strpos($key, '(')) {
  50. // JSON字段支持
  51. list($field, $name) = explode('$.', $key);
  52. $key = $field . '->>\'' . $name . '\'';
  53. } elseif (strpos($key, '.')) {
  54. list($table, $key) = explode('.', $key, 2);
  55. if ('__TABLE__' == $table) {
  56. $table = $this->query->getTable();
  57. }
  58. if (isset($options['alias'][$table])) {
  59. $table = $options['alias'][$table];
  60. }
  61. }
  62. if (isset($table)) {
  63. $key = $table . '.' . $key;
  64. }
  65. return $key;
  66. }
  67. /**
  68. * 随机排序
  69. * @access protected
  70. * @return string
  71. */
  72. protected function parseRand()
  73. {
  74. return 'RANDOM()';
  75. }
  76. }