在PB中动态修改SQL语句[1]

在PB中动态修改SQL语句[1],第1张

;   PowerBuilder是图形界面的Client/Server应用程序开发环境 可以很容易开发出功能强大的应用程序 在当前应用非常广泛

数据库应用程序通常进行一项确定的工作 在编写和编译时就可以确定完整的SQL语句 但是当需要使用PowerBuilder不支持的嵌入SQL语句 或者在编译时不能确定SQL语句的具体格式和参数时 只能在程序运行过程中构造SQL语句 需要使用动态SQL语句 以Format 动态SQL语句为例 使用格式如下 DECLARE Cursor | Procedure DYNAMIC CURSOR | PROCEDURE FOR DynamicStagingArea ;

PREPARE DynamicStagingArea FROM SQLStatement{USING TransactionObject} ;

DESCRIBE DynamicStagingArea INTO DynamicDescriptionArea ;

OPEN DYNAMIC Cursor | ProcedureUSING DESCRIPTOR DynamicDescriptionArea} ;

EXECUTE DYNAMIC Cursor | ProcedureUSING DESCRIPTOR DynamicDescriptionArea ;

FETCH Cursor | Procedure USING DESCRIPTOR DynamicDescriptionArea ;

CLOSE Cursor | Procedure ;

在使用动态SQL语句时 需准备DynamicStagingArea对象(全局对象SQLSA)和DynamicDescriptionArea对象(全局对象SQLDA) 定义游标或过程 读取PREPARE语句中的SQL语句以及语句中说明的参数和类型 执行FETCH语句后 调用相关的函数逐条读取并处理检索结果 动态SQL语句虽然解能够在程序运行过程中构造SQL语句 但在实际应用中较少使用 若SELECT语句的结果序列一定 可以通过重新指定DataWindow对象的SELECT语句的方法 达到动态修改SQL语句的功能 运用时首先用Describe函数读取DataWindow对象的SELECT语句 用Replace等函数修改出符合要求的SELECT语句 并且可以增加检索条件 再用SetSQLSelect函数为DataWindow控件指定修改后的SELECT语句

程序代码 string sql_string sql_newlong start_pos= string old_str //select语句中需要替换的字符串string new_str //替换字符串 可以是结构相同的表名

lishixinzhi/Article/program/PB/201311/24558

读取时判断各个查询条件是否有输入,然後将条件组成一个where 条件
再用dw_1getsqlselect() 取得原datawindow的sql ,然後组合成新的sql 再用dw_1setsqlselect(newsql),再读取

1如果两个数据窗口结构一样的话可以用rowscopy
这个用法贴到最下面
2如果仅复制一部分数据的就只有getitemXX,---and---setitemXX
首先for循环判断dw_1 哪些复选框是选中的(假如复选框列名为Flag,选中值为Y 未选中值为N)
int li_row
for i = 1 to dw_1rowcount()
if dw_1getitemstring(i,'Flag') ='Y' then
// 这里做插入到dw_2 中
li_row = dw_2insertrow(0)
dw_2SetFocus()
dw_2ScrollToRow(li_row)
dw_2selectrow(0,false)
dw_2selectrow(li_row,true)
dw_2SetColumn(1)
dw_2setitem(li_row,'col_name',dw_1getitemstring(i,'col_name'))
//跟多列可以类似写法 只需要更换Col_name即可
end if
next

rowscopy 用法:
Controls
DataWindow controls, DataStore objects, and child DataWindows
Syntax
dwcontrolRowsCopy (startrow, endrow, copybuffer, targetdw, beforerow, targetbuffer )
Argument Description
dwcontrol The name of a DataWindow control, DataStore, or child DataWindow from which you want to copy rows
startrow A long whose value is the number of the first row you want to copy
endrow A long whose value is the number of the last row you want to copy
copybuffer A value of the dwBuffer enumerated data type specifying the buffer from which you want to copy the rows:Primary!Delete!Filter!
targetdw The name of the DataWindow control or DataStore object to which you want to copy the rows Targetdw can be the same DataWindow (or DataStore) or another DataWindow (or DataStore)
beforerow A long specifying the number of the row before which you want to insert the copied rows To insert after the last row, use any value that is greater than the number of existing rows
targetbuffer A value of the dwBuffer enumerated data type specifying the target buffer for the copied rows Values are:Primary!Delete!Filter!
有不明白的可以HI我活着继续提问

可以的。
找个反编译工具来,然后反编译,虽然不能完全回复到源代码,但是基本上来说你也能减少很多工作。
而且,看你说的只有exe的代码也是一个小小程序,很简单。
你百度下“PB反编译”,就会有很多结果!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13388563.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-26
下一篇 2023-07-26

发表评论

登录后才能评论

评论列表(0条)

保存