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.
-
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 How to display code and escape characters
are good places to start.