pb执行sql文件

$PBExportHeader$uf_exesqlfile.srf
global type uf_exesqlfile from function_object
end type
forward prototypes
global function integer uf_exesqlfile (string astr_file, transaction atrs_sql)
end prototypes
global function integer uf_exesqlfile (string astr_file, transaction atrs_sql);int f
string ls_file
ls_file = astr_file
f = fileopen(ls_file,linemode!,read!,shared!)
if f < 0 then 
//messagebox('错误','打开文件'+ls_file+'错误!')
return 0
end if
string ls_line
string ls_sql
int li_rtn,li_exec,li_succ
li_rtn = fileread(f,ls_line)
li_exec = 0
li_succ = 0
do while li_rtn >=0 
ls_line = trim(ls_line)
if left(ls_line,2) = '--' or left(ls_line,2)='//' then
li_rtn = fileread(f,ls_line)
continue
end if
if right(ls_line,1) = ";" then
ls_line = left(ls_line,len(ls_line) - 1)
ls_sql = ls_sql + " " + ls_line
li_exec ++
execute immediate :ls_sql using atrs_sql;
if atrs_sql.sqlcode =0 then
li_succ ++
end if
ls_sql = ""
else
ls_sql = ls_sql + " " + ls_line
end if
li_rtn = fileread(f,ls_line)
loop
commit using atrs_sql;
fileclose(f)
if li_exec = li_succ  then
messagebox('信息','执行'+astr_file+'~r~n执行'+ string(li_exec)+",成功"+string(li_succ)+"。")
return li_succ
else
return - 1
end if
end function
posted @ 2011-08-04 16:18  kuailewangzi1212  阅读(495)  评论(0编辑  收藏  举报