perlquestion
Anonymous Monk
Hello all
<br><br>
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:
<br><br>
<c>
/----------------------\
| TYPE | STYPE | OTHER |
\----------------------/
</c>
<br><br>
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
<br><br>
<c>
/----------------------\
| TYPE | STYPE | OTHER |
|----------------------|
| AAA | BBB | X=CCC |
\----------------------/
</c>
<br><br>
The desired output for this would be
<c>
select * from targettablename where type='AAA' and stype='BBB' and x='CCC';
</c>
<br>
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
<br>
<c>
/-----------------------------\
| TYPE | STYPE | OTHER |
|-----------------------------|
| AA|BB | BB% | X=CC%&Y=DDD |
|-----------------------------|
| AA|BB | | X=CC%&Y=DDD |
|-----------------------------|
| AA | BB% | X=CC%&Y=DD% |
\-----------------------------/
</c>
<br>
The SQL query these should generate are:
<br>
<c>
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%' and X like 'CC%' and y like 'DD%';
</c>
<br>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.
11