在给定的数据窗口对象添加适当的条件字句(转)

/* 函数说明  */ //========================================================================================== //函数名         Gf_addwhereclause //函数描述       在给定的数据窗口对象添加适当的条件字句 //函数参数       adw              datawindow     待添加条件的数据窗口对象 //               as_whereclause   string         待添加的条件 //               ab_iskeep        boolean        为真时将保持原来数据窗的条件字句新的条件字句将 //                                               默认与的关系添加在原来条件字句的后面 //函数返回值     integer           1             设置新的SQL条件表达式成功 //               integer           -1            设置新的SQL条件表达式失败 //========================================================================================== int li_wherepos,li_grouppos,li_havingpos,li_orderpos ,li_otherpos ,li_retu ulong LL_SqlLen=32760 string ls_oldSQL,  ls_oldSQL_temp,ls_other,ls_select,ls_oldwhere,ls_newSQL

if as_whereclause = "" or isnull(as_whereclause) then  return 1 end if

/*检测必须的参数的有效性并初始化*/ //======================================================================== If isnull(adw)or not isvalid(adw) then return  -1 if isnull(as_whereclause) or Len(trim(as_whereclause))=0 then return -1 ls_oldSQL=adw.Getsqlselect()      ls_oldSQL_temp=adw.Getsqlselect() //========================================================================

/*获取 where groub by, having, order by 位置信息并提取相应*/ //======================================================================== li_wherepos = Pos(lower(ls_oldSql),"where") li_grouppos = Pos(lower(ls_oldSql),"group by") if not li_grouppos>0 then li_grouppos=LL_SqlLen

li_havingpos= Pos(lower(ls_oldSql),"having") if not li_havingpos>0 then li_havingpos=LL_SqlLen li_orderpos = Pos(lower(ls_oldSql),"order by") if not li_orderpos>0 then li_orderpos=LL_SqlLen

li_otherpos = Min(Min(li_grouppos,li_havingpos),li_orderpos)

if  li_otherpos=LL_SqlLen then li_otherpos=0 if li_wherepos>0 then      //已经有条件时  ls_select=left((ls_oldSql),li_wherepos - 1)  //提取SELECT 部分  if li_otherpos>0 then                  //其他部分存在时     ls_oldwhere=Mid(ls_oldSQL,li_wherepos,li_otherpos - li_wherepos )  +" AND " //提取条件部分  M 2002 1 21  ##       ls_other=right(ls_oldSQL,len(ls_oldSQL) - li_otherpos + 1) //提取其他部分  else     ls_oldwhere=right(ls_oldSQL,len(ls_oldSQL) - li_wherepos + 1) +" AND "    // M2002 1 21  ##     ls_other=""     end if else                     //没有条件  ls_oldwhere=" WHERE "   if li_otherpos>0 then   ls_select=left(ls_oldSQL,li_otherpos - 1 ) //2002-11-05 12-02   ls_other=right(ls_oldSQL,len(ls_oldSQL) - li_otherpos + 1) //提取其他部分    else   ls_select=ls_oldSQL     //2002-08-13   lower(ls_oldsql)    end if end if //========================================================================

/*根据设置组合成新的SQL语句 */ //======================================================================== if ab_iskeep then  ls_newSQL=ls_select+ " "&              +ls_oldwhere +   &      +"("+as_whereclause+") "&      +ls_other else  ls_newSQL=ls_select+ " "&              +" WHERE" +" "&      +as_whereclause+" "&      +ls_other end if ========================================================================== ///* 现在我们将用生成的SQL语句修改数据窗的SQL语句*/ ========================================================================== //if gb_debug then //    // ::clipboard(ls_newsql) //end if adw.object.DataWindow.Table.Select=ls_newSQL //li_retu =adw.setsqlselect((ls_newSQL)) adw.settransobject(sqlca) //adw.retrieve();

RETURN li_retu //============================^_^结束----谢谢使用^_^========================

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值