我正在尝试将switch语句重构为集合。 switch语句根据switch条件选择要运行的正确SQL查询。
查询都在switch语句中有连接,这在类中的数组中不起作用。这是一个类似于我正在处理的示例查询:
"select qqqq,wwww,eeee,rrrr,tttt, 'yyyy' as uuuu from " . CONSTANT . ".aaaa as ssss inner join ' . CONSTANT2 . '.ddddd .... etc.
有什么建议吗?
修改
这是接近实际代码的东西。我对隐私进行了一些更改:
<?php
命名空间集合;
class ScheduleSQL {
private $sql;
public function __construct($plant)
{
$sql = [
'fgfghh' => "select fdgsgdfg, sgfdfgfg, rotary_priority,sfgfgfddg,sgfsgf, JB_ULT_CUST,jbr_status, jb_cust_want_date, routing_done, jb_date_need, js_time_ship, js_ship_via, jb_job_desc, rot.job_nbr, rot.job_plt, rot.job_type, sdfgdfgdf, js_ship_to, js_shipto_name, js_state, js_city, jbr_created as cvbvbv,xbvbvb, xbvbvb,xvbvbbcvb, vbvbvbas job_class, ruling_completed,scheduled_rule_date, converter, scenario_id, scenario_subdomain, transfer_type,transfer_job, jb_slope, jb_inch
from ' . DB_RASTER_LIB . 'jbraster as rot
inner join ' . DB_STR_LIB . '.sessions_and_jobs as str
on rot.job_type = str.job_type and str.jb_job = rot.job_nbr and cgc.jb_plt = rot.job_plt
inner join ' . DB_RASTER_LIB . '.rot_job_sp as rot_sp
on rot_sp.jb_job = str.jb_job and rot_sp.jb_plt = str.jb_plt and rot_sp.job_type = rot.job_type
left outer join ' . DB_RASTER_LIB . '.job_data as rot_jd
on rot_jd.job_nbr = str.jb_job and rot_jd.job_plt = str.jb_plt and rot_jd.job_type = rot.job_type
inner join ' . DB_STR_LIB . '.jobshp as shp
on str.jb_job = shp.js_job and str.jb_plt = shp.js_plt and shp.job_type = rot.job_type and shp.js_primary = 1
where rot.job_plt = $plant and rot.job_type <> A and (jbr_status is null or jbr_status<>99)
order by jb_date_need asc"
];
}
public function getSQL($type)
{
return $this->sql[$type];
}
}
答案 0 :(得分:0)
我发现问题在于如何将变量$ plant拉入查询字符串。
将其包含在数组外部的双引号内 - 在switch语句的原始上下文中。但是,当我正在进行数组操作时,变量必须在双引号之外。
即
"query statement parts".$string."other query string parts"
感谢所有回复的人。