⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uf_modifysql.srf

📁 动态修改数据窗口的Where子句
💻 SRF
字号:
$PBExportHeader$uf_modifysql.srf
$PBExportComments$函数(动态修改WHERE字句)
global type uf_modifysql from function_object
end type

forward prototypes
global function integer uf_modifysql (ref u_dw adw_obj, string as_newcondition, integer ai_modifytype)
end prototypes

global function integer uf_modifysql (ref u_dw adw_obj, string as_newcondition, integer ai_modifytype);///////////////////////////////////////////////////////////////////////////////
//	Function:  uf_ModifySql                                                   //
// Written by yanghb at 2003-3-15                                            //
//                                                                           //
//	Arguments     :adw_obj         u_dw.                                      //
//	              :as_NewCondition string.                                    //
//	              :ai_ModifyType   integer.                                   //
//                                                                           //
//	Return        :If operation is success then return 1 else -1              //
//                                                                           //
//	Description:  Modify the where cluster of dw sql statement by modify type.//
///////////////////////////////////////////////////////////////////////////////
constant integer ReqOriginal = 1
constant integer ReqAppend   = 2
constant integer ReqReplace  = 3

int i,j,intrtn ,li_colnum,li_tablenum
string strNewSql,ls_col[] ,ls_scope,ls_left 

n_cst_sql 		 lnv_sql
n_cst_sqlattrib lstr_sql[]
n_cst_dwsrv_multitableattrib lnv_OriginalUpdateSettings
//
uf_StoreUpdateSettings(adw_obj,lnv_OriginalUpdateSettings)

lnv_sql.of_parse( adw_obj.getsqlselect(), lstr_sql[] )

choose case ai_modifytype
		
	case ReqOriginal //1
		
		for i = 1 to upperbound(lstr_sql)
			if pos(lstr_sql[i].s_where,"(1=1)") > 0  then
				if pos(lstr_sql[i].s_where,"AND (1=1)") > 0 then
					lstr_sql[i].s_where = left(lstr_sql[i].s_where,pos(lstr_sql[i].s_where,"AND (1=1)") -1)
				else
					lstr_sql[i].s_where = left(lstr_sql[i].s_where,pos(lstr_sql[i].s_where,"(1=1)") -1)
				end if
			end if
		next

	case ReqAppend //2

		for i = 1 to upperbound(lstr_sql)

			// 确定完整的字段名
			li_colnum = uf_parsetoarray(lstr_sql[i].s_columns,",",ls_col)
			ls_left = upper(left(as_newcondition,pos(as_newcondition," ") -1))
			ls_scope = ls_left
			if pos(ls_left,".") = 0 then
				for j = 1 to li_colnum
					if pos(upper(ls_col[j]),ls_scope) > 0 then
						ls_scope = trim(ls_col[j])
						as_newcondition = ls_scope + mid(as_newcondition,pos(as_newcondition," ") )
						exit
					end if
				next
			end if	
			//完成字段名的转换

			if pos(lstr_sql[i].s_where,"(1=1)") > 0 then
				lstr_sql[i].s_where = lstr_sql[i].s_where + " AND ( " + as_newcondition + " )"  
			else
				if len(trim(lstr_sql[i].s_where)) = 0 then
					lstr_sql[i].s_where = " (1=1) AND ( " + as_newcondition + " )"
				else
					lstr_sql[i].s_where = lstr_sql[i].s_where + " AND (1=1) AND ( " + as_newcondition + " )"
				end if
			end if
			
		next
		
	case ReqReplace //3

		for i = 1 to upperbound(lstr_sql)

			// 确定完整的字段名
			li_colnum = uf_parsetoarray(lstr_sql[i].s_columns,",",ls_col)
			ls_left = upper(left(as_newcondition,pos(as_newcondition," ") -1))
			
			ls_scope = ls_left
			if pos(ls_left,".") = 0 then
				ls_scope = ls_left
				for j = 1 to li_colnum
					if pos(upper(ls_col[j]),ls_scope) > 0 then
						ls_scope = trim(ls_col[j])
						as_newcondition = ls_scope + mid(as_newcondition,pos(as_newcondition," ") )
						exit
					end if
				next
			end if	
		 	//完成字段名的转换
			
			if pos(lstr_sql[i].s_where,"(1=1)") > 0 then
				if pos(lstr_sql[i].s_where,"AND (1=1)") > 0 then
					lstr_sql[i].s_where = left(lstr_sql[i].s_where,pos(lstr_sql[i].s_where,"AND (1=1)") -1)
				else
					lstr_sql[i].s_where = left(lstr_sql[i].s_where,pos(lstr_sql[i].s_where,"(1=1)") -1)
				end if
		   end if
			
			if len(trim(lstr_sql[i].s_where)) = 0 then
				lstr_sql[i].s_where = lstr_sql[i].s_where + " (1=1) AND ( " + as_newcondition + " )"  	
			else
				lstr_sql[i].s_where = lstr_sql[i].s_where + " AND (1=1) AND ( " + as_newcondition + " )"  
			end if
			
		next
		
end choose

strNewSql = lnv_sql.of_assemble( lstr_sql)
	
// modify the old select statement with new sql
intRtn = adw_obj.setsqlselect(strNewSql)
uf_RestoreUpdateSettings(adw_obj,lnv_OriginalUpdateSettings)
adw_obj.of_retrieve()
// return 1 if success else -1.
return intRtn


end function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -