CUBRID Engine  latest
cas_sql_log2.h
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 /*
21  * cas_sql_log2.h -
22  */
23 
24 #ifndef _CAS_SQL_LOG2_H_
25 #define _CAS_SQL_LOG2_H_
26 
27 #ident "$Id$"
28 
29 #define SQL_LOG2_NONE 0
30 #define SQL_LOG2_PLAN 1
31 #define SQL_LOG2_HISTO 2
32 #define SQL_LOG2_MAX (SQL_LOG2_PLAN | SQL_LOG2_HISTO)
33 
34 #if defined(WINDOWS) || defined(CAS_FOR_ORACLE) || defined(CAS_FOR_MYSQL) || defined(LIBCAS_FOR_JSP)
35 #define SQL_LOG2_EXEC_BEGIN(SQL_LOG2_VALUE, STMT_ID)
36 #define SQL_LOG2_EXEC_END(SQL_LOG2_VALUE, STMT_ID, RES)
37 #define SQL_LOG2_COMPILE_BEGIN(SQL_LOG2_VALUE, SQL_STMT)
38 #define SQL_LOG2_EXEC_APPEND(SQL_LOG2_VALUE, STMT_ID, RES, PLAN_FILE)
39 #else /* WINDOWS */
40 #define SQL_LOG2_EXEC_BEGIN(SQL_LOG2_VALUE, STMT_ID) \
41  do { \
42  if (SQL_LOG2_VALUE) { \
43  if ((SQL_LOG2_VALUE) & SQL_LOG2_PLAN) { \
44  set_optimization_level(513); \
45  } \
46  sql_log2_write("execute %d", STMT_ID); \
47  if ((SQL_LOG2_VALUE) & SQL_LOG2_HISTO) { \
48  histo_clear(); \
49  } \
50  sql_log2_dup_stdout(); \
51  } \
52  } while (0)
53 
54 #define SQL_LOG2_EXEC_END(SQL_LOG2_VALUE, STMT_ID, RES) \
55  do { \
56  if (SQL_LOG2_VALUE) { \
57  if ((SQL_LOG2_VALUE) & SQL_LOG2_HISTO) { \
58  histo_print(NULL); \
59  } \
60  printf("\n"); \
61  sql_log2_flush(); \
62  sql_log2_restore_stdout(); \
63  sql_log2_write("execute %d : %d", STMT_ID, RES); \
64  reset_optimization_level_as_saved(); \
65  } \
66  } while (0)
67 
68 #define SQL_LOG2_COMPILE_BEGIN(SQL_LOG2_VALUE, SQL_STMT) \
69  do { \
70  if (SQL_LOG2_VALUE) { \
71  sql_log2_write("compile : %s", SQL_STMT); \
72  } \
73  } while (0)
74 
75 #define SQL_LOG2_EXEC_APPEND(SQL_LOG2_VALUE, STMT_ID, RES, PLAN_FILE) \
76  do { \
77  if (SQL_LOG2_VALUE) { \
78  sql_log2_write("execute %d", STMT_ID); \
79  sql_log2_append_file(PLAN_FILE); \
80  sql_log2_write("execute %d : %d", STMT_ID, RES); \
81  } \
82  } while (0)
83 #endif /* !WINDOWS */
84 
85 extern void sql_log2_init (char *br_name, int index, int sql_log2_value, bool log_reuse_flag);
86 extern char *sql_log2_get_filename (void);
87 extern void sql_log2_dup_stdout (void);
88 extern void sql_log2_restore_stdout (void);
89 extern void sql_log2_end (bool reset_filename_flag);
90 extern void sql_log2_flush (void);
91 extern void sql_log2_write (const char *fmt, ...);
92 extern void sql_log2_append_file (char *file_name);
93 
94 #endif /* _CAS_SQL_LOG2_H_ */
void sql_log2_dup_stdout(void)
Definition: cas_sql_log2.c:94
void sql_log2_write(const char *fmt,...)
Definition: cas_sql_log2.c:140
void sql_log2_init(char *br_name, int index, int sql_log2_value, bool log_reuse_flag)
Definition: cas_sql_log2.c:53
void sql_log2_end(bool reset_filename_flag)
Definition: cas_sql_log2.c:118
char * sql_log2_get_filename(void)
Definition: cas_sql_log2.c:84
void sql_log2_restore_stdout(void)
Definition: cas_sql_log2.c:106
void sql_log2_flush(void)
Definition: cas_sql_log2.c:132
void sql_log2_append_file(char *file_name)
Definition: cas_sql_log2.c:165