Allow dots in mysql table names

This commit is contained in:
Alexander Pankratov 2020-05-17 00:38:30 +03:00
parent fa1d73009d
commit 9016a7c0dd

View File

@ -114,7 +114,7 @@ class MysqlArray implements DbArray
} }
$row = yield $this->request( $row = yield $this->request(
"SELECT `value` FROM {$this->table} WHERE `key` = :index LIMIT 1", "SELECT `value` FROM `{$this->table}` WHERE `key` = :index LIMIT 1",
['index' => $offset] ['index' => $offset]
); );
@ -192,7 +192,7 @@ class MysqlArray implements DbArray
*/ */
public function getArrayCopy(): array public function getArrayCopy(): array
{ {
$rows = $this->syncRequest("SELECT `key`, `value` FROM {$this->table}"); $rows = $this->syncRequest("SELECT `key`, `value` FROM `{$this->table}`");
$result = []; $result = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$result[$row['key']] = $this->getValue($row); $result[$row['key']] = $this->getValue($row);
@ -204,7 +204,7 @@ class MysqlArray implements DbArray
public function getIterator(): Producer public function getIterator(): Producer
{ {
return new Producer(function (callable $emit) { return new Producer(function (callable $emit) {
$request = yield $this->db->execute("SELECT `key`, `value` FROM {$this->table}"); $request = yield $this->db->execute("SELECT `key`, `value` FROM `{$this->table}`");
while (yield $request->advance()) { while (yield $request->advance()) {
$row = $request->getCurrent(); $row = $request->getCurrent();
@ -225,7 +225,7 @@ class MysqlArray implements DbArray
public function count(): Promise public function count(): Promise
{ {
return call(function(){ return call(function(){
$row = yield $this->request("SELECT count(`key`) as `count` FROM {$this->table}"); $row = yield $this->request("SELECT count(`key`) as `count` FROM `{$this->table}`");
return $row[0]['count'] ?? 0; return $row[0]['count'] ?? 0;
}); });
} }
@ -279,11 +279,11 @@ class MysqlArray implements DbArray
private function renameTable(string $from, string $to) private function renameTable(string $from, string $to)
{ {
yield $this->request(" yield $this->request("
ALTER TABLE {$from} RENAME TO {$to}; ALTER TABLE `{$from}` RENAME TO `{$to}`;
"); ");
yield $this->request(" yield $this->request("
DROP TABLE IF EXISTS {$from}; DROP TABLE IF EXISTS `{$from}`;
"); ");
} }