jeudi 5 janvier 2017

Trick when dynamically appending GET attributes

When dynamically building SQL queries you often see something like this:

WHEN 1=1 AND title="Example" AND ...

The purpose of the 1=1 is to be able to keep appending AND-statements without having to check if any previous statements exist. Thereby avoiding something like this happening:

WHEN AND title="Example" AND ...

I quite often come across a related issue when building the the attributes/search-query for a GET request. I don't want to keep checking if I need to prepend the attribute with '?' or '&'.

So my question is, is there any 'safe' way for me to add an initial attribute that won't interfere with any potential software on the server side. Assuming I do not have full knowledge of the backend. Something like:

http://ift.tt/2idRBa0
http://ift.tt/2jd2LAc
http://ift.tt/2idRA5W

Or is this allowed?

http://ift.tt/2jcYzAa

Is there perhaps a simpler way to solve this?

Aucun commentaire:

Enregistrer un commentaire