Sybase ASE
All versions
Last updated: 26 January 2020
ASE Quiz Questions: answers 2013
 
More ASE quiz questions: 2013 - 2012 - 2011 - 2010 - 2009 - 2008 - 2007 - 2006 - 2005 - 2004 - 2003 - 2002 - 2001
For a randomly selected quiz question, click here.


January 2020
Recently I noticed the following lines in an ASE customer's application (the procedure was not called 'myproc', I simplified it for this quiz question):
   if @flag = 3
      exec myproc 
   endif	

I was confused at first. Does ASE secretely support the IF...ENDIF syntax or there something else going on?

Answer:
At first sight, this looks like the type of IF-THEN-ENDIF syntax found in other databases than ASE. However, when you try to run a little test, you'll find that syntax is not valid in ASE.
Yet, the customer's code was valid and running. This was certainly puzzling.

To give the answer straightaway: the reason why the code works, is that 'endif' is interpreted as a string that is passed as a parameter to the procedure.
It is really the indentation that suggests the IF-THEN-ENDIF syntax -- but note that there is no THEN keyword at all.

To dig a little bit deeper, this code also works because of two other reasons. First, the procedure was actually declared without parameters, and ASE simply ignores any parameters that are specified in excess. So chances are the original programmer never noticed the 'endif'. If the procedure has been declared with a VARCHAR parameter, it would also have been valid syntax, but I guess passing a value 'endif' as an actual parameter would have alerted the programmer to the problem.
Second, the reason why this is valid syntax is that it is not always mandatory to put quotes around a string in ASE - this is why
sp_help mytable
works in the first place.

In conclusion, my best guess is that the programmer made a cut/paste error. But for the reasons explained above, it never caused an actual error in ASE.

How would you rate this ASE quiz question?
Great    OK    Average    Boring     


More ASE quiz questions: 2013 - 2012 - 2011 - 2010 - 2009 - 2008 - 2007 - 2006 - 2005 - 2004 - 2003 - 2002 - 2001
For a randomly selected quiz question, click here.


 
 This document is located at www.sypron.nl/quiz2013a.html