CUBRID Engine  latest
esql_whenever.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * esql_whenever.c - Routines for preprocessor handling of whenever conditions.
21  */
22 
23 #ident "$Id$"
24 
25 #include <stdlib.h>
26 #include "misc_string.h"
27 #include "esql_misc.h"
28 #include "memory_alloc.h"
29 #include "esql_translate.h"
30 
31 
33 
35 
36 #define LAST_REF(condition) \
37  ((name = scope->cond[condition].name) != NULL \
38  && (new_scope == NULL || name != new_scope->cond[condition].name))
39 
40 static void
42 {
43  char *name;
44 
45  if (LAST_REF (SQLWARNING))
46  {
47  free_and_init (name);
48  }
49  if (LAST_REF (SQLERROR))
50  {
51  free_and_init (name);
52  }
53  if (LAST_REF (NOT_FOUND))
54  {
55  free_and_init (name);
56  }
57 }
58 
59 /*
60  * pp_init_whenever_scope() - Allocate a new whenever scope block,
61  * initializing it from the old scope.
62  * return : void
63  * scope(in) :
64  * old_scope(in) : A pointer to another scope block.
65  */
66 void
68 {
69  if (old_scope == NULL)
70  {
72  }
73  /*
74  * note : this copies any existing pointers to names associated
75  * with GOTO and CALL actions, so you can't just blindly free_and_init()
76  * the pointers when the scope is exited.
77  */
78  *scope = *old_scope;
79 }
80 
81 /*
82  * pp_finish_whenever_scope() - Deallocate the scope if necessary,
83  * and free all strings it holds.
84  * return : void
85  * scope(in): A pointer to a scope to be freed.
86  * new_scope(in):
87  */
88 void
90 {
91 
92  free_last_referenced_name (scope, new_scope);
93 
94  if (new_scope == NULL)
95  {
97  }
98 
102 }
ESQL_TRANSLATE_TABLE esql_Translate_table
void pp_init_whenever_scope(WHENEVER_SCOPE *scope, WHENEVER_SCOPE *old_scope)
Definition: esql_whenever.c:67
void(* tr_whenever)(WHEN_CONDITION condition, WHEN_ACTION action, const char *name)
WHEN_ACTION action
Definition: esql_misc.h:101
#define NULL
Definition: freelistheap.h:34
void pp_finish_whenever_scope(WHENEVER_SCOPE *scope, WHENEVER_SCOPE *new_scope)
Definition: esql_whenever.c:89
static void free_last_referenced_name(WHENEVER_SCOPE *scope, WHENEVER_SCOPE *new_scope)
Definition: esql_whenever.c:41
#define LAST_REF(condition)
Definition: esql_whenever.c:36
#define free_and_init(ptr)
Definition: memory_alloc.h:147
static WHENEVER_SCOPE default_whenever_scope_initializer
Definition: esql_whenever.c:34
WHENEVER_ACTION cond[3]
Definition: esql_misc.h:107