日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 數(shù)據(jù)庫 > sybase > PB9寫的一個拆解SQL語句的通用函數(shù)

PB9寫的一個拆解SQL語句的通用函數(shù)

來源:程序員人生   發(fā)布時間:2014-02-01 11:17:40 閱讀次數(shù):3704次
將以下內(nèi)容復(fù)制,另存為f_split_sql.srf 然后導(dǎo)入pbl中
[cpp] view plaincopy
$PBExportHeader$f_split_sql.srf 
$PBExportComments$SQL操作:分割SQL語句為select、from、where、group by、order by 5個子句 
global type f_split_sql from function_object 
end type 
 
forward prototypes 
global subroutine replace_n (ref string input_str,readonly string replaced_str,readonly string replace_str) 
global subroutine f_split_sql (string as_sql, ref string as_select, ref string as_from, ref string as_where, ref string as_group, ref string as_order) 
end prototypes 
 
global subroutine replace_n (ref string input_str,readonly string replaced_str,readonly string replace_str);string s1 
string s2 
long p 
long n 
 
p = 1 
 
do while 1 = 1 
    p = pos(input_str,replaced_str,p) 
 
    if p = 0 then 
        exit 
    end if 
 
    s1 = mid(input_str,1,p - 1) 
    s2 = mid(input_str,p + len(replaced_str)) 
    input_str = s1 + replace_str + s2 
    p = p + len(replace_str) 
loop 
end subroutine 
 
global subroutine f_split_sql (string as_sql, ref string as_select, ref string as_from, ref string as_where, ref string as_group, ref string as_order);//==================================================================== 
// 過程(函數(shù)|Function): f_split_sql() 
//-------------------------------------------------------------------- 
// 描述(Description): 拆解SQL語句 
//-------------------------------------------------------------------- 
// 變量(Arguments):  
//              string  as_sql      傳入的SQL語句(如:select a from t where b = 1 group by c order by c) 
//      ref     string  as_select   拆解后的select語句(如:select a) 
//      ref     string  as_from     拆解后的from  語句(如:from t) 
//      ref     string  as_where    拆解后的where 語句(如:where b = 1)  
//      ref     string  as_group    拆解后的group 語句(如:group by c)   
//      ref     string  as_order    拆解后的order 語句(如:order by c)   
//-------------------------------------------------------------------- 
// 返回(Returns):  (none) 
//-------------------------------------------------------------------- 
// 作者(Author):  yyoinge     Date: 2012-02-17 13:26 
//-------------------------------------------------------------------- 
// 修改歷史(Modify History):  
//   
//-------------------------------------------------------------------- 
as_sql = lower(trim(as_sql)) 
if as_sql = '' then return 
as_select = ''; as_from = ''; as_group = ''; as_order = '' 
 
replace_n(as_sql,'~r',' ')  
replace_n(as_sql,'~n',' ')  
replace_n(as_sql,'~r~n',' ')  
replace_n(as_sql,'~t',' ')  
replace_n(as_sql, '(select ',' ( select ') 
replace_n(as_sql, ',select ',' , select ') 
replace_n(as_sql,';','  ')  
if leftw(as_sql, 7) <> 'select ' then return 
long ll_gb_p, ll_ob_p, ll_fr_p, ll_se_p, ll_wh_p, ll_tmp, ll_yh_p 
int li_leap = 0 
//先剔除''內(nèi)的內(nèi)容,如:'abc'替換為@@@@@ 
string ls_sql 
ls_sql = as_sql 
do while true 
    ll_yh_p = posw(ls_sql, "'")  
    if ll_yh_p <= 0 then exit 
    ll_tmp = posw(ls_sql, "'", ll_yh_p + 1) 
    if ll_tmp <= 0 then return 
    ls_sql = leftw(ls_sql, ll_yh_p - 1) + fill('@', ll_tmp - ll_yh_p + 1) + midw(ls_sql, ll_tmp + 1)     
loop 
 
//********************************  select 
ll_tmp = 8 
li_leap = -1 
do while true 
    ll_fr_p = posw(ls_sql, " from ", ll_tmp) 
    ll_se_p = posw(ls_sql, " select ", ll_tmp) 
    if ll_fr_p <= 0 then return 
    if ll_fr_p < ll_se_p or ll_se_p = 0 then 
        li_leap ++ 
    else 
        li_leap -- 
    end if 
    if li_leap = 0 then 
        as_select = leftw(as_sql, ll_fr_p) 
        exit 
    end if 
    if ll_fr_p <= 0 then ll_fr_p = 999999 
    if ll_se_p <= 0 then ll_se_p = 999999 
    ll_tmp = min(ll_fr_p, ll_se_p) + 5 
loop 
 
if as_select = '' then return 
 
 
//********************************  group by 
ll_gb_p = lastpos(ls_sql, " group by ") 
ll_ob_p = lastpos(ls_sql, " order by ") 
if ll_gb_p > 0 then 
    if posw(ls_sql, " from ", ll_gb_p + 1) > 0 or posw(ls_sql, " where ", ll_gb_p + 1) > 0 then 
        as_group = '' 
        ll_gb_p = 0 
    else 
        if ll_ob_p > ll_gb_p then 
            as_group = midw(as_sql, ll_gb_p, ll_ob_p - ll_gb_p) 
        else 
            as_group = midw(as_sql, ll_gb_p) 
        end if 
    end if 
else 
    as_group = '' 
end if 
 
//********************************  order by 
if ll_ob_p > 0 then 
    if posw(ls_sql, " from ", ll_ob_p + 1) > 0 or posw(ls_sql, " where ", ll_ob_p + 1) > 0 then 
        as_order = '' 
        ll_ob_p = 0 
    else 
        as_order = midw(as_sql, ll_ob_p) 
    end if 
else 
    as_order = '' 
end if 
//取得select from where 語句的最后一個字符的位置+1 
if ll_gb_p <= 0 then ll_gb_p = ll_ob_p 
if ll_gb_p <= 0 then ll_gb_p = lenw(as_sql) + 1 
 
//********************************  where 
as_sql = midw(leftw(as_sql,ll_gb_p - 1), ll_fr_p) 
ls_sql = midw(leftw(ls_sql,ll_gb_p - 1), ll_fr_p) 
ll_wh_p = lastpos(ls_sql, " where ") 
if ll_wh_p <= 0 then 
    as_where = '' 
else 
    ll_tmp = 5 
    li_leap = 0 
    do while true 
        ll_se_p = posw(ls_sql, "(", ll_tmp) 
        ll_fr_p = posw(ls_sql, ")", ll_tmp) 
        if ll_se_p > ll_wh_p then ll_se_p = 0 
        if ll_fr_p > ll_wh_p then ll_fr_p = 0 
        if (ll_se_p = 0 and ll_fr_p = 0) then exit 
        if ll_fr_p < ll_se_p or ll_se_p = 0 then 
            li_leap ++ 
        else 
            li_leap -- 
        end if 
        if ll_fr_p <= 0 then ll_fr_p = 999999 
        if ll_se_p <= 0 then ll_se_p = 999999 
        ll_tmp = min(ll_fr_p, ll_se_p) + 1 
    loop 
    if li_leap <> 0 then 
        as_where = '' 
    else 
        as_where = midw(as_sql, ll_wh_p) 
        as_sql = leftw(as_sql, ll_wh_p) 
    end if 
end if 
 
//********************************  from 
as_from = as_sql 
 
end subroutine 
 
調(diào)用時,5自學(xué)網(wǎng),這樣寫:
[cpp] view plaincopy
string ls_sql, ls_select, ls_from, ls_where, ls_group, ls_order 
 
ls_sql = dw_1.getsqlselect() 
 
f_split_sql(ls_sql, ls_select, ls_from, ls_where, ls_group, ls_order) 
 
 
即可將SQL語句ls_sql ,拆解為5個部分,之后就可以對各個部分進(jìn)行添加、修改,然后重新組成新的SQL語句了

作者 yyoinge的專欄 ,5自學(xué)網(wǎng)
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国产美女永久免费 | 亚洲精品九九 | 999免费视频| 日本欧美中文字幕 | 成人国产综合 | 亚洲成人毛片 | 成人午夜免费视频 | 欧美午夜性生活 | 国产午夜视频在线观看 | 国产在线视频网 | 色婷婷一区二区三区 | 欧美综合激情网 | 国产一区二区高清视频 | 高清不卡一区二区三区 | 亚洲激情欧美 | 日韩一区二区在线视频 | 久久免费高清 | 亚洲综合成人在线 | 日韩精品 电影一区 亚洲 | 日韩视频在线一区 | 狠狠久久| 夜夜艹天天干 | av在线中文| 欧美国产日本在线观看 | 久久999免费视频 | 99视频在线播放 | 中文字幕在线播放第一页 | 欧美日韩一区二区视频在线观看 | 国产高清无密码一区二区三区 | 国产精品视频网 | 福利视频网址导航 | 性色av一区二区三区 | 午夜精品久久久久久久蜜桃 | 日韩视频一区二区 | 久久精品久久精品 | 欧美视频网 | 免费黄色在线观看 | 欧美日韩成人精品 | av在线二区 | 日韩国产 | 久久久久亚洲一区二区三区 |