从 Crystal Report .rpt 文件中提取原始 SQL 查询
我有一个不是我编写的 .rpt 文件,也找不到相关文档。我希望能够查看从此报告生成的 SQL,以便我可以弄清楚它正在提取哪些数据以及使用了哪些 WHERE 子句参数。
我可以打开它并查看报告布局。但是,当我选择数据库|显示 SQL 查询...时,报表会尝试连接到数据源。问题是,我不知道所使用的数据源,可能是编写查询的人使用的 ODBC 连接。在该阶段我所能做的就是“取消”,然后我会返回查看报表设计器。
我错过了什么吗?我可以在不连接数据源的情况下进行 SQL 查询吗?看来查看选择标准不应该依赖于数据连接。
谢谢。
版本:水晶报表 2008
I've got an .rpt file that I did not write and can find no documentation about. I want to be able to review the SQL that is generated from this report so that I can figure out, well, what data it was pulling and what WHERE clause parameters were used.
I can open it up and see the report layout. But when I select Database|Show SQL Query... the report tries to connect to the data source. The problem is, the data source being used is unknown to me, probably an ODBC connection used by whoever wrote the query. All I can do at that stage is 'Cancel' and I'm back to looking at the report designer.
Am I missing something? Can I get to the SQL query without connecting to the datasource? It seems like viewing the selection criteria shouldn't be dependent on a data connection.
Thanks.
version: Crystal Reports 2008
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是一个旧线程,但我遇到了同样的问题。实际上,我们曾经拥有一个数据库/应用程序,后来被外部机构收购。
尽管他们现在拥有数据库/应用程序,但他们无法访问水晶报告,因此我们不能只向他们发送我们过去运行的旧报告。同样,我们无法运行它,因为我们甚至没有在任何地方设置数据库......因此,我们的计划只是提取报告生成的 SQL 代码并将其转发。
我们遇到了同样的问题,但解决方案实际上非常简单。
如果您无权访问原始数据源,只需创建一个新的“空白”数据源(例如 ODBC 连接)。只要与数据源的连接有效(即它是某种有效的数据源,它就可以正常工作)。运行“显示 SQL”选项时,将报表指向此数据源。只要您不尝试实际运行报告(并且仅显示 SQL),操作就不会失败。无论如何,这对我们的情况有用。 (Crystal Reports 2008)
(如果有任何帮助,我可以提供更多详细信息。)
I know that this is an old thread, but I encountered this same problem. Effectively we used to have a database/application that has since been aquired by an external agency.
Although they now have the database/application they don't have access to crystal reports, so we can't just send them the old report that we used to run. Likewise we can't run it as we don't even have the database set up anywhere.... So instead our plan was just to extract the SQL code generated by the report and forward that on.
We experienced the same problem, but the solution is actually pretty simple.
If you don't have access to the original data source, just create a new 'blank' datasource (such as an ODBC connection). As long as the connection to the datasource works (i.e. it is some kind of valid datasource this it works fine). When running the 'Show SQL' option point the report to this datasource. As long as you don't try to actually run the report (and only show the SQL) the operation wont fail. This worked for our situation anyway. (Crystal Reports 2008)
(I can give more details if it helps in any way.)
如果没有密码,我不确定你能做什么。看来“显示SQL查询”需要先报告运行,然后生成SQL计划。
这并不理想,但您可以转到“数据库”>“ Visual Linking Expert 至少可以查看表及其连接方式,然后转到记录选择公式编辑器并查看自定义 WHERE 语句是什么。
Without the password, I'm not sure how much you can do. It seems "Show SQL Query" requires to report to run first, then generate the SQL plan.
It's not ideal, but you could go to Database > Visual Linking Expert to at least see the tables and how they are joined, and the go to the Record Selection Formula Editor and see what the custom WHERE statements are.
通过选择“数据库”>“现有数据源”应该可以找到有关现有数据源的一些详细信息。设置数据源位置...
除了使您能够更改数据源位置之外,这还应该显示有关当前数据源的一些信息,例如正在使用哪种类型的数据源,以及可能的数据库名称(取决于驱动程序的类型)。如果(正如您猜测的那样)数据源是 ODBC,它可能不太有用,但如果它使用本机驱动程序,则可能会有一些有用的东西。
It should be possible to find out some details about the existing datasource, by selecting Database > Set Datasource Location... .
As well as enabling you to change the datasource location, this should show you some information about the current datasource, such as which type of datasource is being used, and possibly (dependant on the type of driver) the name of the database. It is likely to be less helpful if (as you surmise) the datasource is ODBC, but if it uses a native driver there may be something useful.
查看 Crystal 报表文件中命令的 SQL
有时您只有报表文件,但没有报表使用的关联数据库结构。
在处理您想要模仿的功能的示例报告时,这种情况很常见。
这是一种解决方法,仅允许您在没有报表所基于的基础数据库连接时查看 Crystal Report 所基于的命令的 SQL。
从本质上讲,必须先满足该对话框的要求,然后才能显示 SQL,因此我们使用合法的数据源来愚弄它,而不是使用 SQL 命令中实际使用的 SQL 的数据源。
为什么报告要使用命令? Crystal Reports没有链接表的功能吗?
当 Crystal Report 基于的记录集对于 Crystal Reports 中的表链接功能而言过于复杂时,该报表可以基于 SQL 查询,通常在另一个编辑器工具中开发/测试并粘贴到命令中。这允许使用高级 SQL 函数。
如果您的计算机上尚未设置可连接的数据源,则需要先构建一个。
保存在简单位置的简单 Microsoft Access .mdb 文件就足够了。
我将我的放置在路径 C:\A_test\test.mdb 中,以便于查找。
如果您没有,请在 google 上搜索示例 mdb 文件并下载它,并使用您可以记住的名称和位置保存它。 (您实际上不会打开此文件,而只是连接到它。)
保存文件后,打开 ODBC 管理器并创建新数据源。
(您可以通过“开始”>“在搜索中键入 ODBC”快速访问 ODBC 管理器)
在“用户 DSN”选项卡上,单击“添加”按钮。
将驱动程序列表向下滚动到 Microsoft Access Driver (*.mdb),选择它并单击“完成”按钮。
在“数据源名称”框中,键入名称(我使用的是 MyTest)。
单击“选择”按钮并选择您在上一步中保存的 mdb 文件,然后单击“确定”。
再次单击“确定”。您将看到按您指定的名称列出的新数据源。单击“确定”。
您现在拥有后续步骤所需的数据源。
Viewing the SQL of a Command in a Crystal Report File
There are times you have just the report file, but not the associated database structure that the report uses.
This is common when dealing with example reports of functionality you wish to mimic.
This is a workaround ONLY to allow you to see the SQL of a Command that a Crystal Report is based on, when you don't have the underlying database connection that the report is based on.
In essence, the dialog box has to be satisfied before it will show the SQL, so we fool it with a legitimate Data Source, just not one that would work with the SQL that is actually in the SQL Command.
Why does a report use a command? Doesn't Crystal Reports have the ability to link tables?
When a Crystal Report is based on a record set that is too complex for the table linking functionality within Crystal Reports, the report can instead be based on a SQL Query, usually developed/tested in another editor tool and pasted into the command. This allows advanced SQL functions to be utilized.
If you don't already have a Data Source on your computer set up that you can connect to, you will need to build one first.
A simple Microsoft Access .mdb file saved in a simple location will suffice.
I placed mine with the path C:\A_test\test.mdb to make it easy to find.
If you don't have one, google for a sample mdb file and download it, saving it with a name and location you can remember. (You won't ever actually open this file, but just connect to it.)
Once you have the file saved, open the ODBC Administrator and create a New Data Source.
(you can get to the ODBC Administrator quickly from Start > type ODBC in the Search)
On the User DSN tab, click the Add button.
Scroll down the driver list to Microsoft Access Driver (*.mdb), select it and click the Finish button.
In the Data Source Name box, type a name (I used MyTest).
Click the Select Button and select the mdb file you saved from a previous step, click OK.
Click OK again. You will see your new Data Source listed by the name you gave it. Click OK.
You now have the data source you will need for the next steps.
发生的情况是,水晶报表需要连接到一个数据库,无论它是否是原始源数据库。
创建本地数据库或使用存储在服务器上的数据库,将其添加到 ODBC 数据源并在连接时使用它。成功连接后,您应该能够查看 SQL 查询而不会出现错误。
Whats happening is that the crystal reports needs a database to connect to regardless if its the original source DB or not.
Create a local database or use a database stored on a server, added it to your ODBC Datasources and use it when connecting. After a successful connection you should be able to view the SQL query without an error.