DB BaseBuilder Join() - RawSql as table
维护者通常 1 天内回复
评估
调研方向
从 system/Database/BaseBuilder.php 中的 join() 和 trackAliases() 开始,然后检查 system/Model.php 第 930 行的调用。验证可以将 RawSql 表传递给 join() 而不会产生 TypeError,同时现有的字符串和带别名表的 join 仍能正常工作。
由索引模型根据 Issue 内容生成。
描述
PHP Version
8.2
CodeIgniter4 Version
4.5.3
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
CRITICAL - 2024-07-24 14:10:15 --> TypeError: CodeIgniter\Database\BaseBuilder::join(): Argument #1 ($table) must be of type string, CodeIgniter\Database\RawSql given, called in C:\xampp\portal\vendor\codeigniter4\framework\system\Model.php on line 930
[Method: GET, Route: public/fuel/pricing/getprice]
in SYSTEMPATH\Database\BaseBuilder.php on line 620.
1 SYSTEMPATH\Model.php(930): CodeIgniter\Database\BaseBuilder->join(Object(CodeIgniter\Database\RawSql), 't5.product_id = fpp.id', 'inner')
Steps to Reproduce
Used to be able to use RawSql for table on join()
$builder = $this
->select("{$this->table}.description_id AS id, fpd.description,
fpp.product,
DATE({$this->table}.effective) AS effective,
{$priceField}")
->join(
"{$this->descTable} AS fpd",
"fpd.id = {$this->table}.description_id",
'inner'
)
->join(
"{$this->prodTable} AS fpp",
"fpp.id = {$this->table}.product_id",
'inner'
);
$sql = "(SELECT
fpp.id AS product_id,
IF(ph.TAXCLASS IS NULL,0,ph.TAXCLASS) AS taxclass,
IF(pw.SALESTAXCLASS IS NULL,0,pw.SALESTAXCLASS) AS salestaxclass
FROM
misc.fuel_prices_product AS fpp
LEFT JOIN pds.pds_prodhead AS ph ON ph.PRODUCTCODE = fpp.product
LEFT JOIN pds.pds_prodware AS pw ON pw.PRODUCTCODE = fpp.product AND pw.PACKCODE = '' AND pw.WHALPHA = 3
GROUP BY fpp.id) t5";
$builder->join(
new RawSql($sql),
"t5.product_id = `fpp`.id",
'inner'
);
// $params['id'] = 14;
$builder->where("{$this->table}.description_id", $params['id']);
$builder->where("DATE({$this->table}.effective) BETWEEN DATE_SUB('{$params['fromdate']}',INTERVAL 15 DAY) AND '{$params['todate']}'");
$builder->where('fpp.product', $params['product']);
$builder->groupBY("DATE({$this->table}.effective)");
$builder->orderBy("{$this->table}.effective", 'ASC');
$data = $builder->get()->getResultObject();
Expected Output
Get errors now.
Fix by adding adding RawSq type:
public function join(string|RawSql $table, $cond, string $type = '', ?bool $escape = null)
{
Adding is_string($table) twice in BaseBuilder::trackAliases()
protected function trackAliases($table)
{
if (is_array($table)) {
foreach ($table as $t) {
$this->trackAliases($t);
}
return;
}
// Does the string contain a comma? If so, we need to separate
// the string into discreet statements
if (is_string($table) && str_contains($table, ',')) {
return $this->trackAliases(explode(',', $table));
}
// if a table alias is used we can recognize it by a space
if (is_string($table) && str_contains($table, ' ')) {
Anything else?
I'd send in a PR but I'm slammed busy at the moment and I don't have my development environment ready.
- 主要语言
- PHP
- 星标
- 6k
- 派生
- 2k
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 59
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
codeigniter4/CodeIgniter4 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
codeigniter4/CodeIgniter4#10616 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
codeigniter4/CodeIgniter4#10618 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
codeigniter4/CodeIgniter4#10617 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
codeigniter4/CodeIgniter4#10615 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 48/100
codeigniter4/CodeIgniter4#10589 · 3 条评论 ·
维护者通常 1 天内回复
查看 codeigniter4/CodeIgniter4 的全部 Issue
相似的 Issue
-
FrameworkBundle SecurityBundle
难度 2/5 1-3 小时 新手友好度 68/100
symfony/symfony-docs#23277 ·
维护者通常 3 天内回复
-
[Sync EN] hard link does not need special permissions可能已有人在做 @lacatoire 今天认领。 未关闭sync-en
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
sync-en
难度 1/5 1 小时以内 新手友好度 76/100
维护者通常 4 天内回复
-
bug mod:appointments
难度 2/5 1-3 小时 新手友好度 78/100
3pontos-tech/gil-benefits#303 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复