How to log the raw SQL from Oracle occi C++ api? - c++

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. 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. Is there anyway we can log the raw sql from our end? 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'. 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.

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.
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:
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.

Depending on the architecture the statements sent across the network do not necessarily mirror the SQLs executed. 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. However triggers, fine-grained access control, views etc can all have similar impacts.
For the network transfer, you can look at SQL net traces
For the database side, look at DBMS_MONITOR

Related

using sql without any server

I have a question regarding SQL. Is there any way to connect to a database without a server into sql (no localhost or anything). I want to use SQL for a resource management in c++. I found the API but I need to know if that's possible, so I can use it like that.
Try SQLite.
SQLite is a sql-like database system that saves the database state to a single file somewhere on the file system, as opposed to requiring a full server. It does not have the full performance optimisations in SQL terms of full servers such as Postgres or MySQL; however, it does not require the overhead of a server.
Theres many options, one I know of is SQL Server Compact
Here's a link to microsoft's API for accessing SQL Server Compact via C++

Can I make an unbuffered query in ColdFusion?

I'm in the process of porting a Java desktop application to a ColdFusion web app. This desktop app made queries with very large result sets (thousands of text records) that, while being all right on the database side, could take a lot of memory on the client side if they were buffered. For this reason, the app explicitly tells the database driver to not buffer results too much.
Now that I'm working on the ColdFusion port, I'm being hit by the buffering problem. The ColdFusion page times out during the <cfquery> call, and I'm fairly sure this is because it tries to buffer everything.
Can I make an unbuffered query in ColdFusion?
If pagination is not an option (i.e., you're writing out a report for example), then you'll have to get low level with the java, using setFetchSize(). See this answer. Note that the code in the answer uses the DataSourceService, which, with latest security patches from Adobe, is no longer available on CF8. You'll have to figure out how to get a connection via the adminapi or create a connection outside of coldfusion. Or you could transition your datasource to use JNDI, and then you can lookup the resource yourself without using CF api's.
I'm almost certain that ColdFusion does not provide such a mechanism. As a language, it was meant to abstract the developer away from things like that.
I'd suggest that you look into a few options:
Re-work your query to use pagination, and run it in a loop.
Use the timeout attribute on the <cfquery> to prevent timeouts from happening
Use the CreateObject() syntax to instantiate a JDBC database connection.
With the last option, what you'd actually do is access the underlying Java classes to do the querying and getting results. Take a look at this article for a quick look at the CreateObject() function.
You can also look at the Adobe Livedocs for the function, but they don't really seem helpful.
I haven't tried to use CreateObject() to do querying with the Java database access classes, but I imagine that you can probably get it to work.

Can you make a call to a C++ Application from MS SQL Server?

Is it possible to make a call/notification to a C++ application from Microsoft SQL Server?
To give a broader understanding of what I'm trying to achieve: our database is being updated with new information; Whenever a new piece of information is received, we'd like to push this to the C++ application so that its dashboard reflects up-to-date data for the user.
We know we can do this by having the C++ application polling the database but I see this as inefficient architecture and would like to have SQL push the information or a notification to C++.
Any light shed on this area is greatly appreciated!
----- 28th Jan 3:40pm ----
OK After some reading around on Service Broker External Activation it seems like the right technology to use; however it seems to technology that's introduced in SQL Server 2008; and unfortunately we're using SQL Server 2005. Are there any other suggestive technologies or architectural designs we could use?
You might want to look in to using the Service Broker and handling the events it queues. Here's MSDN: http://msdn.microsoft.com/en-us/sqlserver/cc511479.aspx
There is an alternative, you don't need the app to poll the database, you can create a trigger for the table which sends a message to your application whenever something changes. this would be the more straightforward (and safer) approach
Look at this
Try using xp_cmdshell. It's not something I'd do lightly, and I would definitely make sure you're NOT letting anything access the SQL box with sysadmin rights. Create a stored proc which can EXECUTE AS a sysadmin user, and run xp_cmdshell from there. You'll still need to enable it though...

is there any database transaction mechanism in MFC/C++?

I want to make sure that if any error occurs during the database processing phase, program will know it need to roll back the whole process.
any good ORM in MFC/C++ for doing this ?
The MFC _ConnectionPtr object has BeginTrans, CommitTrans and RollbackTrans methods.
http://msdn.microsoft.com/en-us/library/ms675942(VS.85).aspx
I wouldn't call it good though, you'd need to wrap it.
This has nothing to do with ORM. You want basic transaction functionality
If you're using MFC, then most likely you're working with your database either via CDatabase (ODBC), CDaoWorkspace/CDaoDatabase (DAO), or CDataConnection/CSession (OLE DB). If so, you should use CDatabase::Rollback, CDaoWorkspace::Rollback, or CSession::Abort, respectively.
If you're connecting to a transactional database, like SQL Server, Oracle, PostgreSQL, Firebird, some of MySQL's data engines, etc. then they will have an API for transactions. Similarly, some non-SQL databases also have transactional semantics and an associated API (like Berkeley DB). Since you don't mention what database you're using, I really don't know what else to say.
Debea Database Library is an ORM for C++ - http://debea.net/

Concurrency in RIA

This'll be my first question on this platform. I've done lots of development using Flex, WebORB and ASP.NET. We have solved Concurrency problems with messaging (Pessimistic Concurrency Control). This works pretty good but it also makes the whole application dependent of the messaging. No messaging, no concurrency control.
I know that ASP.NET has version control in DataSets, but how would you go and use that if you are working on a RIA. It seems hard to go and store each dataset in the session of the client... So, if the Client would like need all products, I would need to store the dataset in the session of the client. When the client would change something to a product and save the product, I could then update the dataset (stored in the session) and try to save it...
Seems a lot of work and a lot of memory that will be used (because those products will be kept in the memory of the client, so the dataset needs to be kept on the server side session).
I think the most easy way would be to provide all DTO's with a version number. If the client would try to save a DTO, I could compare the version number with the one in the database.
Lieven Cardoen
This is something I've done before - as the original data was coming from an SQL Server database we just used a rowversion typed column in each DTO to determine if it had changed while the user was working on it.
At this point you can either barf on the error or try and figure out a way to merge the changes, but at least you can tell that it's changed underneath you :)