gongji 发表于 2013-1-29 13:54:18

SQL语句在JavaScript中的应用

最近一直在用javascript在做项目
可是做着做着
感觉很多功能代码都是重复的。

比如对javascript数组的排序
还有对数组数据的删选以及分组

所以,后来兴致以上来。
一发不可收拾。

写了一个能在javascript中应用的 SQL 库
后来又想,怎么不能用javascript直接连接数据库呢?
又做了一个javascript直连Sql数据的类库

后来,又想到其实还可以用SQL语句来操作HTML DOM模型

再再再后来,又看到了HTML5中对web DB的实现
所以对webDB,就是chrome和safari中的sqlite的封装

于是乎就有了:

1.从服务器上获取数据、执行SQL操作:
_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 here.... using result;}

2.操作Javascript Object Array 、执行SQL操作:
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<result.length; i++) {    //do something here.... using result;};"create table mytable".executeSQL();for(var j=0; j<100; j++) {"insert into mytable (id,name,sex) values(2,'zhangsan',true) ".executeSQL();};

接下文吧。这个javaeye写博客。编辑器太小了。 很难写
页: [1]
查看完整版本: SQL语句在JavaScript中的应用