mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
增加Expression类及相关方法
This commit is contained in:
@@ -86,13 +86,16 @@ class Mysql extends Builder
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function parseKey($key, $options = [])
|
||||
protected function parseKey($key, $options = [], $strict = false)
|
||||
{
|
||||
if (is_int($key)) {
|
||||
return $key;
|
||||
}
|
||||
$key = trim($key);
|
||||
if (strpos($key, '$.') && false === strpos($key, '(')) {
|
||||
// JSON字段支持
|
||||
list($field, $name) = explode('$.', $key);
|
||||
$key = 'json_extract(' . $field . ', \'$.' . $name . '\')';
|
||||
return 'json_extract(' . $field . ', \'$.' . $name . '\')';
|
||||
} elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
|
||||
list($table, $key) = explode('.', $key, 2);
|
||||
if ('__TABLE__' == $table) {
|
||||
@@ -102,7 +105,7 @@ class Mysql extends Builder
|
||||
$table = $options['alias'][$table];
|
||||
}
|
||||
}
|
||||
if (!preg_match('/[,\'\"\*\(\)`.\s]/', $key)) {
|
||||
if ($strict || !preg_match('/[,\'\"\*\(\)`.\s]/', $key)) {
|
||||
$key = '`' . $key . '`';
|
||||
}
|
||||
if (isset($table)) {
|
||||
|
||||
@@ -48,7 +48,7 @@ class Pgsql extends Builder
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function parseKey($key, $options = [])
|
||||
protected function parseKey($key, $options = [], $strict = false)
|
||||
{
|
||||
$key = trim($key);
|
||||
if (strpos($key, '$.') && false === strpos($key, '(')) {
|
||||
|
||||
@@ -56,7 +56,7 @@ class Sqlite extends Builder
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function parseKey($key, $options = [])
|
||||
protected function parseKey($key, $options = [], $strict = false)
|
||||
{
|
||||
$key = trim($key);
|
||||
if (strpos($key, '.')) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace think\db\builder;
|
||||
|
||||
use think\db\Builder;
|
||||
use think\db\Expression;
|
||||
|
||||
/**
|
||||
* Sqlsrv数据库驱动
|
||||
@@ -37,7 +38,9 @@ class Sqlsrv extends Builder
|
||||
if (is_array($order)) {
|
||||
$array = [];
|
||||
foreach ($order as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
if ($val instanceof Expression) {
|
||||
$array[] = $val->getValue();
|
||||
} elseif (is_numeric($key)) {
|
||||
if (false === strpos($val, '(')) {
|
||||
$array[] = $this->parseKey($val, $options);
|
||||
} elseif ('[rand]' == $val) {
|
||||
@@ -72,8 +75,11 @@ class Sqlsrv extends Builder
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function parseKey($key, $options = [])
|
||||
protected function parseKey($key, $options = [], $strict = false)
|
||||
{
|
||||
if (is_int($key)) {
|
||||
return $key;
|
||||
}
|
||||
$key = trim($key);
|
||||
if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) {
|
||||
list($table, $key) = explode('.', $key, 2);
|
||||
@@ -84,7 +90,7 @@ class Sqlsrv extends Builder
|
||||
$table = $options['alias'][$table];
|
||||
}
|
||||
}
|
||||
if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) {
|
||||
if ($strict || !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) {
|
||||
$key = '[' . $key . ']';
|
||||
}
|
||||
if (isset($table)) {
|
||||
|
||||
Reference in New Issue
Block a user