• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Validating Field names

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My criteriaFind() method does not validate each of the field names in the criteria string seperately. Instaed it checks the whole record for name-value pair in the criteria string. It will return an empty DataInfo [] object if the field name is wrong or the criteria String is not valid. Is this approach good??
Also, the field names in the criteria String must exactly match with the field names of the record. So the criteria "Origin='SFO'" will get an empty DataInfo array.(Only "Origin airpot='SFO'" is valid).
Please let me know if anything is wrong...
Thanks
Padmaja
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Padmaja,
My requirements state:

Note that only exact matches need to be handled in this criteriaFind(String) method./QUOTE]so I'd say you're mostly all right. I think it would be fair (though I don't do it this way) to define "Origin" as a field name, however.

Originally posted by Padmaja Prasad:
Also, the field names in the criteria String must exactly match with the field names of the record. So the criteria "Origin='SFO'" will get an empty DataInfo array.(Only "Origin airpot='SFO'" is valid).
Please let me know if anything is wrong...

Yes... I believe "Origin airpot" (unless you're trying to smuggle marijuana in your luggage).

 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Obviously this forum software is in need of non-greedy regular expressions...
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Padmaja,


My criteriaFind() method does not validate each of the field names in the criteria string seperately. Instaed it checks the whole record for name-value pair in the criteria string. It will return an empty DataInfo [] object if the field name is wrong or the criteria String is not valid. Is this approach good??


That's probably OK but may not be as efficient as verifying the field names first since you can short-circuit the search on the first invalid field. Also, how do you handle an ANY situation? It seems to me that yours is an additive method as opposed to the easier subtractive method of gathering the matching records.


Also, the field names in the criteria String must exactly match with the field names of the record. So the criteria "Origin='SFO'" will get an empty DataInfo array.(Only "Origin airpot='SFO'" is valid).
Please let me know if anything is wrong...


That's fine. That's exactly what I did. Since it is assumed that your program builds the criteria, that should always work.
Hope this helps,
Michael Morris
 
Padmaja Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
I apologise for mis-spelling airport.

Originally posted by Michael Morris:
That's probably OK but may not be as efficient as verifying the field names first since you can short-circuit the search on the first invalid field. Also, how do you handle an ANY situation? It seems to me that yours is an additive method as opposed to the easier subtractive method of gathering the matching records.


Hi Michael, I am constructing HashMaps that maps field name with data value for both the criteria string and every record in DB and then comparing their entrySets(using containsAll()). (Not using the for loop for finding the record match)
I'm handling ANY condition like this :
I'm not adding the field to the criteria string if it has ANY value. If the criteria String is empty, then before constructing the Maps, it'll simply return getAllRecords()(method defined in Data which returns an array of DataInfo containg all records).


That's fine. That's exactly what I did. Since it is assumed that your program builds the criteria, that should always work.
Hope this helps,
Michael Morris


Thank you so much, Your advise & guidence really helps me a lot.
Thanks
Padmaja
[ September 27, 2002: Message edited by: Padmaja Prasad ]
 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm...

Originally posted by Thomas Fly:
P.S. Obviously this forum software is in need of non-greedy regular expressions...


Originally posted by Thomas Fly:
P.S. Obviously this forum software is in need of non-greedy regular expressions...


Maybe the forum software just needs a preview capability...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Padmaja,


I am constructing HashMaps that maps field name with data value for both the criteria string and every record in DB and then comparing their entrySets(using containsAll()). (Not using the for loop for finding the record match)
I'm handling ANY condition like this :
I'm not adding the field to the criteria string if it has ANY value. If the criteria String is empty, then before constructing the Maps, it'll simply return getAllRecords()(method defined in Data which returns an array of DataInfo containg all records).


That's essentially what I did so I guess I was just a little confused on your initial post.
Michael Morris
 
Do not threaten THIS beaver! Not even with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic