是否可以将 TracQuery 转换为 Trac SQL 语句,反之亦然?

发布于 2024-10-07 22:42:34 字数 1055 浏览 3 评论 0原文

我创建了一些 TracReports,但尝试使用 SQL 来执行它们,但没有得到我期望的结果。这是我的 SQL 查询:

SELECT      p.value AS __color__,
            reporter AS __group__,
            id AS ticket, summary, resolution , component, 
            t.type AS type, priority, severity, time AS created,
            changetime AS modified,
            changetime AS __changetime, description AS _description,
            reporter AS _reporter
FROM        ticket t
LEFT JOIN   enum p ON p.name = t.priority AND p.type = 'priority'
WHERE       t.status = 'closed'
ORDER BY    changetime DESC, CAST(p.value AS integer), milestone, t.type, time

使用此查询,记者分组根本不起作用。每个记者都会收到几行。所以我尝试使用“自定义查询”功能来获取结果。这通过以下 TracQuery 产生了我的预期结果:

query:?status=closed
&group=reporter
&col=id
&col=summary
&col=resolution
&col=component
&col=type
&col=priority
&col=severity
&col=time
&col=changetime
&order=changetime
&desc=1

我的问题是:我可以将 TracQuery 转换为 SQL 语句吗?或者我可以看到在后端完成的 SQL 语句吗?我这样问是因为我希望能够转换某些列或使用其他 SQL 函数。

I've created some TracReports but trying to do them with SQL, I don't get the result I was expecting. This was my SQL query:

SELECT      p.value AS __color__,
            reporter AS __group__,
            id AS ticket, summary, resolution , component, 
            t.type AS type, priority, severity, time AS created,
            changetime AS modified,
            changetime AS __changetime, description AS _description,
            reporter AS _reporter
FROM        ticket t
LEFT JOIN   enum p ON p.name = t.priority AND p.type = 'priority'
WHERE       t.status = 'closed'
ORDER BY    changetime DESC, CAST(p.value AS integer), milestone, t.type, time

Using this query, the group by reporter doesn't worked at all. I get several rows per reporter. So I tried to get the result using the "Custom Query" function. That produced my expected result with the following TracQuery:

query:?status=closed
&group=reporter
&col=id
&col=summary
&col=resolution
&col=component
&col=type
&col=priority
&col=severity
&col=time
&col=changetime
&order=changetime
&desc=1

My question is: Can I convert TracQuery into the SQL statement or can I see the SQL statements that is done in the backend? I am asking because I want to be able to cast some of the columns or use other SQL functions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

征﹌骨岁月お 2024-10-14 22:42:34

将日志记录级别设置为 DEBUG,并在 trac.ini 中设置配置选项 [trac] debug_sql = true。这将记录对数据库执行的所有 SQL 语句,包括与您的查询相对应的语句。最困难的部分是在日志中找到正确的语句。

哦,完成后再次禁用该选项,因为所有日志记录都会大大减慢 Trac 的速度。

Set your logging level to DEBUG, and set the configuration option [trac] debug_sql = true in your trac.ini. This will log all SQL statements made on the database, including the one corresponding to your query. The most difficult part is finding the right statement in the log.

Oh, and disable the option again when you are finished, because all that logging slows down Trac considerably.

淡淡的优雅 2024-10-14 22:42:34

Trac 源代码在内部将查询转换为 SQL,因此您应该能够编辑源代码以将查询字符串打印到日志文件,然后再将其提交到数据库(我面前没有源代码,所以我可以不会立即告诉您确切的代码位置)。当您直接输入 SQL 时,您可能不会得到完全相同的结果,我不记得 Trac 是否通过 TracQuery 对 SQL 查询的结果进行任何额外的后处理。

它还可能有助于将 Trac 日志记录设置调整为“DEBUG”,并在执行这两个查询时查看日志中是否有任何有用的输出。

The Trac source code converts the query to SQL internally, so you should be able to edit the source to print the query string to the logfile before it submits it to the DB (I don't have the source in front of me so I can't tell you an exact code location offhand). You may not get the exact same result when you enter the SQL directly, I can't remember if Trac does any extra post-processing on the results of a SQL query over a TracQuery.

It may also help to adjust your Trac logging settings to 'DEBUG' and see if there is any useful output in the log when executing those two queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文