SQL Replace within LIKE Predicate

Posts   
 
    
Kovan
User
Posts: 19
Joined: 26-Sep-2005
# Posted on: 25-Jun-2007 16:44:16   

I am trying to do something rather obscure, and I wanted to ask before i run of to do a custom predicate like one we previously did for soundex. so here is what I am trying todo.

we have a phone field that is free form string so phone numbers can be entered in any format. we would like to do a LIKE predicate on this by removing ALL non numerical characters first then the LIKE predicate would work if we pass 1239996666 when the field might actually have 123-999-6666 or 123-9996666 so what am really asking is, can we some how apply SQL Replace function to the field before the actual LIKE predicate takes place?

I am using version 1.0.2004 (October 21 2005) version.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 25-Jun-2007 17:00:21   

Hello,

you can call a database function(so the replace function) using the 'new DbFunctionCall' object. The DbFunctionCall can be set to a field's ExpressionToApply property or can be add to an existing Expression.You can find somes examples in the documentation (Using the Generated code -> Calling a database function)

Kovan
User
Posts: 19
Joined: 26-Sep-2005
# Posted on: 25-Jun-2007 17:12:58   

I am using v1.0 and I dont think this object is available. am also using SelfServing on the v1.0.2004

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Jun-2007 05:49:12   

I'm afraid that is not possible for v1.0.2004.x So I would recommend you to use a DBView mapped to a ListView LLBLGen object. I also motivate you to move on across the newest version of LLBLGenPro and enjoy the coolest new features of this tool wink

David Elizondo | LLBLGen Support Team
Kovan
User
Posts: 19
Joined: 26-Sep-2005
# Posted on: 26-Jun-2007 15:13:55   

can you elaborate further? I am not sure views will work either because the phone entity relates to customer entity and Relation object is created between the two so am not exactly sure how view would properly work.

Let me give more details on the problem upto now we created search functionality that allowed one to search for customers based on their phone number and other fields. (obviosly adding RelationsCollection to link phones to customers) and now we want to change the LIKE predicate we been using for the phone to be taking into consideration the mentioned problem. so with the relations in mind, am not exactly sure if this isgonna be possible tod o with a view, if it is please give me details on what needs to be done, so far the only way i feel this is possibleis to create a custom predicate, i really dont want to do that if this is not necessary.

thanks

As for upgrading... its out of the question for us, too many breaking changes for a MASSIVE project we have done, although we will be using thew new llblgen for new projects, thats for sure

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 27-Jun-2007 10:46:28   

You can always implement yuor custom LIKE predicate class. Please check the runtime lib sourcecode which contains the FieldLikePredicate class. Make a copy of it, name it differently and alter the sourcecode so it emits what you want.

Then, in your filters, simply add instances of that predicate class instead of the original like predicate simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Jun-2007 10:49:54   

As for upgrading... its out of the question for us, too many breaking changes for a MASSIVE project we have done, although we will be using thew new llblgen for new projects, thats for sure

At least you can migrate to v.1.0.2005.x and there won't be such breaking changes.

can you elaborate further? I am not sure views will work either because the phone entity relates to customer entity and Relation object is created between the two so am not exactly sure how view would properly work.

I think David ment you can create a view of the Phone table in which you would remove or replace any unwanted characters. Then you can map this view to an entity, and define the relation between this entity and the customer table in the Designer.

Kovan
User
Posts: 19
Joined: 26-Sep-2005
# Posted on: 27-Jun-2007 14:59:02   

Otis wrote:

You can always implement yuor custom LIKE predicate class. Please check the runtime lib sourcecode which contains the FieldLikePredicate class. Make a copy of it, name it differently and alter the sourcecode so it emits what you want.

Then, in your filters, simply add instances of that predicate class instead of the original like predicate simple_smile

was trying to avoid doing that as stated first.. but i guess there is no other way at least u provide source, or i would be cursing like there is no tomorrow simple_smile