以前从网上down了一个,你看看吧。
//以下代码 save as w_sql.srw
//然后 import 引入你的 *.pbl
//===========================
$PBExportHeader$w_sql.srw
$PBExportComments$数据浏览统一格式
forward
global type w_sql from window
end type
type cb_undo from commandbutton within w_sql
end type
type mle_1 from multilineedit within w_sql
end type
type cb_execute from commandbutton within w_sql
end type
type cb_close from commandbutton within w_sql
end type
type dw_1 from datawindow within w_sql
end type
end forward
global type w_sql from window
integer width = 2309
integer height = 1396
boolean titlebar = true
string title = "数据查询分析器"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "Form!"
boolean clientedge = true
cb_undo cb_undo
mle_1 mle_1
cb_execute cb_execute
cb_close cb_close
dw_1 dw_1
end type
global w_sql w_sql
type variables
boolean ib_onoff = false //操作权限开关
end variables
forward prototypes
public subroutine wf_query (string s_sql, ref datawindow dw_x)
end prototypes
if len(ls_exe) < 7 then
MessageBox('系统提示','选中要执行的完整语句,然后再点执行!')
return
end if
//1操作权限验证
if ib_onoff = false then
if ls_exe = 'I AM SUSUE' then
ib_onoff = true
Messagebox('系统提示','你的操作权限已经通过系统验证,可以进行SELECT操作!~r~n~r~n如要执行DELETE,UPDATE,INSERT操作要特别谨慎!!~r~n~r~选中要执行的语句点【[E] 执行】即可。')
else
Messagebox('系统提示','当前的操作存在不安全因素,~r~n~r~n你的操作权限没有通过系统验证前,无法进行任何操作!')
end if
return
end if
//1
string ls_6 //sql 语句的前 6 个字母
ls_6 = left(ls_exe,6)
//执行查询操作
choose case ls_6
case 'SELECT'
//在 dw_1 显示查询结果
wf_query(ls_exe,dw_1)
case 'INSERT','DELETE','UPDATE'
//用动态 sql 执行操作
EXECUTE IMMEDIATE :ls_exe;
if sqlca.sqlcode = 0 and sqlca.sqlnrows > 0 then
messagebox('系统信息','本次操作影响的行数为:' + string(SQLCA.SQLNRows) + '行')
commit;
else
messagebox('错误信息','语法错误或数据错误,~n~r错误信息:' + SQLCA.SQLErrText)
rollback;
end if
case else
//操作提示
MessageBox('系统提示','非法 SQL 语句或被禁止的操作!')
end choose
mle_1.SetFocus()
end event
type cb_close from commandbutton within w_sql
integer x = 37
integer y = 32
integer width = 370
integer height = 104
integer taborder = 20
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string text = "[&C] 关 闭"
end type
event clicked;close(parent)
end event
type dw_1 from datawindow within w_sql
integer x = 27
integer y = 408
integer width = 2158
integer height = 768
integer taborder = 50
string title = "none"
boolean hscrollbar = true
boolean vscrollbar = true
boolean hsplitscroll = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type
event rowfocuschanged;This.SelectRow(0,False)
This.SelectRow(this.GetRow(),True)
end event
PowerBuilder These statements create a new DataWindow in the control dw_new from the DataWindow source code returned by the SyntaxFromSQL function. Errors from SyntaxFromSQL and Create are displayed in the MultiLineEdits mle_sfs and mle_create. After creating the DataWindow, you must call SetTransObject for the new DataWindow object before you can retrieve data: