Home  >  Article  >  Web Front-end  >  Application implementation of SQL statements in JavaScript_javascript skills

Application implementation of SQL statements in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:28:191283browse

For example, sorting JavaScript arrays
and deleting and grouping array data

So, I became more interested later.
Out of control.

I wrote a SQL library that can be used in javascript.
Then I thought, why can’t I use javascript to directly connect to the database?
I also made a JavaScript class library that directly connects to Sql data

Later, I thought that I could actually use SQL statements to operate the HTML DOM model

And later, I saw it again The implementation of web DB in HTML5
So webDB is the encapsulation of sqlite in chrome and safari

So there is:

1. Obtain data from the server and execute SQL operation:

Copy code The code is as follows:

_SQLPROXYURL_ = 'SQLProxy.php ';
_SQLSERVERHOST_ = 'localhost';
_SQLUSERNAME_ = 'root';
_SQLPASSWORD_ = '';
_SQLDATABASE_ = 'HotelManageMent';



var result = "select * from Room".OnServer().executeSQL();
for(var i=0; i//do something here.... using result [i];
}


2. Operate Javascript Object Array and perform SQL operations:

Copy Code The code is 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 asc";
var result = SQL.executeSQL();
for(var i=0; i//do something here.... 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();
};


SQL statements are all written outside. Is it safe?

Regarding security issues, first of all, this is not intended for Internet applications, but for local area networks. Secondly, the database connection is encrypted by SSL. In fact, HTTP also has SSL. Furthermore. Remote call service is only one of the four major modules of JSQL. It is also possible to operate the client objects array, the browser's SQLite and the DOM of the web page without going through the service. The SQL here only represents a language specification, which is suitable for but not limited to back-end SQL databases. There are also three modules for front-end operations.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn