Interesting Problem regarding Parameters

C

Carlo Razzeto

Backgroud:
My company is currently migrating to .Net from PHP for a number of reasons,
however we have one slight problem we would very much like to solve before
moving to .Net (ok, many but this one is a toughie).

Problem:
On our current PHP platform we have our own database abstraction class which
inherits from the PEAR DB abstraction class. One of the major reasons why we
did this is because we wanted to add automatic querie logging to our
database connection object. Here is a brief snippit of code to demonstarte
the functionality we currently have:

//Creating DB connection objects
$connection = mis_DB::connect( 'database-server', 'database' );
$connection->addLog( 'file', '/log_path/filename.log', PEAR_LOG_MODE );
$connection->setLogMask( MISDB_LOG_ALL );

This will automatically log any queries thrown at at, for example (I'm using
prepare and execute syntax for a reason that will be come clear in just a
minute):

/* Disclaimer, such a DB does not exist on my company DB server, but it
should! */
$query = "SELECT * FROM beer.beer_styles WHERE style = ?";
$handle = $connection->prepare( $query );
$result_object = $connection->execute( $handle, array( "Imperial Stout" ) );

What our current database class will do (after executing the query) is logg
the following message to the /log_path/filename.log file:
Friday, July 29, 2005 8:41:10 AM [Informational] SELECT * FROM
beer.beer_styles WHERE style = 'Imerial Stout'

What we would like is to have some thing similar with our new .Net DB class,
however the problem I'm running into is I don't know how to get the query
that was actually executed on the server, what I mean by that is:

//Assume I have a proper connection string
OleDbConnection Connection = new OleDbConnection( ConnectionString );
OleDbCommand Command = new OleDbCommand( "", Connection );
Connection.Open();

//Set the query with parmater then execute reader
Command.CommandText = "SELECT * FROM beer.beer_styles WHERE style = @style";
Command.Paramaters.Add( "@style", "Imperial Stout" );
OleDbDataReader Reader = Command.ExecuteReader();

How do I get the query that actually executed on our DB server, i.e. "SELECT
* FROM beer.beer_styles WHERE style = 'Imperial Stout'", not "SELECT * FROM
beer.beer_styles WHERE style = @style".

Thanks for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top