CYQ. Data V5 Text Database supports SQL statement operations (Implementation Principles) over the weekend, use a text database to play with Code FirstCYQ. Data V5 Text Database Technical Principles for decryption

Source: Internet
Author: User
CYQ. Data V5 text database, which was previously introduced: Play Code First with a text database over the weekend

The principle of Data storage is based on json or xml format. It also introduces the technical principle of CYQ. Data V5 Text Database decryption.

After implementing basic functions a few days ago, I also wrote the idea of conflicting SQL statements: CYQ. Data Text Database parsing SQL syntax.

 

The principle of Text Database: Simply put, there are four steps:

1: json or xml is used for storage.
2: The data is restored to MDataTable during reading.
3: The MDataTable operation changes the data rows.
4: Save the data as json or xml.

 

PS: Of course, there is also a CodeFirst mode that automatically generates the "table name. ts" file used to record the table structure.

Split the Where statement of a text database:

The original function is Select (where), which supports SQL statements. Simply put, the where statement is analyzed as follows:
String where = "id> 1 and name like '% a %' order by id desc ";
Analyze the where, order by, and then analyze the id, name, and corresponding value, and judge the value cyclically to extract the appropriate rows.
To achieve the query function.

To support SQL now, it seems that the complexity is improved, because the simple SQL statements are roughly as follows:

Insert into ErrorLogs (PageUrl, ErrorMessage) values ('HTTP: //... ', 'who' is ...')
Select count (*) from ErrorLogs...
Select * from ErrorLogs where...
Select id, name from ErrorLogs...
Update ErrorLogs set id = 1 and name = 'name is mr' 'right'
Delete From ErrorLogs where...

 

The basic skills for processing these strings are really good:

For example, Insert into ErrorLogs (PageUrl, ErrorMessage) values ('HTTP: //... ', 'who' is (the (name ))...')
Split this statement:
1: Operation: Insert
2: Table Name: ErrorLogs
3: PageUrl: "http ://..."
4: ErrorMessage: "'who' is (the (name ))..."

 

PS: I think I can take it as an interview question ....

The overall implementation is basically equivalent to parsing the preceding SQL syntax and then returning to the original OPERATION OF THE MDataTable. The details will not be repeated.

 

Next, let's take a look at the implementation:

 

The project is omitted. The page background code:

Protected void btnExec_Click (object sender, EventArgs e)
{
If (! String. IsNullOrEmpty (txtSql. Text ))
{
MProc proc = new MProc (txtSql. Text, txtConn. Text );
Switch (ddlExeType. SelectedValue)
{
Case "0 ":
LabTip. Text = proc. ExeScalar <string> ();
Break;
Case "1 ":
LabTip. Text = proc. ExeNonQuery (). ToString ();
Break;
Case "2 ":
MDataTable dt = proc. ExeMDataTable ();
RptList. DataSource = dt;
RptList. DataBind ();
Break;
}
Proc. Close ();
}
}

 

The code above is very simple. Execute the SQL statement for the specified link and then display the corresponding information.

 

To operate on a database, it is essential to specify the log link string in the basic configuration file:

<Add name = "LogConn" connectionString = "txt path = {0} App_Data"/>

 

Note: The system error log is recorded in the file database, and CYQ. Data V5 uses the CodeFirst method to implement the exception of the database execution log error:

Table Name: ErrorLogs
The four fields are:
1: ID, PageUrl, ErrorMessage, CreateTime.

 

Next let's look at the interface: Because my project contains logs, let's look at it:

 

OK. Next we will delete all the databases. Five rows of data are deleted after the execution is successful:

Add another row of data:

The last line of data is updated:

 

The query is displayed again:

 

 

So far, the basic SQL Syntax Parsing and implementation have ended. For GroupBy, multi-table, view, function, and so on, it is beyond the capability of the text database.

You can use two tables For or while to implement the logic you need.

 

The following describes the ErrogLogs log:

The default CodeFirst is the database type you specify. The corresponding table structure is automatically created and the error message about SQL Execution is written into the log for query, analysis, and resolution.
In the past, I used to write the log link:
<Add name = "LogConn" connectionString = "Conn"/>
In fact, it is directed to Conn (the default master database configuration of CYQ. Data), so that the log table is placed in the same database as the master database table ..
As a result, if the primary database crashes, the exception logs cannot be recorded. Therefore, we recommend that you store the logs in other databases.
However, with the file database, it seems a good choice to store logs using text, and the operation is quite convenient.

CodeFirst, if there is data (when the first data is generated, the table structure is automatically generated based on the object. If it is text, it is generated under the specified directory)

 

Of course, except for the standard ones, they are automatically generated. If you create a table manually, you can create a table name. ts table structure with the following content:

 

ID, int;
PageUrl, string;
ErrorMessage, string;
CreateTime, datetime;

 

 

Text Database in CYQ. Data V5, practical value:

 

Including the display of advertisement nodes on the website, links, Key and Value that need to be edited frequently or occasionally, it is most convenient to store a text database.
It effectively stores non-master station additional data to the text database and uses the full memory table mechanism of text data, which is efficient, energy-saving, and convenient.

 

 

CYQ. Data V5 can be used directly without authorization in text databases, Access, SQLite, and XHtmlAction.

:Http://www.cyqdata.com/download/article-detail-426

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.