Jump to content

Recommended Posts

Hi there, so I'm working on a way to be able to write queries and be able to break them down in to their components. For the project I was working on I needed to do a lot of automatic filtering with dynamic WHERE IN statements and other clauses. So I built a query class that could handle that and wrote my queries using that class. But now I'm trying to go the opposite direct and be able to write the query out and have the script deconstruct it and then construct it back together with the added logic I have going on.

 

I'm having trouble finding any scripts on Google, most deal with the URL Query String. But if anyone has done this before and has an example or knows a script out there that would be a good starting point, please let me know.

 

I have a feeling this will involve a lot of regex. If I can't find anything, I will work on developing it myself but just thought it would be nice to have an example to look through.

 

Any help is appreciated, thank you!

 

Just for example purposes. Something like this

 


$qry = "
SELECT t1.employee,sum(t1.hours) as Hours,t2.labor_classifiation
FROM labor_data t1
LEFT JOIN craft_strings t2
ON t2.id = t1.craft_id
";

//This would be broken down in to
Array('tables'=>Array(
'labor_data'=>Array(
 'fields'=>Array('employee','hours'=>Array('name'=>'Hours','equation'=>'sum'))
 ,'prefix'=>'t1')
))

//that's not the entire array that would come out of it, but you get the picture.

Edited by akphidelt2007

Are you absolutely sure you want to do this? Unless you can find something out there already this will take quite some time to get it right. More time if you want to be able to handle lots of different queries. I doubt this work is really necessary.

 

Deconstruct the manual queries you have by yourself. It may sound like a lot of work but it'll be faster and easier than making this SQL parser thing.

Of course the work can be done with out it. I just thought it would be a neat idea and make some things I do much more efficient. What I'm trying to do is set up a report builder where I can just type up the query and have it break it down to automatically create it's headers, filtering, authentication, classes, ajax, etc. But I guess you are probably right, it would probably end up being easier just to build the tools to be able to construct the query from the inputs rather than just typing the entire query out and regexing the heck out of it.

 

Alright, I'll try this other method first. Thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.