This commit is contained in:
as2252258@163.com
2021-07-03 13:41:45 +08:00
parent 40f315f4d9
commit 19bd6882d1
+1 -3
View File
@@ -266,14 +266,12 @@ class Connection extends Component
public function createCommand($sql = null, array $attributes = []): Command
{
$substr = strtoupper(substr($sql, 0, 6));
var_dump($substr);
$sql = match ($substr) {
'SELECT', 'SHOW F' => preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $this->database . '`.$1 ', $sql),
'UPDATE' => preg_replace('/UPDATE\s+(\w+)\s+SET/', 'UPDATE `' . $this->database . '`.$1 SET', $sql),
'DELETE' => preg_replace('/DELETE FROM\s+(\w+)\s+/', 'DELETE FROM `' . $this->database . '`.$1', $sql),
'INSERT' => preg_replace('/INSERT INTO\s+(\w+)\s+/', 'INSERT INTO `' . $this->database . '`.$1', $sql),
'TRUNCA' => preg_replace('/TRUNCATE\s+(\w+)\s+/', 'TRUNCATE `' . $this->database . '`.$1', $sql),
default => throw new Exception('database error')
};
$command = new Command(['db' => $this, 'sql' => $sql]);