CUBRID Engine  latest
csql.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  * csql.h : header file for csql
21  *
22  */
23 
24 #ifndef _CSQL_H_
25 #define _CSQL_H_
26 
27 #ident "$Id$"
28 
29 #include <errno.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include <sys/stat.h>
34 #include <locale.h>
35 
36 #include "porting.h"
37 #include "language_support.h"
38 #include "message_catalog.h"
39 #include "util_func.h"
40 #include "misc_string.h"
41 #include "dbi.h"
42 #include "error_manager.h"
43 #include "memory_alloc.h"
44 
45 #if defined(WINDOWS)
46 #define isatty(stream) _isatty(stream)
47 #endif /* WINDOWS */
48 
49 #define MSGCAT_CSQL_SET_CSQL 1
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 
56 /*
57  * MESSAGE NUMBERS
58  */
59  enum
60  {
67 
91  CSQL_ROWS = 70,
92  CSQL_ROW = 71,
96  CSQL_NAME = 80,
100 
120 
150  };
151 
152 #define SCRATCH_TEXT_LEN (4096)
153 
154 /* error codes defined in csql level */
155  enum
156  {
173  };
174 
175 /* session command numbers */
176  typedef enum
177  {
178 /* File stuffs */
186 
187 /* Edit stuffs */
191 
192 /* Command stuffs */
201 
202 /* Environment stuffs */
210 
211 /* Help stuffs */
217 
218 /* More environment stuff */
226 
227 /* Histogram profile stuff */
232 
233 /* cmd history stuffs */
236 
238  } SESSION_CMD;
239 
240 /* iq_ function return status */
241  enum
242  {
245  };
246 
247  typedef enum
248  {
253 
254  typedef struct
255  {
256  const char *db_name;
257  const char *user_name;
258  const char *passwd;
259  const char *in_file_name;
260  const char *out_file_name;
261  const char *command;
262  bool sa_mode;
263  bool cs_mode;
267  bool read_only;
269  bool nopager;
271  bool sysadm;
282 #if defined(CSQL_NO_LONGGING)
283  bool no_logging;
284 #endif /* CSQL_NO_LONGGING */
285  } CSQL_ARGUMENT;
286 
287  typedef struct
288  {
289  char *name;
290  int width;
292 
293 /* The file streams we are to use */
294  extern FILE *csql_Input_fp;
295  extern FILE *csql_Output_fp;
296  extern FILE *csql_Error_fp;
297 
298  extern char csql_Editor_cmd[];
299  extern char csql_Shell_cmd[];
300  extern char csql_Print_cmd[];
301  extern char csql_Pager_cmd[];
302  extern char csql_Scratch_text[];
303  extern int csql_Error_code;
304 
305 
306  extern int csql_Line_lwm;
307  extern int csql_Row_count;
308  extern int csql_Num_failures;
309 
310  extern int (*csql_text_utf8_to_console) (const char *, const int, char **, int *);
311  extern int (*csql_text_console_to_utf8) (const char *, const int, char **, int *);
312 
313  extern void csql_display_msg (const char *string);
314  extern void csql_exit (int exit_status);
315  extern int csql (const char *argv0, CSQL_ARGUMENT * csql_arg);
316 
317  extern const char *csql_get_message (int message_index);
318 
319  extern char *csql_get_real_path (const char *pathname);
320  extern void csql_invoke_system (const char *command);
321  extern int csql_invoke_system_editor (void);
322  extern void csql_fputs (const char *str, FILE * fp);
323  extern void csql_fputs_console_conv (const char *str, FILE * fp);
324  extern FILE *csql_popen (const char *cmd, FILE * fd);
325  extern void csql_pclose (FILE * pf, FILE * fd);
326  extern void csql_display_csql_err (int line_no, int col_no);
327  extern void csql_display_session_err (DB_SESSION * session, int line_no);
328  extern int csql_append_more_line (int indent, const char *line);
329  extern void csql_display_more_lines (const char *title);
330  extern void csql_free_more_lines (void);
331  extern void csql_check_server_down (void);
332  extern char *csql_get_tmp_buf (size_t size);
333  extern void nonscr_display_error (char *buffer, int buf_length);
334 
335  extern int csql_get_session_cmd_no (const char *input);
336 
337  extern void csql_results (const CSQL_ARGUMENT * csql_arg,
338  DB_QUERY_RESULT * result,
339  DB_QUERY_TYPE * attr_spec, int line_no, CUBRID_STMT_TYPE stmt_type);
340 
341  extern char *csql_edit_contents_get (void);
342  extern int csql_edit_contents_append (const char *str, bool flag_append_new_line);
343  extern void csql_walk_statement (const char *str);
344  extern bool csql_is_statement_complete (void);
345  extern bool csql_is_statement_in_block (void);
346  extern void csql_edit_contents_clear (void);
347  extern void csql_edit_contents_finalize (void);
348  extern int csql_edit_read_file (FILE * fp);
349  extern int csql_edit_write_file (FILE * fp);
350 
351  extern const char *csql_errmsg (int code);
352 
353  extern void csql_help_menu (void);
354  extern void csql_help_schema (const char *class_name);
355  extern void csql_help_trigger (const char *class_name);
356  extern void csql_help_info (const char *command, int aucommit_flag);
357  extern void csql_killtran (const char *argument);
358 
359  extern char *csql_db_value_as_string (DB_VALUE * value, int *length, bool plain_string, CSQL_OUTPUT_TYPE output_type,
360  char cloumn_enclosure);
361 
362  extern char *csql_string_to_plain_string (const char *string_value, int length, int *result_length);
363 
364  extern int csql_set_column_width_info (const char *column_name, int column_width);
365  extern int csql_get_column_width (const char *column_name);
366 
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 
373 #endif /* _CSQL_H_ */
char csql_Pager_cmd[]
Definition: csql.c:125
void csql_edit_contents_finalize(void)
bool auto_commit
Definition: csql.h:268
void csql_invoke_system(const char *command)
Definition: csql_support.c:226
bool line_output
Definition: csql.h:266
int string_width
Definition: csql.h:277
char csql_Editor_cmd[]
Definition: csql.c:129
char csql_Scratch_text[]
Definition: csql.c:146
void csql_help_trigger(const char *class_name)
Definition: csql_session.c:461
bool csql_is_statement_in_block(void)
void csql_display_session_err(DB_SESSION *session, int line_no)
Definition: csql_support.c:512
void csql_display_msg(const char *string)
Definition: csql.c:376
void csql_help_schema(const char *class_name)
Definition: csql_session.c:221
void csql_walk_statement(const char *str)
Definition: csql_support.c:967
char * csql_string_to_plain_string(const char *string_value, int length, int *result_length)
void csql_fputs_console_conv(const char *str, FILE *fp)
Definition: csql_support.c:357
Definition: csql.h:184
char * csql_db_value_as_string(DB_VALUE *value, int *length, bool plain_string, CSQL_OUTPUT_TYPE output_type, char cloumn_enclosure)
bool read_only
Definition: csql.h:267
char column_enclosure
Definition: csql.h:280
void csql_results(const CSQL_ARGUMENT *csql_arg, DB_QUERY_RESULT *result, DB_QUERY_TYPE *attr_spec, int line_no, CUBRID_STMT_TYPE stmt_type)
Definition: csql_result.c:185
char csql_Shell_cmd[]
Definition: csql.c:135
CSQL_OUTPUT_TYPE
Definition: csql.h:247
char csql_Print_cmd[]
Definition: csql.c:124
int csql_edit_contents_append(const char *str, bool flag_append_new_line)
Definition: csql_support.c:938
int csql(const char *argv0, CSQL_ARGUMENT *csql_arg)
Definition: csql.c:2703
int csql_set_column_width_info(const char *column_name, int column_width)
Definition: csql.c:2967
void csql_help_info(const char *command, int aucommit_flag)
Definition: csql_session.c:647
const char * db_name
Definition: csql.h:256
void csql_fputs(const char *str, FILE *fp)
Definition: csql_support.c:322
int csql_append_more_line(int indent, const char *line)
Definition: csql_support.c:550
bool trigger_action_flag
Definition: csql.h:273
int csql_get_session_cmd_no(const char *input)
Definition: csql_session.c:141
char * csql_edit_contents_get(void)
Definition: csql_support.c:896
int(* csql_text_utf8_to_console)(const char *, const int, char **, int *)
Definition: csql.c:113
void csql_check_server_down(void)
Definition: csql_support.c:753
static int input()
Definition: cnvlex.c:1661
bool plain_output
Definition: csql.h:274
void csql_help_menu(void)
Definition: csql_session.c:197
char * csql_get_real_path(const char *pathname)
Definition: csql_support.c:160
const char * passwd
Definition: csql.h:258
Definition: csql.h:91
bool write_on_standby
Definition: csql.h:272
SESSION_CMD
Definition: csql.h:176
void csql_killtran(const char *argument)
Definition: csql_session.c:755
const char * command
Definition: csql.h:261
bool sa_mode
Definition: csql.h:262
const char * out_file_name
Definition: csql.h:260
bool skip_column_names
Definition: csql.h:275
void csql_display_csql_err(int line_no, int col_no)
Definition: csql_support.c:490
FILE * csql_Input_fp
Definition: csql.c:156
int csql_Line_lwm
Definition: csql.c:121
int csql_Error_code
Definition: csql.c:148
int csql_Num_failures
Definition: csql.c:118
bool query_output
Definition: csql.h:278
bool loaddb_output
Definition: csql.h:281
bool continue_on_error
Definition: csql.h:270
bool single_line_execution
Definition: csql.h:264
FILE * csql_popen(const char *cmd, FILE *fd)
Definition: csql_support.c:396
void csql_exit(int exit_status)
Definition: csql.c:2691
void csql_pclose(FILE *pf, FILE *fd)
Definition: csql_support.c:444
void csql_free_more_lines(void)
Definition: csql_support.c:714
void csql_edit_contents_clear(void)
void csql_display_more_lines(const char *title)
Definition: csql_support.c:675
bool csql_is_statement_complete(void)
int csql_edit_write_file(FILE *fp)
char column_delimiter
Definition: csql.h:279
int(* csql_text_console_to_utf8)(const char *, const int, char **, int *)
Definition: csql.c:115
int csql_get_column_width(const char *column_name)
Definition: csql.c:3052
const char * csql_errmsg(int code)
CUBRID_STMT_TYPE
Definition: cas_dbms_util.h:40
bool sysadm
Definition: csql.h:271
void nonscr_display_error(char *buffer, int buf_length)
Definition: csql_support.c:830
int csql_invoke_system_editor(void)
Definition: csql_support.c:252
const char * csql_get_message(int message_index)
Definition: csql.c:2954
Definition: csql.h:96
char * csql_get_tmp_buf(size_t size)
Definition: csql_support.c:779
bool cs_mode
Definition: csql.h:263
bool skip_vacuum
Definition: csql.h:276
int csql_Row_count
Definition: csql.c:117
bool nopager
Definition: csql.h:269
const char * user_name
Definition: csql.h:257
const char * in_file_name
Definition: csql.h:259
bool column_output
Definition: csql.h:265
FILE * csql_Output_fp
Definition: csql.c:157
Definition: csql.h:92
int csql_edit_read_file(FILE *fp)
FILE * csql_Error_fp
Definition: csql.c:158