简体   繁体   English

如何从Oracle occi C ++ api中记录原始SQL?

[英]How to log the raw SQL from Oracle occi C++ api?

One of our customers is complaining our application is not working. 我们的一位客户抱怨我们的申请无效。 Their reasoning is that our sql function call to their Oracle database is not getting the "expected" result. 他们的理由是我们的sql函数调用他们的Oracle数据库没有得到“预期”的结果。 Sometime, it should failed but our application get success from their database. 有时,它应该失败,但我们的应用程序从他们的数据库获得成功。 It's really frustrating because it's their database and we cannot do any test on it. 这真是令人沮丧,因为它是他们的数据库,我们无法对其进行任何测试。

We are using the C++ Oracle OCCI API. 我们正在使用C ++ Oracle OCCI API。 Is there anyway we can log the raw sql from our end? 反正我们可以从我们的结尾记录原始sql吗? That will be very helpful and we can ship the script to them and let them debug in their system to figure out the problem. 这将非常有用,我们可以将脚本发送给他们,让他们在他们的系统中调试以找出问题。

Thanks in advance. 提前致谢。

I assume that you are issuing just a SQL statement, since you say that you want to see the 'raw SQL from your end'. 我假设您只发出一个SQL语句,因为您说您希望看到“来自您的原始SQL”。 The best thing, then, is to get the database trace, as has been suggested. 那么,最好的办法是按照建议获取数据库跟踪。

What I want to point out is that even if your SQL returns the expected result in a test database, the same SQL may return an unexpected result in another database because the data may be different: the data may be corrupted, indexes may exist or may not exist, constraints may be defined or not, etc. Definitely, you need to get the trace from the database to be able to move forward. 我想指出的是,即使您的SQL在测试数据库中返回预期结果,同一SQL也可能在另一个数据库中返回意外结果,因为数据可能不同:数据可能已损坏,索引可能存在或可能不存在,可以定义或不定义约束等。当然,您需要从数据库中获取跟踪才能继续前进。

Ideally you would turn on a trace at the database level which would generate a trace file containing all activity the database performed. 理想情况下,您将在数据库级别启用跟踪,该跟踪将生成包含数据库执行的所有活动的跟踪文件。

Other alternatives would be to alter you application to log all SQL that it was about to execute against the database. 其他替代方法是更改​​您的应用程序以记录它将要针对数据库执行的所有SQL。

This post also goes into some other options (they approach it from trying to detect whether SQL injection is happening) to sniff the database activity: 这篇文章还介绍了其他一些选项(它们试图检测SQL注入是否正在发生)来嗅探数据库活动:

http://www.symantec.com/connect/articles/detecting-sql-injection-oracle http://www.symantec.com/connect/articles/detecting-sql-injection-oracle

Though it must be setup on the database, a trace will give you the truest results. 虽然必须在数据库上进行设置,但跟踪将为您提供最真实的结果。 Oracle Fine Grained Auditing is something else to look into if you are on Oracle 9i or higher. 如果您使用的是Oracle 9i或更高版本,Oracle Oracle Fine Grained Auditing是另一个需要考虑的问题。

Depending on the architecture the statements sent across the network do not necessarily mirror the SQLs executed. 根据体系结构,通过网络发送的语句不一定镜像执行的SQL。 The obvious example is calling a stored procedure, where the network simply has the call, but the database actions all the underlying SQL of the procedure. 显而易见的示例是调用存储过程,其中网络只是调用,但数据库操作过程的所有基础SQL。 However triggers, fine-grained access control, views etc can all have similar impacts. 但是,触发器,细粒度访问控制,视图等都可能具有类似的影响。

For the network transfer, you can look at SQL net traces 对于网络传输,您可以查看SQL网络跟踪

For the database side, look at DBMS_MONITOR 对于数据库端,请查看DBMS_MONITOR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM