Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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
[Discipulus]: my warmest comprehension karlgoethebier ;=(
[Discipulus]: yes LanX.. is so good to be appreciated (I fortunately have a big self estimation that compensate)
[LanX]: you can manipulate a html tree by addressing and replacing so called document objects (DOM) and from my experience the same methods can be used with any XML, though I didn't test all browsers yet
LanX just joking, playing "ego judo"
[marto]: good morning all
[Corion]: Hi marto!
[marto]: the race to the bottom continues, many people lost their job yesterday as a client moves to another outsourcer
[LanX]: brexit or perlxit ?

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-03-23 09:54 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (285 votes). Check out past polls.