如何使DBI记录包括参数的所有查询? [英] How can I make DBI log all queries including params?

查看:84
本文介绍了如何使DBI记录包括参数的所有查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清旧版应用程序对我们的mysql数据库(复数)有什么影响,因为我需要完全重构/替换其中的一部分,而无需关心它的工作方式。我只是对结果感兴趣。

I am trying to figure out what a legacy app does to our mysql databases (plural) as I need to refactor/replace a part of it completely without caring how it does it. I'm just interested in the result.

当前,我正在使用 DBI :: Profile DBI :: ProfileDumper 通过添加 $ ENV {DBI_PROFILE} =!Statement / DBI :: ProfileDumper; 。在命令行上运行 dbiprof dbi.prof 时,这显示了很多查询,但这似乎有些奇怪。

Currently I am working with DBI::Profile and DBI::ProfileDumper by adding $ENV{DBI_PROFILE} = "!Statement/DBI::ProfileDumper";. That shows me a bunch of queries when running dbiprof dbi.prof on the commandline, but it seems a little odd.

可能是我读错了报告。

Might be I am reading the report wrong.

#####[ 3 ]###########################################################
  Count         : 4
  Total Time    : 0.018930 seconds
  Longest Time  : 0.018881 seconds
  Shortest Time : 0.000005 seconds
  Average Time  : 0.004732 seconds
  Key 1         :

INSERT INTO orders (foo, bar) VALUES (1, 2)

为什么显示 4 作为计数?它正在 orders 表中创建两行,而不是4。此外,它还显示了它正在执行的第一个插入的值。对于其他一些人,它会将保留在查询字符串中。

Why is it showing 4 as Count? It is creating two rows in the orders table, not 4. Also, it is showing the values of the first insert it is doing. For some others, it keeps the ? in the query string.

也许分析是错误的方法。我一直在考虑用猴子补丁DBI来记录查询,但是我不确定该去哪里。可能我可以在 prepare 中添加日志记录功能,并在 execute 中添加获取查询字符串以及参数

Maybe profiling is the wrong approach. I've been thinking about monkey-patching DBI to log the query, but I am not sure where to go with that. Might be I could add a logging function to prepare, and to execute to get the query strings as well as the parameters.

是否已经可以使用类似的东西了?当然有人要这样做吗?或者是另一种方法?

Is there something similar already that I can use? Surely someone wanted to do this? Or maybe another approach?

我愿意接受任何建议。

推荐答案

您要在级别2上使用跟踪:
https://metacpan.org / pod / DBI#TRACING

You want to use tracing at level 2: https://metacpan.org/pod/DBI#TRACING

这篇关于如何使DBI记录包括参数的所有查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆