一个数据窗口PowerBuilder中有一些参数,这些参数显然与在数据窗口的查询列匹配。查询是太复杂。在我的剧本我得到了一个字符串变量的查询语法。此外,我得到的数据窗口定义的参数列表。现在我想,其中,列正在与检索的参数相比,从查询语法列的列表。我不需要在那里列未与检索的说法相比,那些列。
例如查询字符串在其文本“PRODUCT_PRICE> =:prod_price和供应商ID是NULL和STORE_ID =:STOREID”
我想所有的排除供应商ID,因为供应商ID不与任何检索参数比较的列名。查询与许多情况下,语句和运算符太复杂。
有没有简单的方法来获得从查询字符串列列表不涉及复杂的字符串解析脚本?
简化你的问题的一种方法是不使用的参数。
代替
select col1, col2, col3 from table where id = :id
尝试
select col1, col2, col3 from table where 1 = 2
在你的代码,你可以找到与1 = 2
取代id = 8675309
例
long ll_id = 8675309
long ll_start_pos
string ls_needle
string ls_replace
string ls_sql
ls_sql = dw_products.Getsqlselect()
//ls_sql = select col1, col2, col3 from table where 1 = 2
ls_needle = "1 = 2"
ls_replace = "id = " + string( ll_id )
ll_start_pos = Pos(ls_sql, ls_needle)
// Only enter the loop if you find ls_needle.
DO WHILE ll_start_pos > 0
// Replace ls_needle with ls_replace.
ls_sql = Replace(ls_sql, ll_start_pos,Len(ls_needle), ls_replace)
// Find the next occurrence of ls_needle.
ll_start_pos= Pos(ls_sql, ls_needle, ll_start_pos + Len(ls_replace))
LOOP
//Replace SQL
if dw_products.Setsqlselect(ls_sql) <> 1 then
Messagebox("Error setting SQL select",sqlca.sqlerrtext)
return 1