in reply to getting the sql of a parameterised query

Until I read the answer from roboticus I didn't even think you might have thought a driver replaced the placeholders with your parameters in the SQL string. The purpose of preparing a statement with parameters is that the database can parse the SQL once, may be compile it, build an execution plan, optimise it, cache it etc as in most cases the parameters won't affect this. Drivers generally pass the SQL string including placeholders to the database engine then pass the parameters separately afterwards. So long as you are using prepare/execute (and not do) you can access the SQL you passed to prepare with the Statement attribute and the parameters via the ParamValues, ParamTypes and ParamArrays.

  • Comment on Re: getting the sql of a parameterised query