Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hello all

I'm sorry if this post is long, I'm trying to provide enough data to examplin my problem. I have some database tables which contain some columns, for example:

/----------------------\ | TYPE | STYPE | OTHER | \----------------------/


The data stored within these columns is something I have to use to make a SQL query. The values stored in these tables can be simple, like

/----------------------\ | TYPE | STYPE | OTHER | |----------------------| | AAA | BBB | X=CCC | \----------------------/


The desired output for this would be
select * from targettablename where type='AAA' and stype='BBB' and x=' +CCC';

Col OTHER inclues a key value pair. So far so good? Now the syntax for things like wildcard searches and or in the existing tables is like
/-----------------------------\ | TYPE | STYPE | OTHER | |-----------------------------| | AA|BB | BB% | X=CC%&Y=DDD | |-----------------------------| | AA|BB | | X=CC%&Y=DDD | |-----------------------------| | AA | BB% | X=CC%&Y=DD% | \-----------------------------/

The SQL query these should generate are:
select * from targettablename where type in ('AA','BB') and stype like + 'BB%' and X like 'CC%' and y='DDD'; select * from targettablename where type in ('AA','BB') and X like 'CC +%' and y='DDD'; select * from targettablename where type = 'AA' and stype like 'BB%' a +nd X like 'CC%' and y like 'DD%';

So as you can see this could end up pretty complex, each column value may have multiple likes or 'ors', and the others col contains key value pairs which may also have various types of searching. I'm investigating a generic solution which can generate proper SQL queries for each entry in this table. At the moment I'm a little lost as to how to actually do this. I know that I need to split any entries in the 'other' column and process them. I'm trying to visualize a generic function to which I can pass the contents of any field (and the split up key value pairs in other). Any advice would be great.

In reply to SQL queries from weird data by Anonymous Monk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (9)
    As of 2014-10-21 04:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (96 votes), past polls