Debugging an SQL Query
Posted by mkhairul - November 12, 2008 at 11:11:26 pm -Categories: Tips, Troubleshoot, blog, code
So, I debugged an error for a good friend recently. Only certain kind of item would be displayed, everything else was not found in the search. The first thing I suspect is the SQL Query. I printed out the SQL Query and tried to debug it.
The first thing I did is to arrange the SQL Query in a readable manner.
Since I do not have the time to follow the trail from the SQL Query manually, I just comment out 3 conditions at a time, and add a condition each time until the item was found. In the above picture, I’ve found the culprit its the one below the commented out line.
When I commented out the line, the results for the keyword appeared as follow.
So thats the divide and conquer part. So now I know the problem is with the commented out criteria and the one below it. I traced it back to its table (products_to_categories) and found out that the category_id value is empty. Thats why it can’t join in with the categories table and thus there’s no result.
So what did I do? I told my friend about the problem, explained it to him (I gave him a couple of screenshots to explain the problem) and gives him a solution. UPDATE products_to_categories SET categories_id = xx. So that all the item have a category and will be displayed when it is searched by the application.
Erm, yeah. Thats about it.
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.



