在給定的數據窗口對象添加適當的條件字句(轉)

/* 函數說明  */ //========================================================================================== //函數名         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 //============================^_^結束----謝謝使用^_^========================

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章