Skip to content
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

修复 issue #468 db链式方法cache查询时判断和返回类型错误问题 #526

Closed
wants to merge 2 commits into from
Closed
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
89 changes: 45 additions & 44 deletions src/db/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,45 @@ abstract class PDOConnection extends Connection
*/
protected $config = [
// 数据库类型
'type' => '',
'type' => '',
// 服务器地址
'hostname' => '',
'hostname' => '',
// 数据库名
'database' => '',
'database' => '',
// 用户名
'username' => '',
'username' => '',
// 密码
'password' => '',
'password' => '',
// 端口
'hostport' => '',
'hostport' => '',
// 连接dsn
'dsn' => '',
'dsn' => '',
// 数据库连接参数
'params' => [],
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '',
'prefix' => '',
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
'slave_no' => '',
// 模型写入后自动读取主服务器
'read_master' => false,
'read_master' => false,
// 是否严格检查字段是否存在
'fields_strict' => true,
'fields_strict' => true,
// 开启字段缓存
'fields_cache' => false,
'fields_cache' => false,
// 监听SQL
'trigger_sql' => true,
'trigger_sql' => true,
// Builder类
'builder' => '',
'builder' => '',
// Query类
'query' => '',
'query' => '',
// 是否需要断线重连
'break_reconnect' => false,
// 断线标识字符串
Expand Down Expand Up @@ -148,11 +148,11 @@ abstract class PDOConnection extends Connection
* @var array
*/
protected $params = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_EMULATE_PREPARES => false,
];

/**
Expand All @@ -161,14 +161,14 @@ abstract class PDOConnection extends Connection
* @var array
*/
protected $bindType = [
'string' => self::PARAM_STR,
'str' => self::PARAM_STR,
'integer' => self::PARAM_INT,
'int' => self::PARAM_INT,
'boolean' => self::PARAM_BOOL,
'bool' => self::PARAM_BOOL,
'float' => self::PARAM_FLOAT,
'datetime' => self::PARAM_STR,
'string' => self::PARAM_STR,
'str' => self::PARAM_STR,
'integer' => self::PARAM_INT,
'int' => self::PARAM_INT,
'boolean' => self::PARAM_BOOL,
'bool' => self::PARAM_BOOL,
'float' => self::PARAM_FLOAT,
'datetime' => self::PARAM_STR,
'timestamp' => self::PARAM_STR,
];

Expand Down Expand Up @@ -276,10 +276,10 @@ public function fieldCase(array $info): array
{
// 字段大小写转换
return match ($this->attrCase) {
PDO::CASE_LOWER => array_change_key_case($info),
PDO::CASE_UPPER => array_change_key_case($info, CASE_UPPER),
PDO::CASE_NATURAL => $info,
default => $info,
PDO::CASE_LOWER => array_change_key_case($info),
PDO::CASE_UPPER => array_change_key_case($info, CASE_UPPER),
PDO::CASE_NATURAL => $info,
default => $info,
};
}

Expand Down Expand Up @@ -389,10 +389,10 @@ public function getSchemaInfo(string $tableName, $force = false)
}

$this->info[$schema] = [
'fields' => array_keys($info),
'type' => $info,
'bind' => $bind,
'pk' => $pk,
'fields' => array_keys($info),
'type' => $info,
'bind' => $bind,
'pk' => $pk,
'autoinc' => $autoinc,
];
}
Expand Down Expand Up @@ -724,9 +724,10 @@ protected function pdoQuery(BaseQuery $query, $sql, bool $master = null): array
$key = $cacheItem->getKey();

$data = $this->cache->get($key);

if (null !== $data) {
if (gettype($data) !== 'boolean' && null !== $data) {
return $data;
} else {
return [];
}
}
}
Expand Down Expand Up @@ -891,8 +892,8 @@ protected function pdoExecute(BaseQuery $query, string $sql, bool $origin = fals
*/
protected function queryPDOStatement(BaseQuery $query, string $sql): PDOStatement
{
$options = $query->getOptions();
$bind = $query->getBind();
$options = $query->getOptions();
$bind = $query->getBind();
$master = !empty($options['master']);
$procedure = !empty($options['procedure']) || in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']);

Expand Down