So that MySoft. Data can also have Discuz! NT database query and analysis tool, mysoft. datadiscuz

Source: Internet
Author: User

So that MySoft. Data can also have Discuz! NT database query and analysis tool, mysoft. datadiscuz

Run Discuz in Debug mode! During the NT project, we will find a Data Query and analysis tool at the bottom of the page, which is very convenient. When running a page, you can view SQL operations at a glance. Of course, some of them still cannot be displayed on the page. For example, when multiple jumps are made, only one page of SQL is displayed. However, it is quite convenient.

This database query and analysis tool is only displayed in Debug mode and not in Release mode.

This method has two advantages: one is convenient debugging, and the other is that each time a site is released, it must be in the Release mode, this ensures the running efficiency of the website (I often Debug the website ).

Disucuz! The Analysis on the page shows how NT works. The debugging information is directly added before </body>.

 

This information is obtained by using CommandText directly in the DbHelper Data Access to obtain the SQL statements and DbParameter to obtain the parameters. When SQL is executed, the QueryDetail class in the DbHelper class is used to assemble html, which is eventually like this. Here, I will give you a simple explanation. If you are interested, you can directly look at Discuz! The pagebase class and dbhelper class of the NT project are all implemented here.

The most important thing is how to use such a good function in the MySoft. Data framework, Discuz! NT displays the page through the template every time HTML is output. Therefore, the SQL statements obtained in the Data Access phase can be directly embedded. However, the output of common pages cannot follow these steps.

After testing, only the HTML that is to be output is obtained in the httpmodule class whenever the HTML analyzed by these databases is obtained and then embedded. If this is not embedded in the original html, it is directly added to the end of the page, which may cause JS errors and css misplacement on the page. Therefore, you must add the html to the front of the </body> tag.

The principle is as follows. For details, refer to the code below:

First, modify the code in the DbHelper class of MySoft. Data: DbHelper. cs

+ View Code

In this class, the DEBUG statement is added to run the Code only during debugging and is not displayed during Relese, this is the purpose of the above description that only the Relese version does not display debugging information.

Specifically, the GetQueryDetail class directly returns HTML information. If SQL is passed in, it will return.

The specific implementation of GetQueryDetail is in the DbQueryDetailHelper class: DbQueryDetailHelper. cs

+ View Code

 

After HTML is obtained, the operation is put in the DbQueryDetailHttpModule class. This is an IHttpModule class to get the HTML output on the final page, embed the debugging SQL information into DbQueryDetailHttpModule. cs

 

+ View Code

 

Let's not talk about it here. Let's look at the Code directly. The principle is also a replacement (I 've been searching for it online for a long time and finally found that this can be written, so I can use it directly, thanks ).

After everything is done, re-compile the MoSoft. Data class library and 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. Finally, let's take a look at our output page:

 

These displays are exactly the same as the original ones. Therefore, I have successfully transplanted this function. Haha

It should be noted that this function can only be used for Web development without the development of desktop applications.

Therefore, another modification is to directly input SQL information to the file, and every access is recorded in the log file, so that it can be used for desktop application development, the specific implementation is also in the DbQueryDetailHelper class (see the previous class ).

Input Format

So far, the entire implementation process is like this. In fact, the implementation method here can be applied to other ORM systems.

Finally, separate files and converted MySoft. Data are attached.

Separate file: xxx

Replace MySoft. Data: 1. Replace MySoft. Data \ Session \ DbHelper. cs 2. Add the DbQueryDetail folder content in MySoft. Data \ Common.

Converted MySoft. Data File (2.7.5): xxx

Usage: Introduce the class library in the Web. add HttpModules section in Config: <add name = "DbQueryDetailHttpModule" type = "MySoft. data. dbQueryDetailHttpModule, MySoft. data "/>. Be sure to add it to the end.

Genuine MySoft. Data address: xxx

Complete example project: xxx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.