Application of SQL statement in JavaScript to realize _javascript skill

Source: Internet
Author: User
Tags sqlite javascript array
Like the sort of JavaScript array
There are also the deletion and grouping of the data in the array.

So, later in the interest to come up.
Out of hand.

Write a SQL library that can be applied in JavaScript
Later thought, how can not use JavaScript directly to connect the database?
A class library of JavaScript Direct-attached SQL data

Later, I thought that I could actually manipulate the HTML DOM model with SQL statements.

And then again, I saw the implementation of Web DB in HTML5
So for WebDB, that's the encapsulation of SQLite in Chrome and Safari.

And there it was:

1. Get data from the server, perform SQL operations:

Copy Code code as follows:

_sqlproxyurl_ = ' sqlproxy.php ';
_sqlserverhost_ = ' localhost ';
_sqlusername_ = ' root ';
_sqlpassword_ = ';
_sqldatabase_ = ' hotelmanagement ';



var result = ' select * from Room '. Onserver (). ExecuteSQL ();
for (var i=0; i<result.length; i++) {
Do something ... using result[i];
}


2. Manipulate JavaScript Object Array, execute SQL Operation:

Copy Code code as follows:


var Room = [
{
ID: ' bot ',
Name: ' Test ',
Sex:true
}, {
Id:2,
Name: ' Test8 ',
Sex:true
}, {
Id:3,
Name: ' Test5 ',
Sex:false
}, {
Id:4,
Name: ' Test2 ',
Sex:true
}];


SQL = "Select Max" (ID) as bid,sum (ID) as total from records where name like \ test%\ GROUP BY sex ORDER by ID Desc,name as C ";
var result = Sql.executesql ();
for (var i=0; i<result.length; i++) {
Do something ... using result[i];
};
"CREATE TABLE MyTable". ExecuteSQL ();
for (Var j=0 j<100; J + +) {
"INSERT INTO MyTable (Id,name,sex) VALUES (2, ' Zhangsan ', True)". ExecuteSQL ();
};


The SQL statements are all written out. Is it safe?

On the security issue first of all this does not intend to do Internet applications, oriented to the LAN. Second, the connection of the database has SSL encryption, in fact, HTTP also has SSL, moreover. The remote invocation service is only one of the four modules of Jsql. There is also the DOM that can operate client objects array without service, browser SQLite and Web page. My SQL here only represents a language specification, suitable but not limited to the back-end SQL database, and three modules are facing the previous segment of the operation

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.