Friday, 27 January 2012

Using NHibernate to format your SQL

Just did this in the immediate window from break point set in Abstract Batcher, GetSQL method in the NHibernate source code

image

sql.ToString()

"exec [dbo].[GetProjectComments] ?"

SqlClientDriver driver= new SqlClientDriver();

SqlStringFormatter formatter = new SqlStringFormatter(driver);

sql.Visit(formatter)

Expression has been evaluated and has no value

formatter.GetFormattedText()

"exec [dbo].[GetProjectComments] @p0"

Thinking of using this to write a custom little app on the side to make all my SQL look nice again. I know SQL Prompt already does this nicely, but don't have a license for that right now, so this is a nice free alternative I guess.

No comments:

Post a Comment

Android mediaserver process killing battery life

If this happens to you, then do the following Force stop on Settings, Applications, All, Media Storage. Clear Cache and Clear Data, fo...