Laravel 5 whereRaw导致错误,但返回的查询在postgres客户端中运行正常

时间:2015-08-21 19:53:25

标签: php postgresql laravel

我收到错误: SQLSTATE [42P18]:不确定数据类型:7错误:无法确定参数$ 2的数据类型,主要问题是whereRaw()函数中的那个部分我的代码:

$result = $result->whereRaw(
    "lower(translate(?, ' ''àáâãäéèëêíìïîóòõöôúùüûçÇ', ' -aaaaaeeeeiiiiooooouuuucc')) LIKE lower(translate('%?%', ' ''àáâãäéèëêíìïîóòõöôúùüûçÇ', ' -aaaaaeeeeiiiiooooouuuucc'))",
    [
        $field_where,
        $value
    ]
);

但是当我得到结果查询并在我的postgres客户端中运行时,我得到的不是错误。

所以...问题是什么?

异常

SQLSTATE[42P18]: Indeterminate datatype: 7 ERROR: could not 
determine data type of parameter $2 (SQL: select count(*) as 
aggregate from "pace_records" left join "customers" on 
"customers"."id" = "pace_records"."customer_id" left join "cities"
on "cities"."id" = "customers"."city_id" left join 
"customer_subregions" on "customer_subregions"."id" = 
"pace_records"."customer_subregion_id" left join "schools" on 
"schools"."id" = "pace_records"."school_id" left join "programs" on 
"programs"."id" = "pace_records"."program_id" left join "users" on 
"users"."id" = "pace_records"."user_id" where 
"pace_records"."deleted_at" is null and 
lower(translate("cities"."name", ' ''àáâãäéèëêíìïîóòõöôúùüûçÇ', ' -aaaaaeeeeiiiiooooouuuucc')) LIKE 
lower(translate('%Arapi%', ' ''àáâãäéèëêíìïîóòõöôúùüûçÇ', ' -aaaaaeeeeiiiiooooouuuucc')))

完整代码

$result = static::joins();

if (isset(self::$searchable[$field])) {
    $field_where = $field;
    if (isset(self::$searchable[$field]['join_field'])) {
        $field_where = self::$searchable[$field]['join_field'];
    }

    $result = $result->whereRaw(
        "lower(translate(?, ' ''àáâãäéèëêíìïîóòõöôúùüûçÇ', ' -aaaaaeeeeiiiiooooouuuucc')) LIKE lower(translate('%?%', ' ''àáâãäéèëêíìïîóòõöôúùüûçÇ', ' -aaaaaeeeeiiiiooooouuuucc'))",
        [
            $field_where,
            $value
        ]
    );
}

return $result->orderBy('cities.name', 'ASC')
    ->orderBy('schools.name', 'ASC')
    ->orderBy('programs.name', 'ASC')
    ->paginate($maxPerPage);

的相关信息

  • Laravel 5.1.x
  • PHP 5.6.x
  • PostgreSQL 9.4
  • Mac OS Yosemite 10.10.4

如果您需要更多信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

我目前的解决方案是连接值而不是使用params。

就像那样:

$ColNameNow = "Name"
$SrcValue = $TextBox1.text

for ($i = 0; $i -lt $datagridview1.RowCount; $i++)
{
    if ($datagridview1.Rows[$i].Cells['Name'].Value -eq "$SrcValue")
    {
        [System.Windows.Forms.MessageBox]::Show("Found", "Update", "Ok", [System.Windows.Forms.MessageBoxIcon]::Warning)

        $datagridview1.CurrentRow.Index = $i            
        $datagridview1.CurrentRow = $datagridview1.Rows[$i].Cells[0]            
        $datagridview1.SelectedRows[$i]         
    }
}

有效,但我不喜欢这样做。

我会继续寻找其他解决方案。