Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Seems Mojo is pretty different from CGI in passing form parameters with GET.

Not really, also has an OO interface with a ->param method. Everything else is different, though :-)

How to make make it do partial matching (and possibly case insensitive)

That's more of an SQL question; it will depend on the database you're using. The most important thing is that if you build SQL queries yourself, you need to be very careful to quote everything correctly, usually using either placeholders or DBI's ->quote method, which in my code above you can access via $c->sqlite->db->dbh->quote(...) (or app->sqlite->...).

SQLite and DBD::SQLite supports an extension called FTS5 that might be helpful to you. For example, if in my code you replace the CREATE TABLE with this:

CREATE VIRTUAL TABLE contacts USING fts5(name, department); INSERT INTO contacts (name,department) VALUES ('John Doe','Perl'); INSERT INTO contacts (name,department) VALUES ('Larry Wall','Perl'); INSERT INTO contacts (name,department) VALUES ('Gloria Wall','Perl');

And the $c->stash( rows => ... value with this:

$c->sqlite->db->query( q{ SELECT rowid,name,department FROM contacts WHERE name MATCH ? }, $c->stash('query') )->arrays );

Then you get the full power of the FTS5 extension, e.g. your query can be john OR larry, g*, etc. and it'll just work.

Edit: Typo fix.

In reply to Re^3: Mojo database routing by haukex
in thread Mojo database routing by rajaman

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-05-27 12:58 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (95 votes). Check out past polls.