CYQ. Data V5 Text Database supports SQL statement operations (Implementation Principles)

Source: Internet
Author: User

CYQ. the text database of Data V5 has previously been introduced in this article: on weekends, we used a text database to play with the storage of Code First Data, which is implemented based on the json or xml format, there is also an introduction: CYQ. after achieving basic functions a few days ago, the technical principles of Data V5 text database were decrypted, I also wrote the idea of conflicting SQL statements: CYQ. SQL syntax for Data Text Database ParsingThe 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 above code 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:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/16211415R-0.jpg "alt =" "/>OK. Next we will delete all the databases. Five rows of data are deleted after the execution is successful:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1621145R3-1.jpg "alt =" "/>Add another row of data:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1621141436-2.jpg "alt =" "/>The last line of data is updated:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/16211434W-3.jpg "alt =" "style =" line-height: 1.5; "/>The query is displayed again:650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/16211453V-4.jpg "alt =" "style =" line-height: 1.5; "/>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"/>
It actually points to the top of the default master database configuration of ConnCYQ. 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 the first data is generated, the table structure is automatically generated based on the object. If it is text, it is generated in the specified directory) 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/162114G17-5.jpg "alt =" "style =" line-height: 1.5; "/> Of course, in addition to the standard, it is automatically generated, if you create a table manually, you can create a new table name. ts table structure, 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

This article from the "passing by autumn" blog, please be sure to keep this source http://cyq1162.blog.51cto.com/2127378/1191805

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.