Re: Case Insensitive Index (was Re: Three cheers for 4gl's CONSTRUCT)
Posted in 1995
Carl Uschold (carl@spock) wrote: : There's no way to make construct do a case insensitive search...not without : using all possible cominations of upper and lower case in the constructed : query (ie SM* Sm* sM* and sm*) This list would becomes 2**chars long. A : better solution would be the ablility to create a "case insensitive" index : on a field, so that the values in the index are all upper case for query : purposes, but the field values in the .dat file are mixed case. Then a : query for SM* would bring back all three Smith records. Of course THERE IS. The [Ss][Mm]* expression can be used to match all records beginning with sm, SM, sM, Sm. The Informix Engines recognize "match-either-of-these-characters" expressions, (e.g. [ab], [a-z], [a=0k]). A formatting function can be written to change a string (e.g. smith) to an expression (e.g. [Ss][Mm][Ii][Tt][Hh]). It can then be used inside or after the CONSTRUCT statement. Sample formatting function: function formatExpr(source) define source char(100), # size as required sourceLen smallint, result char(200), # size as required resultLen smallint, chr char(1), # current Character insideExpr smallint, # Inside an existing expression '[]' skipNext smallint, # Escape Sequence '\\' i smallint # loop counter let result = " " # all spaces let sourceLen = length(source) let resultLen = 0 let skipNext = false let insideExpr = false for i = 1 to sourceLen let chr = source[i,i] case when skipNext # Do nothing when insideExpr # Do nothing when chr matches "[A-Za-z]" let resultLen = resultLen + 4 let result[resultLen-3,resultLen] = "[", upshift(chr), downshift(chr), "]" continue for end case let resultLen = resultLen + 1 let result[resultLen] = chr case when skipNext = true let skipNext = false when chr = "\\\\" let skipNext = true when chr = "[" let insideExpr = true when chr = "]" let insideExpr = false end case end for return result end function Sample run: display formatExpr("smith") [Ss][Mm][Ii][Tt][Hh] display formatExpr("[abc] Joe") [abc] [Jj][Oo][Ee] ;,._..___...-''^``--._ |\\, Catalin Badea ```--,,,--, `-_ .`/ ,\\ Senior Technical Architect {\\ ` ``-_' / } Tecsys Inc. ; ; ; `;;' `.;. `.._ ,,,_. ``--.._. cat@tecsys.com ``--..,) ```----...._,) include system "disclaim.4gh"