前台插件访问

This commit is contained in:
2016-10-08 11:39:31 +08:00
parent a70c700b04
commit bb97786838
13 changed files with 176 additions and 72 deletions

View File

@@ -24,19 +24,28 @@ class Mysql extends Builder
* 字段和表名处理
* @access protected
* @param string $key
* @param array $options
* @return string
*/
protected function parseKey($key)
protected function parseKey($key, $options = [])
{
$key = trim($key);
if (strpos($key, '$.') && false === strpos($key, '(')) {
// JSON字段支持
list($field, $name) = explode('$.', $key);
$key = 'json_extract(' . $field . ', \'$.' . $name . '\')';
} elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
list($table, $key) = explode('.', $key, 2);
if (isset($options['alias'][$table])) {
$table = $options['alias'][$table];
}
}
if (!preg_match('/[,\'\"\*\(\)`.\s]/', $key)) {
$key = '`' . $key . '`';
}
if (isset($table)) {
$key = '`' . $table . '`.' . $key;
}
return $key;
}

View File

@@ -43,15 +43,24 @@ class Pgsql extends Builder
* 字段和表名处理
* @access protected
* @param string $key
* @param array $options
* @return string
*/
protected function parseKey($key)
protected function parseKey($key, $options = [])
{
$key = trim($key);
if (strpos($key, '$.') && false === strpos($key, '(')) {
// JSON字段支持
list($field, $name) = explode('$.', $key);
$key = $field . '->>\'' . $name . '\'';
} elseif (strpos($key, '.')) {
list($table, $key) = explode('.', $key, 2);
if (isset($options['alias'][$table])) {
$table = $options['alias'][$table];
}
}
if (isset($table)) {
$key = $table . '.' . $key;
}
return $key;
}

View File

@@ -48,4 +48,25 @@ class Sqlite extends Builder
return 'RANDOM()';
}
/**
* 字段和表名处理
* @access protected
* @param string $key
* @param array $options
* @return string
*/
protected function parseKey($key, $options = [])
{
$key = trim($key);
if (strpos($key, '.')) {
list($table, $key) = explode('.', $key, 2);
if (isset($options['alias'][$table])) {
$table = $options['alias'][$table];
}
}
if (isset($table)) {
$key = $table . '.' . $key;
}
return $key;
}
}

View File

@@ -61,17 +61,27 @@ class Sqlsrv extends Builder
}
/**
* 字段名分析
* 字段和表名处理
* @access protected
* @param string $key
* @param array $options
* @return string
*/
protected function parseKey($key)
protected function parseKey($key, $options = [])
{
$key = trim($key);
if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) {
list($table, $key) = explode('.', $key, 2);
if (isset($options['alias'][$table])) {
$table = $options['alias'][$table];
}
}
if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) {
$key = '[' . $key . ']';
}
if (isset($table)) {
$key = '[' . $table . '].' . $key;
}
return $key;
}