Hi. I use this code to test if a variable exists or not (in this case gnVar)

ALTER TRIGGER  
  ......  
   declare a tinyint;  
   ......  
   begin  
     set gnVar=1;  
     set a=1;  
   exception  
     when others then  
        set a=2;  
   end;  
   if a=1 then  
      --gnVar exists  
   else  
      --gnVar doesn't exist  
   end if;  
   ........  
end  

Is it possible for a to be 1 even if gnVar does not exist (this is the only explanation for some strange data sets)? The code is designed for Sql Anywhere 7 and 9. The problem appeared in Sql Anywhere 9.

Gabriel

asked 19 Jul '12, 09:31

poptcat's gravatar image

poptcat
16113
accept rate: 0%

edited 19 Jul '12, 10:35

Mark%20Culp's gravatar image

Mark Culp
24.9k10139297


The following code works as expected in 7.0.3.2046 and 9.0.2.3951 (the V9 test is shown), so you should look elsewhere for an explanation.

FYI if it actually is a bug in V9, it's not going to get fixed, so version-specific branching to call VAREXISTS() may be the only workaround (VAREXISTS was introduced in 8.0.2).

SELECT @@VERSION;
@@VERSION
'9.0.2.3951'

BEGIN
   declare a tinyint;  
   begin  
     set gnVar=1;  
     set a=1;  
   exception  
     when others then  
        set a=2;  
   end;  
   SELECT a;
end

a
2

CREATE VARIABLE gnVar INTEGER;
BEGIN
   declare a tinyint;  
   begin  
     set gnVar=1;  
     set a=1;  
   exception  
     when others then  
        set a=2;  
   end;  
   SELECT a;
end

a
1
permanent link

answered 19 Jul '12, 10:46

Breck%20Carter's gravatar image

Breck Carter
32.5k5417261050
accept rate: 20%

edited 19 Jul '12, 10:48

Thanks for your answer. I've tested a lot this code, but I don't have other explanation for my problem.

(20 Jul '12, 02:50) poptcat
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×108
×13
×2

question asked: 19 Jul '12, 09:31

question was seen: 1,928 times

last updated: 20 Jul '12, 07:00