Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Formatting a DBI/MySQL query from HTML form via Perl

by Polyglot (Pilgrim)
on May 21, 2009 at 16:09 UTC ( #765491=perlquestion: print w/replies, xml ) Need Help??
Polyglot has asked for the wisdom of the Perl Monks concerning the following question:

I have been wrestling with this for some time now. I have a form which accepts user input for search terms and for a specific resource (MySQL table) in which to search. Is there a good resource for converting "standard" search terms and operators into a MySQL select query? Barring that, I've come up with a rather complicated regexp solution, but it still fails of working intuitively as it should, especially with the following exceptional searches:
  1. a search with nested parentheses
  2. a search which has been copy/pasted from a paragraph of text including all of the original punctuation
  3. a search with no parentheses but with a combination of AND and OR operators

Currently, each of these exceptions will return either no results (MySQL error), or an improper result set due to an incorrect ordering of terms.

I'm sure someone must have dealt with this before...

Thank you for sharing your tips with us.



  • Comment on Formatting a DBI/MySQL query from HTML form via Perl

Replies are listed 'Best First'.
Re: Formatting a DBI/MySQL query from HTML form via Perl
by Your Mother (Chancellor) on May 21, 2009 at 18:08 UTC

    There is a bit on natural language parsing --> SQL in Object Oriented Perl. I know I've seen someone else's code that worked on the problem too but it was 5 years ago and I don't remember who/where. A casual couple of searches on the CPAN didn't turn up anything complete.

    If I were starting on this from scratch I'd revisit Conway's stuff (it's been years since I read it but his clarity of thought in problem solving is invaluable even if you go a different way in the end) and join the idea with SQL::Abstract.

    When you're done, write some tests and release it! It would great to have available. If I missed something on the CPAN that already touches this problem space, please someone mention it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://765491]
Approved by herveus
and the sunlight beams...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-01-21 15:40 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (228 votes). Check out past polls.