Skip to content

Commit c05cef4

Browse files
committed
优化
1 parent 9530eaa commit c05cef4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ShardingQuery.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ class ShardingQuery
8787
*/
8888
protected $trace;
8989

90+
/**
91+
* 表通配符
92+
* @var string
93+
*/
94+
protected static $tableSymbol = '{table}';
95+
9096
/**
9197
* ShardingQuery constructor.
9298
* @param array $config
@@ -176,7 +182,7 @@ public function select()
176182
$sql = $this->sql();
177183
$data = [];
178184
foreach ($range as $tableName => $item) {
179-
$tmpSql = str_replace('{table}', $tableName, $sql);
185+
$tmpSql = str_replace(static::$tableSymbol, $tableName, $sql);
180186
$tmpSql = "{$tmpSql} LIMIT {$item['limit']} OFFSET {$item['offset']}";
181187
$result = call_user_func($this->callback, $tmpSql);
182188
$data = array_merge($data, $result);
@@ -202,6 +208,7 @@ protected function stats($table)
202208
if (!empty($this->where)) {
203209
$sql .= " WHERE {$this->where}";
204210
}
211+
$sql = str_replace(static::$tableSymbol, $tableName, $sql);
205212
$result = call_user_func($this->callback, $sql);
206213
$first = array_pop($result);
207214
$count = array_pop($first);

0 commit comments

Comments
 (0)