Skip to content

修复 3.2.0 中 dbType 报错的 Bug #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ZM/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Framework
public const VERSION_ID = 721;

/** @var string 版本名称 */
public const VERSION = '3.2.0';
public const VERSION = '3.2.1';

/**
* @var RuntimePreferences 运行时偏好(环境信息&参数)
Expand Down
4 changes: 2 additions & 2 deletions src/ZM/Store/Database/DBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class DBConnection implements Connection
public function __construct(private array $params)
{
$this->db_type = $params['dbType'] ?? ZM_DB_POOL;
if ($params['dbType'] === ZM_DB_POOL) {
if ($this->db_type === ZM_DB_POOL) {
// 默认连接池的形式,
logger()->debug('Constructing...');
$this->conn = DBPool::pool($params['dbName'])->get();
$this->pool_name = $params['dbName'];
} elseif ($params['dbType'] === ZM_DB_PORTABLE) {
} elseif ($this->db_type === ZM_DB_PORTABLE) {
$connect_str = 'sqlite:{filename}';
if (FileSystem::isRelativePath($params['filename'])) {
$params['filename'] = zm_dir(config('global.data_dir') . '/db/' . $params['filename']);
Expand Down
12 changes: 10 additions & 2 deletions src/ZM/Store/Database/DBWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,27 @@ public function __construct(string $name, array $options = [])
$db_type = $options['dbType'] ?? ZM_DB_POOL;
try {
if ($db_type === ZM_DB_POOL) {
// 设置 dbName
$options['dbName'] = $name;
// pool 为连接池格式
$db_list = config()->get('global.database');
if (isset($db_list[$name]) || (is_countable($db_list) ? count($db_list) : 0) === 1) {
if ($name === '') {
$name = array_key_first($db_list);
}
$this->connection = DriverManager::getConnection(['driverClass' => $this->getConnectionClass($db_list[$name]['type']), ...$options]);
$this->connection = DriverManager::getConnection(array_merge(
['driverClass' => $this->getConnectionClass($db_list[$name]['type']), 'dbName' => $name],
$options
));
} else {
throw new DBException('Cannot find database config named "' . $name . '" !');
}
} elseif ($db_type === ZM_DB_PORTABLE) {
// portable 为sqlite单文件模式
$this->connection = DriverManager::getConnection(['driverClass' => SQLiteDriver::class, 'filename' => $name, ...$options]);
$this->connection = DriverManager::getConnection(array_merge(
['driverClass' => SQLiteDriver::class, 'filename' => $name],
$options
));
}
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
Expand Down