发布新日志

  • 英语的烦恼

    2008-07-03 11:48:20

         由于有2年多没有碰英语了,现在会的估计和中学生差不多了。回想下,毕业两年多了,工作也是,为了工作把自己的课本知识忘记的都快没影了。 

         看到很多招聘的信息,对英语的要求都比较高,特别是口语的要求,自己从想过要好好的学习英语,可是没次拿起书本都不想看那些奇怪的符号,为什么我们要学不是自己国家的语言,为什么有那么多的语言,都是地球上的人,就不能有一种语言?呵呵,自己的想法有些天真。

         英语现在成了IT行业的头号杀手,因为外国的技术始终比本国的技术强,什么交流啊,文档啊等等一些,全是英文的,看来想在这行长久的发展下去或想看一下外面的世界,英语不好,就完了,,只有靠自己了,我一定要把英语学好!

  • 迷信自动化是测试人员的误区

    2008-06-19 13:20:04

    迷信自动化是测试人员的误区

     

     先说说为什么做测试的人喜欢搞自动化。

      第一,自尊心。计算机科班出身的人都喜欢作开发(Dev)。做测试工作经常是身不由己,可是测试工作很多时间不需要编程,于是做测试的人想方设法写些程序,以显示自己也会编程。结果往往是欲罢不能,测试自动化程序越写越多,越写越复杂。后面我会谈谈测试自动化框架复杂的代价。

      第二,为了出成绩。很多测试组为了向管理层展示成绩,往往要拿出例如测试自动化达到80%,程序覆盖率达到90%。要我说,这些都是Bull Shit。就象小平同志说的实践是检验真理的唯一标准,我认为在测试中用户不出问题是检验质量的唯一标准。自动化做的再多,用户出了问题,也是白搭。另外,一个人就可以做的测试,自动化往往需要两个,三个。倒是解决就业的好方法。

      我对测试自动化的认识也有一个变化的过程。刚刚入行时也是很相信自动化,想方设法写一些从头到尾自动化的框架,觉得自动测试很过瘾。到微软的Portal Media Center组后也是和另外两个人做了一个相当复杂的用户界面的自动测试。其实现在想想,用自动测试发现的问题基本上可以一个人用手工测试完成,最多写些简单的测试辅助工具就可以完成。有些人可能会说自动化可以为产品的下一个版本节省测试时间。其实Portal Media Center 下一个版本出来时,所有户界面完全变了,80%以上的自动测试程序都需要改动。做完第一个版本,我们三个人全都走掉了。后面来的人往往宁可自己再写一套,也懒得改以前人的程序。自动化的浪费就是这样造成的。想说服别人用你开发的自动测试框架是很难的,所有人都想另搞一套。

      下面分几点讲讲为什么要放弃对测试自动化的幻想,和怎样进行低成本的有效测试。如果你还不能同意我对测试自动化的看法,可以去微软员工的Blog看看为什么Windows测试组用的WTT测试框架被称作“Waste of Tester Time"。我最基本的观点不是说测试自动化不能测出bug,而是想问:一个比较复杂的测试自动化框架所造成的人力浪费,值不值得最终的结果?如果不做测试自动化,能不能达到同样的效果。以我的亲身经历,去年我的测试组两个人对应开发组五个人,项目经理三个人的工作量,去年做了好几个ReleaseHotfix只有两三个。我们旁边的测试组七八个人对应五六个Dev。他们又是自动化,又是搞程序覆盖率,好不热闹,Hotfix 也不少。按一个人的人工成本12万美元,我们组省至少三个人的成本36万美元。

      第一,不要指望自动化能帮你找bug。软件bug和生物的bug很像,测试的规律是bug少的地方bug越少,bug多地方越找越多。做测试自动化,往往在开发自动化的时候,该发现的bug就发现了。自动化开发完成,再想发现更多bug就很难了。这是无论你怎样跑你的自动化,也不会发现新的bug

      第二,不要指望自动化对Regression Test的测试的贡献。软件的特点是如果一次做对了,以后永远不会出错。当程序出现变动时,只要针对变动的部分测试就可以了,以前测过的东西,如果和变动没有关联就不会出错。相反如果,程序出现很大变化,自动化可能完全不能用了。

      第三,自动化不如测试工具加手工测试。我不建议测试人员作全面自动化,相反我建议测试人员多做小巧灵活的测试工具。自动化往往需要自动判PassFail 想想你如果测试用于生成www.microsoft.com的页面的产品,你如何判断页面框架生成的正确?很多东西是动态产生的,你很难确认所有的内容的正确性。如果你自己用这个产品手工做个页面,用肉眼很容易判断所有相关和不相关的内容生成的正确性。我就是用这个方法在工作中发现了网页上谁也想不到的bug, 如果用自动化很难在测试阶段发现这个bug

      第四,软件项目的生命周期就定了自动化的无用。现在很多网络应用项目的生命周期都很短,一个项目从生到死不过两三年。死的定义是项目进入Sustain Engineering维持状态。自动化原来的一个主要目的是使软件测试的未来阶段越来越容易,成本越来越低。可是当一个项目死掉了,自动化还有什么用。而且最新的敏捷开发,软件的要求,程序,接口,界面在不断变化,自动化怎么可能跟得上变化。与其去搞自动化,不如多理解变化,直接测试变化的东西。

     

  • QTP的Action间的信息共享的4种方法(转)

    2008-06-13 11:01:47

    通过Action参数来传递数据
     
    Action2的脚本如下:
    ' Input Parameters
    Message = Parameter("Msg")
    Msgbox Message
     
    ' Output Parameters
    If NOT Message = "" Then
           Parameter("ReturnMsg") = "The Message is " & Message
    Else
           Parameter("ReturnMsg") = "The Message is Empty!"
    End If
     
    ' RetuenValue
    ExitAction "HAHAHAHHAHA!!!!!"
    'ExitAction Parameter("ReturnMsg")
     
     
    3种调用Action的方法,Action1的脚本如下:
    ' 调用Action2,输入参数为 “ Hello!”,把输出参数值写到ReturnMessage1变量
    RunAction "Action2", oneIteration,"Hello!" ,ReturnMessage1
    Msgbox ReturnMessage1
     
    ' 调用Action2,输入参数为 “ Hello!”,通过Parameter方法读取输出参数值
    RunAction "Action2", oneIteration,"Hello!"
    ReturnMessage2= Parameter("Action2","ReturnMsg")
    Msgbox ReturnMessage2
     
    ' 如果被调用的Action使用了ExitAction来退出Action并返回ReturnValue,则可以使用下面的方式来获取Return Value的值
    ' 注意OutPut Parameters与Return Value的区别
    ReturnMessage3 = RunAction( "Action2", oneIteration ,"Hello!")
    Msgbox ReturnMessage3
     
            通过全局数据表(Global Data Table)来共享数据
     
    在Action1中设置参数值,Action1的脚本如下:
    ' 获取全局数据表
    Set Sheet = DataTable.GetSheet("Global")
    ' 查找参数列
    Set Parameter1 = Sheet.GetParameter("Column1")
    Set Parameter2 = Sheet.GetParameter("Column2")
    ' 设置参数值
    Parameter1.Value="Hello"
    Parameter2.Value="World!"
    ' 调用Action2,Action2将使用前面设置的参数值
    RunAction "Action2", oneIteration
     
    在Action2中读取参数值,Action2的脚本如下:
    ' 获取全局数据表
    Set Sheet = DataTable.GetSheet("Global")
    ' 读取参数值
    Set Parameter1 = Sheet.GetParameter("Column1")
    Set Parameter2 = Sheet.GetParameter("Column2")
    ' 使用参数值
    Msgbox Parameter1 &" " & Parameter2

  • QTP常用函数(转)

    2008-06-12 12:00:01

    1.GetCellData函数 

      作用:获取单元格的值

      例:  rowCount = Browser("xxx ").Page("xxx ").Frame("xxx").WebTable("xxx").RowCount软件测试专业网站:51Testing软件测试网e6{k.X SO.x
    For counter = 1 To rowCount软件测试专业网站:51Testing软件测试网8S'\!~?%F2H x*Ifx
      text = Browser("xxx").Page("xxx").Frame("xxx").WebTable("xxx").GetCellData(counter,1)软件测试专业网站:51Testing软件测试网;Wl)[{1v X(YgP
      If (text = "xxx") Then
    2K%c3s.T#L!^9z.} S ~46301    counter = counter - 1
    .imw&a~p Y:\w;\0~46301    selectNO = "#" & counter软件测试专业网站:51Testing软件测试网`7J Pmd
        Browser("xxx").Page("xxx").Frame("xxx").WebRadioGroup("xxx").Select selectNO
    qLT8{y46301    Exit For
    (M:n j.K'P sEB46301  End If软件测试专业网站:51Testing软件测试网-q l)j;yl
    Next

    2.把值插入datatable里

      例:   datatable.setcurrentrow(i) 软件测试专业网站:51Testing软件测试网 R6AB7t m f
            datatable.value("name","Global")="name"软件测试专业网站:51Testing软件测试网0k"E*E5d'['z:~#b&h`;@
            datatable.value("passwd","Global")="passwd"

    3.用代码来启动浏览器

      Browser1 = "IE"
    -rw&\,PM(P'C0R:E7P+|"J7E46301  StartURL = "www.51testing.com"
    !o!r,] xT[46301  IF Browser1 = "IE" THEN 软件测试专业网站:51Testing软件测试网gtJi8K
         set IE = CreateObject("InternetExplorer.Application")软件测试专业网站:51Testing软件测试网Ft8_4O^!ZW-\.`&VF
         IE.Visible = true
    5s!uY(p-[46301     IE.Navigate StartURL
    u%Hwq"s+V46301  END IF软件测试专业网站:51Testing软件测试网"Xe$z#B pY
     

    4.ExecuteFile函数

      作用:ExecuteFile 可以直接执行vbs文件,而不需要将其导入resource中 软件测试专业网站:51Testing软件测试网2Oz|? X
           ExecuteFile FileName 软件测试专业网站:51Testing软件测试网*f s%TM*s3})k[,Mf
      说明:where FileName is the absolute or relative path of your VBscrīpt file.

      例:ExecuteFile("F:\test.vbs")

    5.Strcomp函数 

      作用:比较文本

      例:dim strtext1,strtext2,str ,str1,comp1
    B%B { u8crC9l46301     strtext1 = "xxx"
    +O8{ Tn m[46301     strtext2 = "xxx"
    +|%b xQ"mY#K(]46301     str = VbWindow("xxx").VbWindow("xxx").VbLabe1("xxx").GetTOProperty("text")软件测试专业网站:51Testing软件测试网:\d#a8AW g w ud6V&e
         str1= VbWindow("xxx").VbWindow("xxx").VbLabel("xxx").GetTOProperty("text")软件测试专业网站:51Testing软件测试网,C/` vLr$z-_ EE
         comp1=strcomp(strtext1,str,0)
    .k$nL#a%k0y6rJM*j%Z|46301     If  comp=0 Then
    -Z*S0s!i EGL(GY,h46301          msgbox “这两个串相等”
    XW1b_@ U:r(ODgr&c46301     else
    Al \4v%eGq"j46301       msgbox str软件测试专业网站:51Testing软件测试网Q#D$YB Hv dw-A
         End If 

    6.CaptureBitmap 

      作用:捕获屏幕

    7. GetROProperty

      作用:取对象属性值

      例:VbWindow("xxx").VbWindow("xxx").VbWindow("xxx").ActiveX("xxx").GetROProperty("TextMatrix(1,0)") 

    8.ExitAction - 退出当前操作,无论其循环属性如何。软件测试专业网站:51Testing软件测试网7^k7u9h(a oZ ~Iw
      ExitActionIteration - 退出操作的当前循环。软件测试专业网站:51Testing软件测试网?'_&t ^$n9Od
      ExitRun - 退出测试,无论其循环属性如何。软件测试专业网站:51Testing软件测试网*{)nM)b*D4[F}
      ExitGlobalIteration - 退出当前全局循环。


    R$iRF!bf|463019.如何使用Excel对象处理数据?
    7Z7C3[,ME3[d1anogP46301  Dim xl软件测试专业网站:51Testing软件测试网+q`^w_f#i
      打开excel文件软件测试专业网站:51Testing软件测试网 fh8j,e3Z#d@3^M7[M+u
      Function OpenExcelFile(strFilePath)软件测试专业网站:51Testing软件测试网*S(G)W {k%t#k0L.X"g1E$V
      Set xl = CreateObject("Excel.Application")
    8Q7CN!D@ Fz46301  xl.Workbooks.Open strFilePath软件测试专业网站:51Testing软件测试网} V3h ~ju(pI gq
      End Function软件测试专业网站:51Testing软件测试网h"N%WI ]q
      获得指定单元格数据
    (E%g8C+P-?O!r2qz;z46301  Function GetCellData(strSheet,rwIndex,colIndex)
    :PB-t?f2VD.Ug46301  GetCellData = xl.WorkSheets(strSheet).Cells(rwIndex,colIndex)软件测试专业网站:51Testing软件测试网:Zt^jUk"a8G
      End Function软件测试专业网站:51Testing软件测试网H6}*HeY
      填充单元格数据软件测试专业网站:51Testing软件测试网1yY5e*IJVq&l8iI
      Function PutCellData(strSheet,rwIndex,colIndex,varData)
    /{,Y%HLO-Kj ne j^46301  xl.WorkSheets(strSheet).Cells(rwIndex,colIndex) = varData软件测试专业网站:51Testing软件测试网&\:zIA1Lg a7z"V
      End Function软件测试专业网站:51Testing软件测试网 E*w'{O:~^0aCUk
      保存并推出软件测试专业网站:51Testing软件测试网'f\+oQ h#f/V@i
      Function SaveAndQuit()软件测试专业网站:51Testing软件测试网`&AAW!c!r D
      xl.Activeworkbook.save
    7WyY{KQ A46301  xl.Quit
    LG'r-b A?"m,M46301  Set xl = nothing软件测试专业网站:51Testing软件测试网0x4NJ|~%s6l:D
      End Function
    "p8Yqr(C,y,\-R46301

    10.连接sql数据库

      例:Dim res,cmd,sql软件测试专业网站:51Testing软件测试网8[&qb p.}m
         Set Res=createobject("adodb.recordset")
    S$u"Q6Y0B1dO D46301     Set Cmd=createobject("adodb.command")
    7Q;kijE t46301     Cmd.activeconnection="Provider=SQLOLEDB.1;Password=111111;Persist Security Info=True;User ID=sa;Initial Catalog=xhq;Data Source=192.168.191.142"  '这句话是连接数据库的数据源,要做修改软件测试专业网站:51Testing软件测试网~ RDO| M ~)jS3CW/K#b
        Cmd.CommandType = 1
    amW1Uw Nq46301    sql="selec t * from 表 where name=username"软件测试专业网站:51Testing软件测试网*z _g,^ o G0_#t|
        Cmd.CommandText = sql
    .J.~e6U,l:Cp$l46301    Set res = Cmd.Execute()软件测试专业网站:51Testing软件测试网'T D+]xg0R*uz"E
        Set res = nothing软件测试专业网站:51Testing软件测试网 n2GWU:c J
        Set cmd.ActiveConnection = nothing软件测试专业网站:51Testing软件测试网8G1e(D}+i"r+g2?x(u
        Set Cmd= nothing

  • SQL操作全集(转)

    2008-06-12 11:55:12

    下列语句部分是Mssql语句,不可以在access中使用。

    SQL分类:  
    DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)  
    DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)  
    DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)

    首先,简要介绍基础语句:
    1、说明:创建数据库
    CREATE DATABASE database-name  
    2、说明:删除数据库
    drop database dbname
    3、说明:备份sql server
    --- 创建 备份数据的 device
    USE master
    EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
    --- 开始 备份
    BACKUP DATABASE pubs TO testBack  
    4、说明:创建新表
    create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
    根据已有的表创建新表:  
    A:create table tab_new like tab_old (使用旧表创建新表)
    B:create table tab_new as select col1,col2… from tab_old definition only
    5、说明:删除新表drop table tabname  
    6、说明:增加一个列
    Alter table tabname add column col type
    注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。
    7、说明:添加主键: Alter table tabname add primary key(col)  
    说明:删除主键: Alter table tabname drop primary key(col)  
    8、说明:创建索引:create [unique] index idxname on tabname(col….)  
    删除索引:drop index idxname
    注:索引是不可更改的,想更改必须删除重新建。
    9、说明:创建视图:create view viewname as select statement  
    删除视图:drop view viewname
    10、说明:几个简单的基本的sql语句
    选择:select * from table1 where 范围
    插入:insert into table1(field1,field2) values(value1,value2)
    删除:delete from table1 where 范围
    更新:update table1 set field1=value1 where 范围
    查找:select * from table1 where field1 like ’%value1%’ ---like的语法很精妙,查资料!
    排序:select * from table1 order by field1,field2 [desc]
    总数:select count * as totalcount from table1
    求和:select sum(field1) as sumvalue from table1
    平均:select avg(field1) as avgvalue from table1
    最大:select max(field1) as maxvalue from table1
    最小:select min(field1) as minvalue from table1
    11、说明:几个高级查询运算词
    A: UNION 运算符  
    UNION 运算符通过组合其他两个结果表(例如 TABLE1 和 TABLE2)并消去表中任何重复行而派生出一个结果表。当 ALL 随 UNION 一起使用时(即 UNION ALL),不消除重复行。两种情况下,派生表的每一行不是来自 TABLE1 就是来自 TABLE2。  
    B: EXCEPT 运算符  
    EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL),不消除重复行。  
    C: INTERSECT 运算符
    INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。  
    注:使用运算词的几个查询结果行必须是一致的。  
    12、说明:使用外连接  
    A、left outer join:  
    左外连接(左连接):结果集几包括连接表的匹配行,也包括左连接表的所有行。  
    SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
    B:right outer join:  
    右外连接(右连接):结果集既包括连接表的匹配连接行,也包括右连接表的所有行。  
    C:full outer join:  
    全外连接:不仅包括符号连接表的匹配行,还包括两个连接表中的所有记录。

    其次,大家来看一些不错的sql语句
    1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
    法一:select * into b from a where 1 <>1
    法二:select top 0 * into b from a

    2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
    insert into b(a, b, c) select d,e,f from b;

    3、说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)
    insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件
    例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..

    4、说明:子查询(表名1:a 表名2:b)
    select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)

    5、说明:显示文章、提交人和最后回复时间
    select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b

    6、说明:外连接查询(表名1:a 表名2:b)
    select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c

    7、说明:在线视图查询(表名1:a )
    select * from (SELECT a,b,c FROM a) T where t.a > 1;

    8、说明:between的用法,between限制查询数据范围时包括了边界值,not between不包括
    select * from table1 where time between time1 and time2
    select a,b,c, from table1 where a not between 数值1 and 数值2

    9、说明:in 的使用方法
    select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)

    10、说明:两张关联表,删除主表中已经在副表中没有的信息  
    delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

    11、说明:四表联查问题:
    select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....

    12、说明:日程安排提前五分钟提醒  
    SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5

    13、说明:一条sql 语句搞定数据库分页
    select top 10 b.* from (select top 20 主键字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主键字段 = a.主键字段 order by a.排序字段

    14、说明:前10条记录
    select top 10 * form table1 where 范围

    15、说明:选择在每一组b值相同的数据中对应的a最大的记录的所有信息(类似这样的用法可以用于论坛每月排行榜,每月热销产品分析,按科目成绩排名,等等.)
    select a,b,c from tablename ta where a=(select max(a) from tablename tb where tb.b=ta.b)

    16、说明:包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个结果表
    (select a from tableA ) except (select a from tableB) except (select a from tableC)

    17、说明:随机取出10条数据
    select top 10 * from tablename order by newid()

    18、说明:随机选择记录
    select newid()

    19、说明:删除重复记录
    Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)

    20、说明:列出数据库里所有的表名
    select name from sysobjects where type='U'  

    21、说明:列出表里的所有的
    select name from syscolumns where id=object_id('TableName')

    22、说明:列示type、vender、pcs字段,以type字段排列,case可以方便地实现多重选择,类似select 中的case。
    select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type
    显示结果:
    type vender pcs
    电脑 A 1
    电脑 A 1
    光盘 B 2
    光盘 A 2
    手机 B 3
    手机 C 3

    23、说明:初始化表table1
    TRUNCATE TABLE table1

    24、说明:选择从10到15的记录
    select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
      
    随机选择数据库记录的方法(使用Randomize函数,通过SQL语句实现)
      对存储在数据库中的数据来说,随机数特性能给出上面的效果,但它们可能太慢了些。你不能要求ASP“找个随机数”然后打印出来。实际上常见的解决方案是建立如下所示的循环:  
    Randomize  
    RNumber = Int(Rnd*499) +1  
     
    While Not objRec.EOF  
    If objRec("ID") = RNumber THEN  
    ... 这里是执行脚本 ...  
    end if  
    objRec.MoveNext  
    Wend  
     
      这很容易理解。首先,你取出1到500范围之内的一个随机数(假设500就是数据库内记录的总数)。然后,你遍历每一记录来测试ID 的值、检查其是否匹配RNumber。满足条件的话就执行由THEN 关键字开始的那一块代码。假如你的RNumber 等于495,那么要循环一遍数据库花的时间可就长了。虽然500这个数字看起来大了些,但相比更为稳固的企业解决方案这还是个小型数据库了,后者通常在一个数据库内就包含了成千上万条记录。这时候不就死定了?  
      采用SQL,你就可以很快地找出准确的记录并且打开一个只包含该记录的recordset,如下所示:  
    Randomize  
    RNumber = Int(Rnd*499) + 1  
     
    SQL = "SELECT * FROM Customers WHERE ID = " & RNumber  
     
    set ōbjRec = ObjConn.Execute(SQL)  
    Response.WriteRNumber & " = " & objRec("ID") & " " & objRec("c_email")  
     
      不必写出RNumber 和ID,你只需要检查匹配情况即可。只要你对以上代码的工作满意,你自可按需操作“随机”记录。Recordset没有包含其他内容,因此你很快就能找到你需要的记录这样就大大降低了处理时间。  
    再谈随机数  
      现在你下定决心要榨干Random 函数的最后一滴油,那么你可能会一次取出多条随机记录或者想采用一定随机范围内的记录。把上面的标准Random 示例扩展一下就可以用SQL应对上面两种情况了。  
      为了取出几条随机选择的记录并存放在同一recordset内,你可以存储三个随机数,然后查询数据库获得匹配这些数字的记录:  
    SQL = "SELECT * FROM Customers WHERE ID = " & RNumber & " OR ID = " & RNumber2 & " OR ID = " & RNumber3  
     
      假如你想选出10条记录(也许是每次页面装载时的10条链接的列表),你可以用BETWEEN 或者数学等式选出第一条记录和适当数量的递增记录。这一操作可以通过好几种方式来完成,但是 SELECT 语句只显示一种可能(这里的ID 是自动生成的号码):  
    SQL = "SELECT * FROM Customers WHERE ID BETWEEN " & RNumber & " AND " & RNumber & "+ 9"  

      注意:以上代码的执行目的不是检查数据库内是否有9条并发记录。

     
    随机读取若干条记录,测试
    Access语法:SELECT top 10 * From 表名 ORDER BY Rnd(id)
    Sql server:select top n * from 表名 order by newid()
    mysqlelect * From 表名 Order By rand() Limit n
    Access左连接语法(最近开发要用左连接,Access帮助什么都没有,网上没有Access的SQL说明,只有自己测试, 现在记下以备后查)
    语法elect table1.fd1,table1,fd2,table2.fd2 From table1 left join table2 on table1.fd1,table2.fd1 where ...
    使用SQL语句 用...代替过长的字符串显示
    语法:
    SQL数据库:select case when len(field)>10 then left(field,10)+'...' else field end as news_name,news_id from tablename
    Access数据库:SELECT iif(len(field)>2,left(field,2)+'...',field) FROM tablename;  
     
    Conn.Execute说明
    Execute方法
      该方法用于执行SQL语句。根据SQL语句执行后是否返回记录集,该方法的使用格式分为以下两种:
        1.执行SQL查询语句时,将返回查询得到的记录集。用法为:
        Set 对象变量名=连接对象.Execute("SQL 查询语言")
       Execute方法调用后,会自动创建记录集对象,并将查询结果存储在该记录对象中,通过Set方法,将记录集赋给指定的对象保存,以后对象变量就代表了该记录集对象。

        2.执行SQL的操作性语言时,没有记录集的返回。此时用法为:
        连接对象.Execute "SQL 操作性语句" [, RecordAffected][, Option]
          ·RecordAffected 为可选项,此出可放置一个变量,SQL语句执行后,所生效的记录数会自动保存到该变量中。通过访问该变量,就可知道SQL语句队多少条记录进行了操作。
          ·Option 可选项,该参数的取值通常为adCMDText,它用于告诉ADO,应该将Execute方法之后的第一个字符解释为命令文本。通过指定该参数,可使执行更高效。
  • JMeter与LoadRunner的比较(转)

    2008-06-02 11:30:13

       随着对JMeter使用的深入,我越来越倾向于在自己的工作中使用JMeter工具,并且也不遗余力的向我认识的测试工程师推荐这个工具,但很多工程师在初步使用过这个工具后,会向我抱怨JMeter有太多不能做的事情,但在我看来,JMeter确实有不能做的事情,不过,对于Web应用的测试,JMeter是足够强大了。很多人会把JMeter和自己正在使用的LoadRunner进行比较,然后说“还是LoadRunner好用”——关于这一点,我觉得首先要明确“好用”的定义。接下来,我以自己的工作为例,说明一下JMeter是如何适应我的工作内容的。

       我测试的主要项目都是基于Web的应用,从性能测试的角度来说,我希望性能测试工具具有这样的一些特点:
    Critical Features:
    1,支持HTTP/HTTPS协议,能够发送HTTP/HTTPS request;
    2,支持用户场景(借用了LR中的词汇),能够以某种比例在不同的业务上分布用户数量;
    3,支持事务;
    4,支持参数化和关联(还是借用LR中的词汇);
    5,能够获得和汇总请求响应时间等数据,能够提供响应时间汇总、事务/请求处理成功率等数据报表;

    Non-Critical Features:
    1,能够以漂亮的图表展示出结果数据;
    2,能够提供漂亮的用户界面(GUI);
    3,能够提供良好的录制功能和调试环境;

       另外,从我所测试的产品,和我个人的角度来说,我还希望工具具有以下功能:
    1,能够灵活的扩展,例如,我的应用的后端(bakcend)和前端的通讯使用的是RPC方式,则我希望工具能够通过我已有的API直接对后端产生负载,进行负载测试;
    2,可以使用命令行方式,采用批处理模式运行(不需要GUI),运行后的结果能够通过Email等发送给我,或是直接integration到一个可发布的web页面上;
    3,收集得到的数据能够很容易的进行再处理(例如,以XML格式存储raw data);
    4,工具本身具有很好的可信度,可以通过查看代码等方式,了解当意外发生时是工具本身的问题或是应用的问题。

       大体上,JMeter和LoadRunner都可以很好的完成Critical Feature中列出的任务,而LR在Non-Critical Feature方面表现更出色。不过,JMeter在我希望的更灵活的功能方面大获全胜。

       JMeter的另一个最大的优势,自然是在cost方面,LR的价格是有目共睹的,而JMeter,接近0的获得成本对于资金不那么宽裕的公司来说,实在是难得。

       我得承认,在对JMeter和LoadRunner进行比较的时候,我很明显的偏向了JMeter:)在本文中,我不打算以一个独立第三方的面目出现,你可以把本文的观点看作是对JMeter的推介或是认可,目的只是为了消除一些人认为“JMeter是玩具”的观点,实际上,JMeter现在确实是我的性能测试中的主要工具,而LoadRunner已经不再出现在我的性能测试工具列表中了。

       希望这篇文章不会开罪LoadRunner的坚定拥护者们,有任何意见,我非常欢迎理性的讨论。


  • 五十四条DB2常用语句集萃(来源网路)

    2008-05-11 14:45:07

           1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。
    select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'日期不详') birthday
    from employee
    order by dept

      2、查找与喻自强在同一个单位的员工姓名、性别、部门和职称
    select emp_no,emp_name,dept,title
    from employee
    where emp_name<>'喻自强' and dept in
    (select dept from employee
    where emp_name='喻自强')

      3、按部门进行汇总,统计每个部门的总工资
    select dept,sum(salary)
    from employee
    group by dept

      4、查找商品名称为14寸显示器商品的销售情况,显示该商品的编号、销售数量、单价和金额
    select a.prod_id,qty,unit_price,unit_price*qty totprice
    from sale_item a,product b
    where a.prod_id=b.prod_id and prod_name='14寸显示器'

      5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额
    select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
    from sale_item
    group by prod_id

      6、使用convert函数按客户编号统计每个客户1996年的订单总金额
    select cust_id,sum(tot_amt) totprice
    from sales
    where convert(char(4),order_date,120)='1996'
    group by cust_id

      7、查找有销售记录的客户编号、名称和订单总额
    select a.cust_id,cust_name,sum(tot_amt) totprice
    from customer a,sales b
    where a.cust_id=b.cust_id
    group by a.cust_id,cust_name

      8、查找在1997年中有销售记录的客户编号、名称和订单总额
    select a.cust_id,cust_name,sum(tot_amt) totprice
    from customer a,sales b
    where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'
    group by a.cust_id,cust_name

      9、查找一次销售最大的销售记录
    select order_no,cust_id,sale_id,tot_amt
    from sales
    where tot_amt=
    (select max(tot_amt)
    from sales)

      10、查找至少有3次销售的业务员名单和销售日期
    select emp_name,order_date
    from employee a,sales b
    where emp_no=sale_id and a.emp_no in
    (select sale_id
    from sales
    group by sale_id
    having count(*)>=3)
    order by emp_name

      11、用存在量词查找没有订货记录的客户名称
    select cust_name
    from customer a
    where not exists
    (select *
    from sales b
    where a.cust_id=b.cust_id)

      12、使用左外连接查找每个客户的客户编号、名称、订货日期、订单金额订货日期不要显示时间,日期格式为yyyy-mm-dd按客户编号排序,同一客户再按订单降序排序输出
    select a.cust_id,cust_name,convert(char(10),order_date,120),tot_amt
    from customer a left outer join sales b on a.cust_id=b.cust_id
    order by a.cust_id,tot_amt desc

      13、查找16M DRAM的销售情况,要求显示相应的销售员的姓名、性别,销售日期、销售数量和金额,其中性别用男、女表示
    select emp_name 姓名, 性别= case a.sex when 'm' then '男'
    when 'f' then '女'
    else '未'
    end,
    销售日期= isnull(convert(char(10),c.order_date,120),'日期不详'),
    qty 数量, qty*unit_price as 金额
    from employee a, sales b, sale_item c,product d
    where d.prod_name='16M DRAM' and d.prod_id=c.prod_id and
    a.emp_no=b.sale_id and b.order_no=c.order_no

      14、查找每个人的销售记录,要求显示销售员的编号、姓名、性别、产品名称、数量、单价、金额和销售日期
    select emp_no 编号,emp_name 姓名, 性别= case a.sex when 'm' then '男'
    when 'f' then '女'
    else '未'
    end,
    prod_name 产品名称,销售日期= isnull(convert(char(10),c.order_date,120),'日期不详'),
    qty 数量, qty*unit_price as 金额
    from employee a left outer join sales b on a.emp_no=b.sale_id , sale_item c,product d
    where d.prod_id=c.prod_id and b.order_no=c.order_no

      15、查找销售金额最大的客户名称和总货款
    select cust_name,d.cust_sum
    from customer a,
    (select cust_id,cust_sum
    from (select cust_id, sum(tot_amt) as cust_sum
    from sales
    group by cust_id ) b
    where b.cust_sum =
    ( select max(cust_sum)
    from (select cust_id, sum(tot_amt) as cust_sum
    from sales
    group by cust_id ) c )
    ) d
    where a.cust_id=d.cust_id  

    16、查找销售总额少于1000元的销售员编号、姓名和销售额

    select emp_no,emp_name,d.sale_sum
    from employee a,
    (select sale_id,sale_sum
    from (select sale_id, sum(tot_amt) as sale_sum
    from sales
    group by sale_id ) b
    where b.sale_sum <1000
    ) d
    where a.emp_no=d.sale_id

      17、查找至少销售了3种商品的客户编号、客户名称、商品编号、商品名称、数量和金额
    select a.cust_id,cust_name,b.prod_id,prod_name,d.qty,d.qty*d.unit_price
    from customer a, product b, sales c, sale_item d
    where a.cust_id=c.cust_id and d.prod_id=b.prod_id and
    c.order_no=d.order_no and a.cust_id in (
    select cust_id
    from (select cust_id,count(distinct prod_id) prodid
    from (select cust_id,prod_id
    from sales e,sale_item f
    where e.order_no=f.order_no) g
    group by cust_id
    having count(distinct prod_id)>=3) h )

      18、查找至少与世界技术开发公司销售相同的客户编号、名称和商品编号、商品名称、数量和金额
    select a.cust_id,cust_name,d.prod_id,prod_name,qty,qty*unit_price
    from customer a, product b, sales c, sale_item d
    where a.cust_id=c.cust_id and d.prod_id=b.prod_id and
    c.order_no=d.order_no and not exists
    (select f.*
    from customer x ,sales e, sale_item f
    where cust_name='世界技术开发公司' and x.cust_id=e.cust_id and
    e.order_no=f.order_no and not exists
    ( select g.*
    from sale_item g, sales h
    where g.prod_id = f.prod_id and g.order_no=h.order_no and
    h.cust_id=a.cust_id)
    )

      19、查找表中所有姓刘的职工的工号,部门,薪水
    select emp_no,emp_name,dept,salary
    from employee
    where emp_name like '刘%'

      20、查找所有定单金额高于2000的所有客户编号
    select cust_id
    from sales
    where tot_amt>2000

      21、统计表中员工的薪水在4000-6000之间的人数
    select count(*)as 人数
    from employee
    where salary between 4000 and 6000

      22、查询表中的同一部门的职工的平均工资,但只查询"住址"是"上海市"的员工
    select avg(salary) avg_sal,dept
    from employee
    where addr like '上海市%'
    group by dept

      23、将表中住址为"上海市"的员工住址改为"北京市"
    update employee
    set addr like '北京市'
    where addr like '上海市'

      24、查找业务部或会计部的女员工的基本信息。
    select emp_no,emp_name,dept
    from employee
    where sex='F'and dept in ('业务','会计')

      25、显示每种产品的销售金额总和,并依销售金额由大到小输出。
    select prod_id ,sum(qty*unit_price)
    from sale_item
    group by prod_id
    order by sum(qty*unit_price) desc

    26、选取编号界于'C0001'和'C0004'的客户编号、客户名称、客户地址。

    select CUST_ID,cust_name,addr
    from customer
    where cust_id between 'C0001' AND 'C0004'

      27、计算出一共销售了几种产品。
    select count(distinct prod_id) as '共销售产品数'
    from sale_item  

      28、将业务部员工的薪水上调3%。
    update employee
    set salary=salary*1.03
    where dept='业务'

      29、由employee表中查找出薪水最低的员工信息。
    select *
    from employee
    where salary=
    (select min(salary )
    from employee )

      30、使用join查询客户姓名为"客户丙"所购货物的"客户名称","定单金额","定货日期","电话号码"
    select a.cust_id,b.tot_amt,b.order_date,a.tel_no
    from customer a join sales b
    on a.cust_id=b.cust_id and cust_name like '客户丙'

      31、由sales表中查找出订单金额大于"E0013业务员在1996/10/15这天所接每一张订单的金额"的所有订单。
    select *
    from sales
    where tot_amt>all
    (select tot_amt
    from sales
    where sale_id='E0013'and order_date='1996/10/15')
    order by tot_amt

      32、计算'P0001'产品的平均销售单价
    select avg(unit_price)
    from sale_item
    where prod_id='P0001'

      33、找出公司女员工所接的定单
    select sale_id,tot_amt
    from sales
    where sale_id in
    (select sale_id from employee
    where sex='F')

      34、找出同一天进入公司服务的员工
    select a.emp_no,a.emp_name,a.date_hired
    from employee a
    join employee b
    on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)
    order by a.date_hired

      35、找出目前业绩超过232000元的员工编号和姓名。
    select emp_no,emp_name
    from employee
    where emp_no in
    (select sale_id
    from sales
    group by sale_id
    having sum(tot_amt)<232000)

    36、查询出employee表中所有女职工的平均工资和住址在"上海市"的所有女职工的平均工资

    select avg(salary)
    from employee
    where sex like 'f'
    union
    select avg(salary)
    from employee
    where sex like 'f' and addr like '上海市%'

      37、在employee表中查询薪水超过员工平均薪水的员工信息。
    Select *
    from employee
    where salary>( select avg(salary)
    from employee)

      38、 找出目前销售业绩超过10000元的业务员编号及销售业绩,并按销售业绩从大到小排序。
    Select sale_id ,sum(tot_amt)
    from sales
    group by sale_id
    having sum(tot_amt)>10000
    order by sum(tot_amt) desc

      39、 找出公司男业务员所接且订单金额超过2000元的订单号及订单金额。
    Select order_no,tot_amt
    From sales ,employee
    Where sale_id=emp_no and sex='M' and tot_amt>2000

      40、 查询sales表中订单金额最高的订单号及订单金额。
    Select order_no,tot_amt from sales
    where tot_amt=(select max(tot_amt) from sales)

      41、 查询在每张订单中订购金额超过4000元的客户名及其地址。
    Select cust_name,addr from customer a,sales b
    where a.cust_id=b.cust_id and tot_amt>4000

      42、 求出每位客户的总订购金额,显示出客户号及总订购金额,并按总订购金额降序排列。
    Select cust_id,sum(tot_amt) from sales
    Group by cust_id
    Order by sum(tot_amt) desc

      43、 求每位客户订购的每种产品的总数量及平均单价,并按客户号,产品号从小到大排列。
    Select cust_id,prod_id,sum(qty),sum(qty*unit_price)/sum(qty)
    From sales a, sale_item b
    Where a.order_no=b.order_no
    Group by cust_id,prod_id
    Order by cust_id,prod_id

      44、 查询订购了三种以上产品的订单号。
    Select order_no
    from sale_item
    Group by order_no
    Having count(*)>3

      45、 查询订购的产品至少包含了订单3号中所订购产品的订单。
    Select distinct order_no
    From sale_item a
    Where order_no<>'3'and not exists (
    Select * from sale_item b where order_no ='3' and not exists
    (select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id))

    46、 在sales表中查找出订单金额大于"E0013业务员在1996/11/10这天所接每一张订单的金额"的所有订单,并显示承接这些订单的业务员和该订单的金额。

    Select sale_id,tot_amt from sales
    where tot_amt>all(select tot_amt
    from sales
    where sale_id='E0013' and order_date='1996-11-10')  

      47、 查询末承接业务的员工的信息。
    Select *
    From employee a
    Where not exists
    (select * from sales b where a.emp_no=b.sale_id)

      48、 查询来自上海市的客户的姓名,电话、订单号及订单金额。
    Select cust_name,tel_no,order_no,tot_amt
    From customer a ,sales b
    Where a.cust_id=b.cust_id and addr='上海市'

      49、 查询每位业务员各个月的业绩,并按业务员编号、月份降序排序。
    Select sale_id,month(order_date), sum(tot_amt)
    from sales
    group by sale_id,month(order_date)
    order by sale_id,month(order_date) desc

      50、 求每种产品的总销售数量及总销售金额,要求显示出产品编号、产品名称,总数量及总金额,并按产品号从小到大排列。
    Select a.prod_id,prod_name,sum(qty),sum(qty*unit_price)
    From sale_item a,product b
    Where a.prod_id=b.prod_id
    Group by a.prod_id,prod_name
    Order by a.prod_id

      51、 查询总订购金额超过'C0002'客户的总订购金额的客户号,客户名及其住址。
    Select cust_id, cust_name,addr
    From customer
    Where cust_id in (select cust_id from sales
    Group by cust_id
    Having sum(tot_amt)>
    (Select sum(tot_amt) from sales where cust_id='C0002'))

      52、 查询业绩最好的的业务员号、业务员名及其总销售金额。
    select emp_no,emp_name,sum(tot_amt)
    from employee a,sales b
    where a.emp_no=b.sale_id
    group by emp_no,emp_name
    having sum(tot_amt)=
    (select max(totamt)
    from (select sale_id,sum(tot_amt) totamt
    from sales
    group by sale_id) c)

      53、 查询每位客户所订购的每种产品的详细清单,要求显示出客户号,客户名,产品号,产品名,数量及单价。
    select a.cust_id, cust_name,c.prod_id,prod_name,qty, unit_price
    from customer a,sales b, sale_item c ,product d
    where a.cust_id=b.cust_id and b.order_no=c.order_no and c.prod_id=d.prod_id

      54、 求各部门的平均薪水,要求按平均薪水从小到大排序。
    select dept,avg(salary)
    from employee
    group by dept
    order by avg(salary)

     

数据统计

  • 访问量: 3629
  • 日志数: 7
  • 文件数: 1
  • 建立时间: 2008-04-29
  • 更新时间: 2008-07-03

RSS订阅

Open Toolbar