FIND does not work the same in PB 11.5 as in PB 9

My problem:

In a datastore lds there are 3 rows.
A column name is "sscode" - char(10) 
One of the rows has sscode = 'LARRY' (5 bytes)

I have an input field captured into a string variable called ls_text.
The captured value is ' LARRY' which has a leading space. (6 bytes)

Run the following FIND scenarios:

ll_find = lds.("LEFTTRIM(sscode)='" + ls_text + "'", 1, 3)
ll_find = lds.("LEFTTRIM(sscode)='" + RIGHTTRIM(ls_text) + "'", 1, 3)
ll_find = lds.("TRIM(sscode)='" + ls_text + "'", 1, 3)
ll_find = lds.("TRIM(sscode)='" + RIGHTTRIM(ls_text) + "'", 1, 3)
ll_find = lds.("RIGHTTRIM(sscode)='" + ls_text + "'", 1, 3)
ll_find = lds.("RIGHTTRIM(sscode)='" + RIGHTTRIM(ls_text) + "'", 1, 3)

In PB 9 they all fail to find a row - ll_find = 0

In PB 11.5 they all find a row - ll_find > 0

There are 16 possible permutations for the find where the datastore
column (sscode) can be untrimmed, lefttrimmed, trimmed and/or
righttrimmed and the text columns can be similarly treated. I have run
all 16 scenarios against PB 9 and PB 11.5 and all cases perform the
same EXCEPT the six cases above.

I am looking for an explanation with a view to implementing a generic
solution. Currently the application, which worked fine in PB 9, is
behaving badly in PB 11.5.

I have a feeling that Unicode is somehow involved but I do not see how
or why.

Larry


PS:
Here are two objects: a datastore and a window to illustrate:
They are PB 9 for backward compatibility:

The datastore called d_1:
release 9;
datawindow(units=0 timer_interval=0 color=15780518 processing=1
HTMLDW=no print.printername="" print.documentname="" print.orientation
= 0 print.margin.left = 110 print.margin.right = 110 print.margin.top
= 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size
= 0 print.canusedefaultprinter=yes print.prompt=no print.buttons=no
print.preview.buttons=no print.cliptext=no print.overrideprintjob=no
print.collate=yes hidegrayline=no grid.lines=0 )
header(height=80 color="536870912" )
summary(height=0 color="536870912" )
footer(height=0 color="536870912" )
detail(height=92 color="536870912" )
table(column=(type=char(11) updatewhereclause=yes name=sscode
dbname="sscode" )
 column=(type=char(35) updatewhereclause=yes name=ssname
dbname="ssname" )
 )
data("LARRY","Larry Peters","BILLY","William Tell","PAUL","Paul
Jones",) 
text(band=header alignment="2" text="Sscode" border="0"
color="33554432" x="9" y="8" height="64" width="302"
html.valueishtml="0"  name=sscode_t visible="1"  font.face="Arial"
font.height="-10" font.weight="400"  font.family="2" font.pitch="2"
font.charset="0" background.mode="1" background.color="536870912" )
text(band=header alignment="2" text="Ssname" border="0"
color="33554432" x="320" y="8" height="64" width="960"
html.valueishtml="0"  name=ssname_t visible="1"  font.face="Arial"
font.height="-10" font.weight="400"  font.family="2" font.pitch="2"
font.charset="0" background.mode="1" background.color="536870912" )
column(band=detail id=1 alignment="0" tabsequence=10 border="0"
color="33554432" x="9" y="8" height="76" width="302"
format="[general]" html.valueishtml="0"  name=sscode visible="1"
edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes
edit.autohscroll=yes edit.imemode=0  font.face="Arial"
font.height="-10" font.weight="400"  font.family="2" font.pitch="2"
font.charset="0" background.mode="1" background.color="536870912" )
column(band=detail id=2 alignment="0" tabsequence=20 border="0"
color="33554432" x="320" y="8" height="76" width="960"
format="[general]" html.valueishtml="0"  name=ssname visible="1"
edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes
edit.autohscroll=yes edit.imemode=0  font.face="Arial"
font.height="-10" font.weight="400"  font.family="2" font.pitch="2"
font.charset="0" background.mode="1" background.color="536870912" )
htmltable(border="1" )
htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1"
clientformatting="0" clientscriptable="0" generatejavascript="1"
encodeselflinkargs="1" netscapelayers="0" )
export.xml(headgroups="1" includewhitespace="0" metadatatype=0
savemetadata=0 )
import.xml()
export.pdf(method=0 distill.custompostscript="0" xslfop.print="0" )
 

The window called w_1 and using d_1:
forward
global type w_1 from window
end type
type cb_1 from commandbutton within w_1
end type
type sle_1 from singlelineedit within w_1
end type
type dw_1 from datawindow within w_1
end type
end forward

global type w_1 from window
integer width = 1179
integer height = 1048
boolean titlebar = true
string title = "PB 9"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cb_1 cb_1
sle_1 sle_1
dw_1 dw_1
end type
global w_1 w_1

on w_1.create
this.cb_1=create cb_1
this.sle_1=create sle_1
this.dw_1=create dw_1
this.Control[]={this.cb_1,&
this.sle_1,&
this.dw_1}
end on

on w_1.destroy
destroy(this.cb_1)
destroy(this.sle_1)
destroy(this.dw_1)
end on

type cb_1 from commandbutton within w_1
integer x = 18
integer y = 800
integer width = 402
integer height = 112
integer taborder = 30
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "Test"
end type

event clicked;
long		ll_1
string	ls_1, ls_2

messagebox("0) RIGHTTRIM(sscode)", "[" +
RIGHTTRIM(dw_1.GETITEMSTRING(1, "sscode")) + "]")


ls_1 = sle_1.text
ls_2 = "sscode='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("1a) NoTrim(text) NoTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = LEFTTRIM(sle_1.text)
ls_2 = "sscode='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("1b) LtTrim(text) NoTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = TRIM(sle_1.text)
ls_2 = "sscode='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("1c)   Trim(text) NoTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = RIGHTTRIM(sle_1.text)
ls_2 = "sscode='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("1d) RtTrim(text) NoTrim(find)", ls_2 + " : " +
string(ll_1))



ls_1 = sle_1.text
ls_2 = "LEFTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("2a) NoTrim(text) LtTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = LEFTTRIM(sle_1.text)
ls_2 = "LEFTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("2b) LtTrim(text) LtTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = TRIM(sle_1.text)
ls_2 = "LEFTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("2c)   Trim(text) LtTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = RIGHTTRIM(sle_1.text)
ls_2 = "LEFTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("2d) RtTrim(text) LtTrim(find)", ls_2 + " : " +
string(ll_1))



ls_1 = sle_1.text
ls_2 = "TRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("3a) NoTrim(text)   Trim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = LEFTTRIM(sle_1.text)
ls_2 = "TRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("3b) LtTrim(text)   Trim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = TRIM(sle_1.text)
ls_2 = "TRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("3c)   Trim(text)   Trim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = RIGHTTRIM(sle_1.text)
ls_2 = "TRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("3d) RtTrim(text)   Trim(find)", ls_2 + " : " +
string(ll_1))


ls_1 = sle_1.text
ls_2 = "RIGHTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("4a) NoTrim(text) RtTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = LEFTTRIM(sle_1.text)
ls_2 = "RIGHTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("4b) LtTrim(text) RtTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = TRIM(sle_1.text)
ls_2 = "RIGHTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("4c)   Trim(text) RtTrim(find)", ls_2 + " : " +
string(ll_1))

ls_1 = RIGHTTRIM(sle_1.text)
ls_2 = "RIGHTTRIM(sscode)='" + ls_1 + "'"
ll_1 = dw_1.FIND(ls_2, 1, 10)
messagebox("4d) RtTrim(text) RtTrim(find)", ls_2 + " : " +
string(ll_1))

end event

type sle_1 from singlelineedit within w_1
integer x = 18
integer y = 672
integer width = 402
integer height = 112
integer taborder = 20
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
string text = " LARRY"
borderstyle borderstyle = stylelowered!
end type

type dw_1 from datawindow within w_1
integer x = 18
integer y = 12
integer width = 1088
integer height = 640
integer taborder = 10
string title = "none"
string dataobject = "d_1"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type


0
Larry
11/24/2010 2:54:48 AM
sybase.powerbuilder.datawindow 28057 articles. 4 followers. Follow

2 Replies
715 Views

Similar Articles

[PageSpeed] 25

"Larry Peters" <peterslarry@hotmail.com> wrote in message 
news:ndvoe6turojmjfivqv8csb29i1holutr63@4ax.com...
>
> My problem:
>
> In a datastore lds there are 3 rows.
> A column name is "sscode" - char(10)
> One of the rows has sscode = 'LARRY' (5 bytes)

Step 1 is to realize that [number of characters] is no longer [number of 
bytes].

<snip>

> I am looking for an explanation with a view to implementing a generic
> solution. Currently the application, which worked fine in PB 9, is
> behaving badly in PB 11.5.
>
> I have a feeling that Unicode is somehow involved but I do not see how
> or why.

Most likely the explanation is based on the functions that PB is calling to 
compare strings.  The unicode conversion must have required the use of newer 
(and "enhanced") windows API functions for string comparison.  The tip of an 
explanation probably lies in:
http://msdn.microsoft.com/en-us/library/dd318144.aspx

If you want your head to explode, you can try the blog:
http://blogs.msdn.com/b/michkap/

How the PB code actually implements the comparison at the API level isn't 
documented - though it would be nice to have at least some information 
regarding the options used.

An alternative approach is difficult to suggest.  It seems, for most 
string-based data at least, that real "data" should not begin with a spaces. 
The same can be said for trailing spaces.  If the content of the datawindow 
is based on data in a database, then it should have already been scrubbed 
for legitimacy.  If so, that eliminates one side of the find expression as 
problematic and you only need to deal with the input value - and it seems 
like it shouldn't be difficult to handle (just trim it on both sides). 
Since only 6 of the 16 permutations return an expected value, perhaps you 
can use one of the ones that does what is expected (or explain why not). 
Perhaps you can use LIKE - or maybe limit the comparison to the number of 
characters entered by the user?  Kinda depends on what specifically you are 
trying to accomplish. 


0
Scott
11/29/2010 8:26:50 PM
Thanks for your comments.
Looks like I'll need to visit all FINDs and check them for validity.
Unfortunately, leading spaces are not barred in this implementation.

Lary

On 29 Nov 2010 12:26:50 -0800, "Scott Morris" <bogus@bogus.com> wrote:

>"Larry Peters" <peterslarry@hotmail.com> wrote in message 
>news:ndvoe6turojmjfivqv8csb29i1holutr63@4ax.com...
>>
>> My problem:
>>
>> In a datastore lds there are 3 rows.
>> A column name is "sscode" - char(10)
>> One of the rows has sscode = 'LARRY' (5 bytes)
>
>Step 1 is to realize that [number of characters] is no longer [number of 
>bytes].
>
><snip>
>
>> I am looking for an explanation with a view to implementing a generic
>> solution. Currently the application, which worked fine in PB 9, is
>> behaving badly in PB 11.5.
>>
>> I have a feeling that Unicode is somehow involved but I do not see how
>> or why.
>
>Most likely the explanation is based on the functions that PB is calling to 
>compare strings.  The unicode conversion must have required the use of newer 
>(and "enhanced") windows API functions for string comparison.  The tip of an 
>explanation probably lies in:
>http://msdn.microsoft.com/en-us/library/dd318144.aspx
>
>If you want your head to explode, you can try the blog:
>http://blogs.msdn.com/b/michkap/
>
>How the PB code actually implements the comparison at the API level isn't 
>documented - though it would be nice to have at least some information 
>regarding the options used.
>
>An alternative approach is difficult to suggest.  It seems, for most 
>string-based data at least, that real "data" should not begin with a spaces. 
>The same can be said for trailing spaces.  If the content of the datawindow 
>is based on data in a database, then it should have already been scrubbed 
>for legitimacy.  If so, that eliminates one side of the find expression as 
>problematic and you only need to deal with the input value - and it seems 
>like it shouldn't be difficult to handle (just trim it on both sides). 
>Since only 6 of the 16 permutations return an expected value, perhaps you 
>can use one of the ones that does what is expected (or explain why not). 
>Perhaps you can use LIKE - or maybe limit the comparison to the number of 
>characters entered by the user?  Kinda depends on what specifically you are 
>trying to accomplish. 
>

0
Larry
11/30/2010 6:54:55 PM
Reply: