When we run discuz! in debug mode NT Project, we will find at the bottom of the page there is a data query analysis tool, very convenient. When we run a page, the operation of SQL can be at a glance. Of course, some can not be displayed on the page, such as multiple jumps, the final display is only one page of SQL. But it's also very convenient.
This database query analysis tool is only displayed in debug mode and the release mode is not displayed.
This approach has two advantages, one is convenient debugging, the second is whenever the release site, it must be the release mode, you can ensure that the site in the operational efficiency of the guarantee (many times I was debug, embarrassed).
In the end disucuz! NT is how to do, from the page analysis can know, is directly in the front of </body> add these debugging information up
This information, in the data access DBHelper directly through the CommandText get Sql,dbparameter get parameters. When SQL is executed, the HTML is assembled by dbhelper the Querydetail class inside the class, which eventually becomes the same. Here I simply say, do not do a detailed analysis, interested students can directly see discuz! The Pagebase and DBHelper classes of NT projects are all implemented here.
The key is, how to move to the mysoft.data frame with such a good function, discuz! NT every time the HTML output is through the template page display, so, in the data access stage to get SQL directly embedded in it. However, our normal page output cannot follow this approach.
After testing, only to get the HTML of these database analysis in the HttpModule class to get the output of the page will be exported HTML and then embedded in, if not embedded in the original HTML, but directly to the end of the page, will lead to the page JS error, CSS dislocation and so on. Therefore, the HTML must be added to the front of the </body> tag.
The principle is this, specifically see the following code to achieve it:
First, the code is modified in Mysoft.data's DBHelper class: DbHelper.cs
+ View Code
In this class, add the debug statement, the purpose is to run the code when debugging, Relese will not show, this is the only version of the Relese does not display the purpose of debugging information.
Where getquerydetail this class returns HTML information directly, the SQL is passed in and returned.
The specific implementation of Getquerydetail is in the Dbquerydetailhelper class: DbQueryDetailHelper.cs
+ View Code
After getting the HTML is the output, then this operation I put in the Dbquerydetailhttpmodule class, this is a IHttpModule class, the purpose is to get the final page output of the HTML, the debug SQL information embedded in it: D BQueryDetailHttpModule.cs
+ View Code
Here is not much to say, directly look at the code, the principle is also replaced (here I looked for a long time on the internet, finally found that this can be, directly used, embarrassed).
After everything is done, recompile the Mosoft.data class library, and finally add the HttpModule configuration section in the Web. config file:
<add name= "Dbquerydetailhttpmodule" type= "Mysoft.data.dbquerydetailhttpmodule,mysoft.data"/>
In this way, the entire function can be fully implemented, and finally look at our output page:
The display is exactly the same as the original, so I succeeded in porting the feature. Ha ha
It is important to note that this feature is only suitable for web development and does not use desktop application development.
So, I re-modify, is to directly input SQL information into the file, each access is recorded in the log file, so that it can be used for desktop application development, the implementation is also in the Dbquerydetailhelper class (see the preceding Class).
Format of input
So far, this is the whole implementation process. In fact, the implementation of the method can be applied to other ORM, to see the personal love.
Finally, a separate document and a modified mysoft.data are attached.
Separate file: XXX
Replacement method for Mysoft.data: 1, replace Mysoft.data\data\session\dbhelper.cs 2, add Dbquerydetail folder contents in Mysoft.data\common
Modified Mysoft.data file (2.7.5): XXX
How to: Introduce a class library, add httpmodules section in Web. config: <add name= "Dbquerydetailhttpmodule" type= " Mysoft.data.dbquerydetailhttpmodule,mysoft.data "/>, note be sure to add to the last face.
The Mysoft.data address of genuine is: XXX
Complete sample project: XXX
So that Mysoft.data can have discuz!. NT database query and Analysis tool