Mysql try ... catch

This commit is contained in:
Alexander Pankratov 2020-05-12 01:41:27 +03:00
parent 8254360d2f
commit 912577617e
2 changed files with 14 additions and 9 deletions

View File

@ -5,6 +5,7 @@ namespace danog\MadelineProto\Db;
use Amp\Mysql\ConnectionConfig; use Amp\Mysql\ConnectionConfig;
use Amp\Mysql\Pool; use Amp\Mysql\Pool;
use Amp\Sql\Common\ConnectionPool; use Amp\Sql\Common\ConnectionPool;
use danog\MadelineProto\Logger;
use function Amp\call; use function Amp\call;
use function Amp\Mysql\Pool; use function Amp\Mysql\Pool;
use function Amp\Promise\wait; use function Amp\Promise\wait;
@ -62,14 +63,18 @@ class Mysql
private static function createDb(ConnectionConfig $config) private static function createDb(ConnectionConfig $config)
{ {
wait(call(static function() use($config) { wait(call(static function() use($config) {
$db = $config->getDatabase(); try {
$connection = pool($config->withDatabase(null)); $db = $config->getDatabase();
yield $connection->query(" $connection = pool($config->withDatabase(null));
CREATE DATABASE IF NOT EXISTS `{$db}` yield $connection->query("
CHARACTER SET 'utf8mb4' CREATE DATABASE IF NOT EXISTS `{$db}`
COLLATE 'utf8mb4_general_ci' CHARACTER SET 'utf8mb4'
"); COLLATE 'utf8mb4_general_ci'
$connection->close(); ");
$connection->close();
} catch (\Throwable $e) {
Logger::log($e->getMessage(), Logger::ERROR);
}
})); }));
} }

View File

@ -320,7 +320,7 @@ class MysqlArray implements DbArray
try { try {
$request = yield $this->db->execute($query, $params); $request = yield $this->db->execute($query, $params);
} catch (\Throwable $e) { } catch (\Throwable $e) {
Logger::log($e, Logger::ERROR); Logger::log($e->getMessage(), Logger::ERROR);
return []; return [];
} }