CUBRID Engine  latest
session_sr.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  * session_sr.c - Session management on the server
21  */
22 
23 #include "session.h"
24 
25 #include "dbtype.h"
26 #include "xasl.h"
27 #include "xasl_cache.h"
28 #include "xserver_interface.h"
29 
30 /*
31  * xsession_create_new () - create a new session
32  * return : error code
33  * id (in/out) : session id
34  * Note: this function allocates a new session id and creates a session for
35  * it
36  */
37 int
39 {
40  assert (id != NULL);
41 
42  return session_state_create (thread_p, id);
43 }
44 
45 /*
46  * xsession_check_session () - validates the session with session_id
47  * return : error code
48  * id (in) : session id
49  * Note: this function checks if the session with session_id is still active
50  * and updates the last access timeout for it
51  */
52 int
54 {
55  return session_check_session (thread_p, id);
56 }
57 
58 /*
59  * xsession_end_session () - end the session with session_id
60  * return : error code
61  * id (in) : session id
62  * thread_p (in)
63  */
64 int
66 {
67  return session_state_destroy (thread_p, id);
68 }
69 
70 /*
71  * xsession_set_row_count () - set the count of affected rows for the
72  * session associated to thread_p
73  * return : error code
74  * thread_p (in) : worker thread
75  * row_count(in) : affected rows count
76  */
77 int
78 xsession_set_row_count (THREAD_ENTRY * thread_p, int row_count)
79 {
80  return session_set_row_count (thread_p, row_count);
81 }
82 
83 /*
84  * xsession_get_row_count () - get the count of affected rows for the
85  * session associated to thread_p
86  * return : error code
87  * thread_p (in) : worker thread
88  * row_count(out): affected rows count
89  */
90 int
91 xsession_get_row_count (THREAD_ENTRY * thread_p, int *row_count)
92 {
93  return session_get_row_count (thread_p, row_count);
94 }
95 
96 /*
97  * xsession_set_cur_insert_id () - set the value of current insert id
98  *
99  * return : error code
100  * thread_p (in) : worker thread
101  * value (in) : the value of last insert id
102  * force (in) : update the value unconditionally
103  *
104  */
105 int
106 xsession_set_cur_insert_id (THREAD_ENTRY * thread_p, const DB_VALUE * value, bool force)
107 {
108  int err = NO_ERROR;
109 
110  assert (value != NULL);
111 
112  err = session_set_cur_insert_id (thread_p, value, force);
113 
114  return err;
115 }
116 
117 /*
118  * xsession_get_last_insert_id () - retrieve the value of the last insert id
119  *
120  * return : error code
121  * thread_p (in) : worker thread
122  * value (out) : the value of last insert id
123  * update_last_insert_id(in): whether update the last insert id
124  */
125 int
126 xsession_get_last_insert_id (THREAD_ENTRY * thread_p, DB_VALUE * value, bool update_last_insert_id)
127 {
128  int err = NO_ERROR;
129 
130  assert (value != NULL);
131 
132  err = session_get_last_insert_id (thread_p, value, update_last_insert_id);
133  if (err != NO_ERROR)
134  {
135  db_make_null (value);
136  }
137  return err;
138 }
139 
140 /*
141  * xsession_reset_cur_insert_id () - reset current insert id as NULL
142  *
143  * return : error code
144  * thread_p (in) : worker thread
145  */
146 int
148 {
149  int err = NO_ERROR;
150 
151  err = session_reset_cur_insert_id (thread_p);
152 
153  return err;
154 }
155 
156 /*
157  * xsession_create_prepared_statement () - create a prepared statement and add it to the prepared statements list
158  * return : NO_ERROR or error code
159  * thread_p (in) : thread entry
160  * name (in) : the name of the statement
161  * alias_print(in) : the printed compiled statement
162  * info (in) : serialized prepared statement info
163  * info_len (in) : serialized buffer length
164  *
165  * Note: This function assumes that the memory for its arguments was
166  * dynamically allocated and does not copy the values received. It's important
167  * that the caller never frees this memory. If an error occurs, this function
168  * will free the memory allocated for its arguments
169  */
170 int
171 xsession_create_prepared_statement (THREAD_ENTRY * thread_p, char *name, char *alias_print, SHA1Hash * sha1, char *info,
172  int info_len)
173 {
174  return session_create_prepared_statement (thread_p, name, alias_print, sha1, info, info_len);
175 }
176 
177 /*
178  * xsession_get_prepared_statement () - get the information about a prepared
179  * statement
180  * return : NO_ERROR or error code
181  * thread_p (in) :
182  * name (in) : the name of the statement
183  * name (in) : the name of the prepared statement
184  * info (out) : serialized prepared statement information
185  * info_len (out) : serialized buffer length
186  * xasl_id (out) : XASL ID for this statement
187  * xasl_header_p (out) : XASL node header for this statement.
188  */
189 int
190 xsession_get_prepared_statement (THREAD_ENTRY * thread_p, const char *name, char **info, int *info_len,
191  XASL_ID * xasl_id, xasl_node_header * xasl_header_p)
192 {
193  XASL_CACHE_ENTRY *xasl_entry = NULL;
194  int error = NO_ERROR;
195 
196  assert (xasl_id != NULL);
197 
198  XASL_ID_SET_NULL (xasl_id);
199  error = session_get_prepared_statement (thread_p, name, info, info_len, &xasl_entry);
200  if (error != NO_ERROR)
201  {
202  ASSERT_ERROR ();
203  assert (xasl_entry == NULL);
204  return error;
205  }
206  if (xasl_entry != NULL)
207  {
208  XASL_ID_COPY (xasl_id, &xasl_entry->xasl_id);
209 
210  if (xasl_header_p != NULL)
211  {
212  /* get XASL node header from XASL stream */
213  qfile_load_xasl_node_header (thread_p, xasl_entry->stream.buffer, xasl_header_p);
214  }
215 
216  xcache_unfix (thread_p, xasl_entry);
217  }
218  else
219  {
221  }
222 
223  return error;
224 }
225 
226 /*
227  * xsession_delete_prepared_statement () - delete a prepared statement
228  * return : error code or NO_ERROR
229  * thread_p (in) :
230  * name (in) : name of the prepared statement
231  */
232 int
233 xsession_delete_prepared_statement (THREAD_ENTRY * thread_p, const char *name)
234 {
235  return session_delete_prepared_statement (thread_p, name);
236 }
237 
238 /*
239  * xlogin_user () - login user
240  * return : error code or NO_ERROR
241  * thread_p (in) :
242  * username (in) : name of the prepared statement
243  */
244 int
245 xlogin_user (THREAD_ENTRY * thread_p, const char *username)
246 {
247  return login_user (thread_p, username);
248 }
249 
250 /*
251  * xsession_set_session_variables () - set session variables
252  * return : error code
253  * thread_p (in) : worker thread
254  * values (in) : array of variables to set
255  * count (in) : number of elements in array
256  */
257 int
259 {
260  return session_set_session_variables (thread_p, values, count);
261 }
262 
263 /*
264  * xsession_get_session_variable () - get the value of a session variable
265  * return : int
266  * thread_p (in) : worker thread
267  * name (in) : name of the variable
268  * value (out) : variable value
269  */
270 int
271 xsession_get_session_variable (THREAD_ENTRY * thread_p, const DB_VALUE * name, DB_VALUE * value)
272 {
273  return session_get_variable (thread_p, name, value);
274 }
275 
276 /*
277  * xsession_get_session_variable_no_copy () - get the value of a session
278  * variable
279  * return : int
280  * thread_p (in) : worker thread
281  * name (in) : name of the variable
282  * value (in/out): variable value
283  * Note: This function gets a reference to a session variable from the session
284  * state object. Because it gets the actual pointer, it is not thread safe
285  * and it should only be called in the stand alone mode
286  */
287 int
289 {
290 #if defined (SERVER_MODE)
291  /* do not call this function in a multi-threaded context */
292  assert (false);
293  return ER_FAILED;
294 #endif
295  return session_get_variable_no_copy (thread_p, name, value);
296 }
297 
298 /*
299  * xsession_drop_session_variables () - drop session variables
300  * return : error code or NO_ERROR
301  * thread_p (in) : worker thread
302  * values (in) : names of the variables to drop
303  * count (in) : number of elements in the values array
304  */
305 int
307 {
308  return session_drop_session_variables (thread_p, values, count);
309 }
310 
311 /*
312  * xsession_store_query_entry_info () - create a query entry
313  * return : void
314  * thread_p (in) :
315  * qentry_p (in) : query entry
316  */
317 void
319 {
320  session_store_query_entry_info (thread_p, qentry_p);
321 }
322 
323 /*
324  * xsession_load_query_entry_info () - search for a query entry
325  * return : error code or NO_ERROR
326  * thread_p (in) :
327  * qentry_p (in/out) : query entry
328  */
329 int
331 {
332  return session_load_query_entry_info (thread_p, qentry_p);
333 }
334 
335 /*
336  * xsession_remove_query_entry_info () - remove a query entry from the
337  * holdable queries list
338  * return : error code or NO_ERROR
339  * thread_p (in) : active thread
340  * query_id (in) : query id
341  */
342 int
343 xsession_remove_query_entry_info (THREAD_ENTRY * thread_p, const QUERY_ID query_id)
344 {
345  return session_remove_query_entry_info (thread_p, query_id);
346 }
347 
348 /*
349  * xsession_remove_query_entry_info () - remove a query entry from the
350  * holdable queries list but do not
351  * close the associated list files
352  * return : error code or NO_ERROR
353  * thread_p (in) : active thread
354  * query_id (in) : query id
355  */
356 int
357 xsession_clear_query_entry_info (THREAD_ENTRY * thread_p, const QUERY_ID query_id)
358 {
359  return session_clear_query_entry_info (thread_p, query_id);
360 }
361 
362 /*
363  * xsession_set_tran_auto_commit () - set transaction auto commit state
364  *
365  * return : NO_ERROR or error code
366  * thread_p(in) : thread
367  * auto_commit(in) : auto commit
368  */
369 int
370 xsession_set_tran_auto_commit (THREAD_ENTRY * thread_p, bool auto_commit)
371 {
372  return session_set_tran_auto_commit (thread_p, auto_commit);
373 }
Definition: sha1.h:50
int login_user(THREAD_ENTRY *thread_p, const char *username)
Definition: session.c:1917
#define NO_ERROR
Definition: error_code.h:46
int xsession_get_last_insert_id(THREAD_ENTRY *thread_p, DB_VALUE *value, bool update_last_insert_id)
Definition: session_sr.c:126
int xsession_load_query_entry_info(THREAD_ENTRY *thread_p, QMGR_QUERY_ENTRY *qentry_p)
Definition: session_sr.c:330
int session_get_last_insert_id(THREAD_ENTRY *thread_p, DB_VALUE *value, bool update_last_insert_id)
Definition: session.c:1381
#define ASSERT_ERROR()
int xsession_set_tran_auto_commit(THREAD_ENTRY *thread_p, bool auto_commit)
Definition: session_sr.c:370
int session_state_create(THREAD_ENTRY *thread_p, SESSION_ID *id)
Definition: session.c:637
int session_get_variable(THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE *result)
Definition: session.c:2003
int xsession_get_session_variable(THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE *value)
Definition: session_sr.c:271
#define ER_FAILED
Definition: error_code.h:47
void qfile_load_xasl_node_header(THREAD_ENTRY *thread_p, char *xasl_stream, xasl_node_header *xasl_header_p)
Definition: list_file.c:1063
int session_check_session(THREAD_ENTRY *thread_p, const SESSION_ID id)
Definition: session.c:810
int session_remove_query_entry_info(THREAD_ENTRY *thread_p, const QUERY_ID query_id)
Definition: session.c:2556
int xsession_clear_query_entry_info(THREAD_ENTRY *thread_p, const QUERY_ID query_id)
Definition: session_sr.c:357
int session_clear_query_entry_info(THREAD_ENTRY *thread_p, const QUERY_ID query_id)
Definition: session.c:2601
int xsession_create_prepared_statement(THREAD_ENTRY *thread_p, char *name, char *alias_print, SHA1Hash *sha1, char *info, int info_len)
Definition: session_sr.c:171
int session_load_query_entry_info(THREAD_ENTRY *thread_p, QMGR_QUERY_ENTRY *qentry_p)
Definition: session.c:2525
int session_reset_cur_insert_id(THREAD_ENTRY *thread_p)
Definition: session.c:1473
int session_drop_session_variables(THREAD_ENTRY *thread_p, DB_VALUE *values, const int count)
Definition: session.c:2157
void THREAD_ENTRY
int xsession_set_session_variables(THREAD_ENTRY *thread_p, DB_VALUE *values, const int count)
Definition: session_sr.c:258
XASL_STREAM stream
Definition: xasl_cache.h:94
void xsession_store_query_entry_info(THREAD_ENTRY *thread_p, QMGR_QUERY_ENTRY *qentry_p)
Definition: session_sr.c:318
int xsession_get_prepared_statement(THREAD_ENTRY *thread_p, const char *name, char **info, int *info_len, XASL_ID *xasl_id, xasl_node_header *xasl_header_p)
Definition: session_sr.c:190
#define XASL_ID_COPY(X1, X2)
Definition: xasl.h:562
#define assert(x)
int session_get_prepared_statement(THREAD_ENTRY *thread_p, const char *name, char **info, int *info_len, xasl_cache_ent **xasl_entry)
Definition: session.c:1786
int xsession_get_session_variable_no_copy(THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE **value)
Definition: session_sr.c:288
int xsession_set_cur_insert_id(THREAD_ENTRY *thread_p, const DB_VALUE *value, bool force)
Definition: session_sr.c:106
void xcache_unfix(THREAD_ENTRY *thread_p, XASL_CACHE_ENTRY *xcache_entry)
Definition: xasl_cache.c:1083
int xsession_end_session(THREAD_ENTRY *thread_p, const SESSION_ID id)
Definition: session_sr.c:65
XASL_ID xasl_id
Definition: xasl_cache.h:92
#define NULL
Definition: freelistheap.h:34
int xsession_remove_query_entry_info(THREAD_ENTRY *thread_p, const QUERY_ID query_id)
Definition: session_sr.c:343
#define err(fd,...)
Definition: porting.h:431
int session_get_variable_no_copy(THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE **result)
Definition: session.c:2069
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
static void error(const char *msg)
Definition: gencat.c:331
STATIC_INLINE void perfmon_inc_stat(THREAD_ENTRY *thread_p, PERF_STAT_ID psid) __attribute__((ALWAYS_INLINE))
int session_set_tran_auto_commit(THREAD_ENTRY *thread_p, bool auto_commit)
Definition: session.c:3097
int xlogin_user(THREAD_ENTRY *thread_p, const char *username)
Definition: session_sr.c:245
int session_set_row_count(THREAD_ENTRY *thread_p, const int row_count)
Definition: session.c:1586
int xsession_create_new(THREAD_ENTRY *thread_p, SESSION_ID *id)
Definition: session_sr.c:38
int session_create_prepared_statement(THREAD_ENTRY *thread_p, char *name, char *alias_print, SHA1Hash *sha1, char *info, int info_len)
Definition: session.c:1674
int xsession_reset_cur_insert_id(THREAD_ENTRY *thread_p)
Definition: session_sr.c:147
unsigned int SESSION_ID
Definition: dbtype_def.h:480
int xsession_drop_session_variables(THREAD_ENTRY *thread_p, DB_VALUE *values, const int count)
Definition: session_sr.c:306
int xsession_set_row_count(THREAD_ENTRY *thread_p, int row_count)
Definition: session_sr.c:78
int xsession_delete_prepared_statement(THREAD_ENTRY *thread_p, const char *name)
Definition: session_sr.c:233
char * buffer
Definition: xasl.h:613
int session_set_cur_insert_id(THREAD_ENTRY *thread_p, const DB_VALUE *value, bool force)
Definition: session.c:1414
void session_store_query_entry_info(THREAD_ENTRY *thread_p, QMGR_QUERY_ENTRY *qentry_p)
Definition: session.c:2440
int db_make_null(DB_VALUE *value)
int session_get_row_count(THREAD_ENTRY *thread_p, int *row_count)
Definition: session.c:1562
int xsession_check_session(THREAD_ENTRY *thread_p, const SESSION_ID id)
Definition: session_sr.c:53
int session_delete_prepared_statement(THREAD_ENTRY *thread_p, const char *name)
Definition: session.c:1865
#define XASL_ID_SET_NULL(X)
Definition: xasl.h:546
int xsession_get_row_count(THREAD_ENTRY *thread_p, int *row_count)
Definition: session_sr.c:91
int session_set_session_variables(THREAD_ENTRY *thread_p, DB_VALUE *values, const int count)
Definition: session.c:1939
int session_state_destroy(THREAD_ENTRY *thread_p, const SESSION_ID id)
Definition: session.c:741