It's possible. I've never deeply explored SQL::Statement or AnyData, but a generic approach using straight DBI is easy.

Grab the field names of the table (using either DBI's not-completely-supported-by-all-DBMSs metadata functions or a DBMS specific query). Using that list dynamically construct the ‘OR’ section of the WHERE clause.

While that method would do what you're asking for, it's not all that useful a query and quickly becomes very very expensive. The prefered approach for such a query is to use a full text search engine, which is generally DBMS dependent.

A good FTS will allow you to give weightings to fields (such as finding ‘foo’ in the title meaning more than just finding it in the body), search on multiple terms with the option of giving higher weightings when terms are close together, stemming, etc. All with a reasonable cost (I'm talking machine resources).

Many popular RDMBS packages have FTS engines either included or as additions. Oracle has many included tools as well many third party options, MS SQL Server has some FTS included IIRC, MySQL has rather limited FTS capability, and PostgreSQL has a few options (check under contrib/ or OpenFTS which is actually written largely in Perl). DBMSs’ that aren't listed here probably have such options, I just can't remeber or don't know them well enough.

Sorry for the brevity of the reply, but it's late and I don't have time to go into the topic deeply. Hope it helps anyways.


In reply to Re: DBI - Multi-field SQL: *OR* condition w/o specifying field names...possible? by Arguile
in thread DBI - Multi-field SQL: *OR* condition w/o specifying field names...possible? by S_Shrum

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.