CUBRID Engine  latest
set_scan.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  * set_scan.c - Routines to implement set based derived tables.
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <string.h>
28 
29 #include "set_scan.h"
30 
31 #include "dbtype.h"
32 #include "fetch.h"
33 #include "xasl.h"
34 
35 /*
36  * qproc_next_set_scan () -
37  * return: SCAN_CODE
38  * s_id(in) : s_id: Scan identifier
39  *
40  * Note: Move the current element to the next element in the set. Signal
41  * scan end if at the end of the set.
42  */
45 {
46  SET_SCAN_ID *set_id = &s_id->s.ssid;
47  REGU_VARIABLE *func;
48  DB_SET *setp;
49 
50  func = set_id->set_ptr;
51  if (func->type == TYPE_FUNC && func->value.funcp->ftype == F_SEQUENCE)
52  {
53  /* if its the empty set, return end of scan */
54  if (set_id->operand == NULL)
55  {
56  return S_END;
57  }
58 
59  if (s_id->position == S_BEFORE)
60  {
61  s_id->position = S_ON;
62  set_id->cur_index = 0;
63 
64  db_value_clear (s_id->val_list->valp->val);
65  if (fetch_copy_dbval (thread_p, &set_id->operand->value, s_id->vd, NULL, NULL, NULL,
66  s_id->val_list->valp->val) != NO_ERROR)
67  {
68  return S_ERROR;
69  }
70  return S_SUCCESS;
71  }
72  else if (s_id->position == S_ON)
73  {
74  set_id->cur_index++;
75  if (set_id->cur_index == set_id->set_card)
76  {
77  return S_END;
78  }
79  set_id->operand = set_id->operand->next;
80 
81  db_value_clear (s_id->val_list->valp->val);
82  if (fetch_copy_dbval (thread_p, &set_id->operand->value, s_id->vd, NULL, NULL, NULL,
83  s_id->val_list->valp->val) != NO_ERROR)
84  {
85  return S_ERROR;
86  }
87  return S_SUCCESS;
88  }
89  else if (s_id->position == S_AFTER)
90  {
91  return S_END;
92  }
93  else
94  {
96  return S_ERROR;
97  }
98  }
99  else
100  {
101  /* if its the empty set, return end of scan */
102  if (DB_IS_NULL (&set_id->set))
103  {
104  return S_END;
105  }
106  setp = db_get_set (&set_id->set);
107  if (!setp)
108  {
109  return S_END;
110  }
111  set_id->set_card = db_set_size (setp);
112  if (set_id->set_card == 0)
113  {
114  return S_END;
115  }
116 
117  if (s_id->position == S_BEFORE)
118  {
119  s_id->position = S_ON;
120  set_id->cur_index = 0;
121 
122  db_value_clear (s_id->val_list->valp->val);
123  if (db_set_get (setp, set_id->cur_index, s_id->val_list->valp->val) != NO_ERROR)
124  {
125  return S_ERROR;
126  }
127  return S_SUCCESS;
128  }
129  else if (s_id->position == S_ON)
130  {
131  set_id->cur_index++;
132  if (set_id->cur_index == set_id->set_card)
133  {
134  return S_END;
135  }
136 
137  db_value_clear (s_id->val_list->valp->val);
138  if (db_set_get (setp, set_id->cur_index, s_id->val_list->valp->val) != NO_ERROR)
139  {
140  return S_ERROR;
141  }
142  return S_SUCCESS;
143  }
144  else if (s_id->position == S_AFTER)
145  {
146  return S_END;
147  }
148  else
149  {
151  return S_ERROR;
152  }
153  } /* else */
154 
155 }
regu_variable_node * set_ptr
Definition: scan_manager.h:280
val_descr * vd
Definition: scan_manager.h:350
#define NO_ERROR
Definition: error_code.h:46
DB_COLLECTION * db_get_set(const DB_VALUE *value)
SCAN_CODE
REGU_VARIABLE_LIST next
Definition: regu_var.hpp:221
int fetch_copy_dbval(THREAD_ENTRY *thread_p, REGU_VARIABLE *regu_var, val_descr *vd, OID *class_oid, OID *obj_oid, QFILE_TUPLE tpl, DB_VALUE *dbval)
Definition: fetch.c:4466
SCAN_CODE qproc_next_set_scan(THREAD_ENTRY *thread_p, SCAN_ID *s_id)
Definition: set_scan.c:44
void THREAD_ENTRY
DB_VALUE * val
Definition: xasl.h:196
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
Definition: db_set.h:35
int db_set_get(DB_SET *set, int index, DB_VALUE *value)
Definition: db_set.c:508
REGU_VARIABLE value
Definition: regu_var.hpp:222
#define NULL
Definition: freelistheap.h:34
#define ER_QPROC_UNKNOWN_CRSPOS
Definition: error_code.h:522
SCAN_POSITION position
Definition: scan_manager.h:334
DB_VALUE set
Definition: scan_manager.h:282
int db_set_size(DB_SET *set)
Definition: db_set.c:557
regu_variable_list_node * operand
Definition: scan_manager.h:281
val_list_node * val_list
Definition: scan_manager.h:349
#define ARG_FILE_LINE
Definition: error_manager.h:44
QPROC_DB_VALUE_LIST valp
Definition: xasl.h:207
class regu_variable_node REGU_VARIABLE
Definition: regu_var.hpp:64
union scan_id_struct::@153 s
#define DB_IS_NULL(value)
Definition: dbtype.h:63
int db_value_clear(DB_VALUE *value)
Definition: db_macro.c:1588
SET_SCAN_ID ssid
Definition: scan_manager.h:358