Posted by bianbian on 2008-04-02 21:16
本文Tags: SQL, 数据库
SQL语句的需求真是无止境,今天又有一个:需要保留数据表内最后N条记录。
这个需求还是经常碰到的:
比如实时更新的滚动新闻,只需要保留最后的N条,过期的就删除;或者临时上载文件存放表,每天只允许保留N个文件,过期的就连文件一起删除(数据库存放文件路径方式,除了删除记录,还要删除文件——意味着需要取出将被删除的过期记录)。
因为事先不知道总记录长度,常规做法应该select count(*)一遍,然后获得要删除的记录条数。
不过为了提高数据库性能,应尽量减少查询结果返回次数——其实就是能不能一句SQL搞定?
- //删除记录,假设N为100
- DELETE FROM table WHERE id NOT IN ( SELECT id FROM table ORDER BY id DESC LIMIT 100 );
-
- //取出过期记录
- SELECT * FROM table WHERE id NOT IN ( SELECT id FROM table ORDER BY id DESC LIMIT 100 );
标签:
SQL,
数据库遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in Database, Technology | No Comments »
Posted by bianbian on 2008-03-31 22:09
本文Tags: Firefox, IE, Mouse, Wheel, 滚轮, 鼠标
滚轮IE和Firefox的代码不一样:
IE是mousewheel事件,Firefox是DOMMouseScroll事件
事件属性,IE是event.wheelDelta,Firefox是event.detail
属性的方向值也不一样,IE向上滚 > 0,Firefox向下滚 > 0
- //滚轮放大或缩小,基于Prototype 1.6
- var scrollfunc = function(event) {
- var direct = 0;
- if (event.wheelDelta) {
- direct = event.wheelDelta > 0 ? 1 : -1;
- } else if (event.detail) {
- direct = event.detail < 0 ? 1 : -1;
- }
- zoom(direct);
- };
- Event.observe(document, 'mousewheel', scrollfunc);
- Event.observe(document, 'DOMMouseScroll', scrollfunc); //firefox
标签:
Firefox,
IE,
Mouse,
Wheel,
滚轮,
鼠标遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in JavaScript, Technology | No Comments »
Posted by bianbian on 2008-03-26 14:32
本文Tags: bug, IDL, IDLgrClipboard, 剪贴板
经过运行剪贴板监视器程序,我确认这是IDL的bug:如果用VC等其他语言调用IDL绘图,IDL并不能通过IDLgrClipboard对象将绘图结果保存到系统剪贴板(而在IDL的编辑器环境下运行,剪贴板是能得到绘图结果的)。
下面是英文描述:
IDLgrClipboard not works in callable mode (I use VC++ to execute IDL procedure to draw some plots, and copy the result to system clipboard). After running a system-clipboard-viewer-tool, I conclude it must be a bug (I tested with IDL6.2, IDL7.0).
oClipbrd = OBJ_NEW(’IDLgrClipboard’, DIMENSIONS=windowSize)
oClipbrd->Draw, oView
It works well under IDL-workbench, but when call from VC++, everything else goes OK except clipboard is empty.
解决办法:只好制定FILENAME参数,将结果保存到文件:
Finally, I have no choise but to save the drawing to a file, and it works:
oClipbrd->Draw, oView, FILENAME=’tempout.bmp’
标签:
bug,
IDL,
IDLgrClipboard,
剪贴板遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in C/C++, ENVI & IDL, Technology | No Comments »
Posted by bianbian on 2008-03-25 10:03
本文Tags: FY2C, 云图
模仿Google Map(图片切片载入在此平台不需要实现):
支持IE、Firefox等,支持鼠标移动、鼠标双击放大(左键)缩小(右键)、鼠标滚轮放大缩小
云图实时处理和发布(因为在学校内网,实时版本大家不能看到啦)
这里贴下演示地址(只有最后两个时次的图片):FY2C实时云图平台演示
标签:
FY2C,
云图遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in C/C++, JavaScript, Meteorology, Technology | No Comments »
Posted by bianbian on 2008-03-25 01:57
本文Tags: JavaScript, prototype, this
发信人: Net (BBS上没有什么事情是bg不能解决的), 信区: WebDesign
标 题: Re: Javascript问题
发信站: 南京大学小百合站 (Tue Mar 25 01:16:03 2008)
Javascript里的this和其他OO语言不一样
Javascript其实并不适合做OO,其实OO也并不适合Javascript
扯远了。。。。。。
this你就当“执行函数的宿主”理解。因此在一串函数的执行过程中,this不停地在变。
- A = {
- member: "OK",
- method: function () {
- alert(this.member);
- }
- };
- B = A.method;
-
- A.method(); //弹出"OK". A是宿主,this.member == A.member
- B(); //弹出undefined. window(缺省)是宿主,this.member == window.member
为了解决这个问题,很多框架对此进行了包装。
比如Prototype,用bind,实际是动态生成一个function,把宿主作为动态function的执行者,这样对用户来说,this似乎没有变化。
- bind: function() {
- if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
- var __method = this, args = $A(arguments), object = args.shift();
- return function() {
- return __method.apply(object, args.concat($A(arguments)));
- }
- }
实际只要明白this是执行者的指针,一切都可迎刃而解。
标签:
JavaScript,
prototype,
this遵守创作共用协议,转载请链接形式注明来自
http://bianbian.org 做人要厚道
相关日志
Posted in JavaScript, Technology | No Comments »