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

[10.x] Add getRawQueryLog() method #47623

Merged
merged 8 commits into from
Jul 4, 2023

Conversation

fuwasegu
Copy link
Contributor

@fuwasegu fuwasegu commented Jun 30, 2023

⚠ NOTICE: A failed test is not about my changes

In #47507 , toRawSql() was implemented that can retrieve the complete query with values bound to the SQL output by toSql().

I thought it would be nice to have an extension method that could retrieve the complete query with bound values, similarly with DB:::getQueryLog()

I implemented it.

Usage

Basically, the usage is the same as getQueryLog()

DB::enableQueryLog();

// do something with querying

$logs = DB::getRawQueryLog();

In the case of getQueryLog(), we could get an associative array like this

[
  [
    "query" => "select * from "users" where "id" in (?, ?, ?)"
    "bindings" => [
      0 => 3
      1 => 6
      2 => 8
    ]
    "time" => 4.06
  ]
]

Now, we could get an associative array like this with getRawQueryLog()

[
  [
    "raw_query" => "select * from "users" where "id" in (3, 6, 8)"
    "time" => 4.06
  ]
]

@driesvints driesvints changed the title 【10.x】Add getRawQueryLog() method [10.x] Add getRawQueryLog() method Jul 3, 2023
@huangdijia
Copy link
Contributor

Will there be leakage of sensitive information?

@fuwasegu
Copy link
Contributor Author

fuwasegu commented Jul 4, 2023

@huangdijia
Thank you for your comment!

Certainly, there are concerns about leaking of sensitive information because this feature make it possible to dump full sql query logs which is bound all properties.
Perhaps, the one of the reasons why anyone didn't implement a function like toRawSql() is protecting from leaking of sensitive informatioins.
However, I think this project had decided to entrust developers to judge to use these features because toRawSql() was implemented and merged in the previous Pull Request.
Therefore, I think whether to output logs which contains sensitive informations should be based on developers judgement as well this feature.

@taylorotwell taylorotwell merged commit 80319cf into laravel:10.x Jul 4, 2023
@fuwasegu fuwasegu deleted the feat/get-raw-query-log branch July 10, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants