Friday, April 22, 2011

Passing SQL String as Query String in Web Applications

I was working on a web page where I had to pass a SQL Query string to another page as query parameter.

When I finished the coding and tested, it was working for some queries and failing for certain. After a close examination I found out it was failing for "LIKE" queries. The query had characters like '%'

For example if the query is like "SELECT FNAME LIKE '%ANA%'" then this will fail. Because the receiving page was unable to pass the query string properly.

After some research I found out there is a javascript function encodeURI() which will encode the query string.

There is also another function decodeURI() which does opposite of encodeURI().

By using these functions I was able to complete the coding.



No comments:

Post a Comment

All Blogs so far ...