LoginSignup
2
0

More than 5 years have passed since last update.

QueryExceptionのエラーメッセージのちょっとした不具合?

Posted at

セッションのHandlerを拡張して書いてたらちょっとエラーのなかで?になった箇所がったので調べてみた。

環境と前提

  • PHP7.1
  • Laravel 5.5.39
  • セッション保存先にDBを使っている

現象

とある理由でSQLエラーになったときに本来 ? で記録される場所にbindingsの値が入ってた。

sql

insert XXX (id, data, updated) values (?,?,?);

bindings

[
 'xxxx',
 'a:4:{s:9:"_previous";a:1:{s:3:"url";s:64:"http://xxxxxxx/xxxx/?key=val";}}',
 '2018-03-27 18:55:39'
]

QueryExceptionのgetMessageの出力

insert XXX (id, data, updated) values (xxxx, a:4:{s:9:"_previous";a:1:{s:3:"url";s:64:"http://xxxxxxx/xxxx/2018-03-27 18:55:39key=val";}}}, ?))

理由

replaceArrayで?をbindingsの値に置き換えてるからこうなる。

vendor/laravel/framework/src/Illuminate/Database/QueryException.php

    /**
     * Format the SQL error message.
     *
     * @param  string  $sql
     * @param  array  $bindings
     * @param  \Exception $previous
     * @return string
     */
    protected function formatMessage($sql, $bindings, $previous)
    {
        return $previous->getMessage().' (SQL: '.Str::replaceArray('?', $bindings, $sql).')';
    }

解決方法

対応するかは別として対応はQueryExceptionをバグ修正したものに差し替えるくらいかなぁ。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0