六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 103|回复: 0

SQL语句在JavaScript中的应用

[复制链接]

升级  52%

6

主题

6

主题

6

主题

童生

Rank: 1

积分
26
 楼主| 发表于 2013-1-24 06:50:30 | 显示全部楼层 |阅读模式
最近一直在用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[i];}

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[i];};"create table mytable".executeSQL();for(var j=0; j<100; j++) {"insert into mytable (id,name,sex) values(2,'zhangsan',true) ".executeSQL();};

接下文吧。这个javaeye写博客。编辑器太小了。 很难写
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表