CUBRID Engine  latest
csql_support.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdarg.h>
#include <signal.h>
#include <setjmp.h>
#include <assert.h>
#include <pwd.h>
#include "porting.h"
#include "csql.h"
#include "filesys.hpp"
#include "filesys_temp.hpp"
#include "memory_alloc.h"
#include "system_parameter.h"
#include "ddl_log.h"
Include dependency graph for csql_support.c:

Go to the source code of this file.

Classes

struct  CSQL_EDIT_CONTENTS
 
struct  CSQL_ERR_MSG_MAP
 

Macros

#define TAB_STOP   8
 
#define MORE_LINE_EXPANSION_UNIT   40
 
#define DEFAULT_DB_ERROR_MSG_LEVEL   3 /* current max */
 

Typedefs

typedef enum csql_statement_state CSQL_STATEMENT_STATE
 

Enumerations

enum  csql_statement_state {
  CSQL_STATE_GENERAL = 0, CSQL_STATE_C_COMMENT, CSQL_STATE_CPP_COMMENT, CSQL_STATE_SQL_COMMENT,
  CSQL_STATE_SINGLE_QUOTE, CSQL_STATE_MYSQL_QUOTE, CSQL_STATE_DOUBLE_QUOTE_IDENTIFIER, CSQL_STATE_BACKTICK_IDENTIFIER,
  CSQL_STATE_BRACKET_IDENTIFIER, CSQL_STATE_STATEMENT_END
}
 

Functions

static void iq_pipe_handler (int sig_no)
 
static void iq_format_err (char *string, int buf_size, int line_no, int col_no)
 
static bool iq_input_device_is_a_tty (void)
 
static bool iq_output_device_is_a_tty (void)
 
static int csql_get_user_home (char *homebuf, int bufsize)
 
char * csql_get_real_path (const char *pathname)
 
void csql_invoke_system (const char *command)
 
int csql_invoke_system_editor (void)
 
void csql_fputs (const char *str, FILE *fp)
 
void csql_fputs_console_conv (const char *str, FILE *fp)
 
FILE * csql_popen (const char *cmd, FILE *fd)
 
void csql_pclose (FILE *pf, FILE *fd)
 
void csql_display_csql_err (int line_no, int col_no)
 
void csql_display_session_err (DB_SESSION *session, int line_no)
 
int csql_append_more_line (int indent, const char *line)
 
void csql_display_more_lines (const char *title)
 
void csql_free_more_lines (void)
 
void csql_check_server_down (void)
 
char * csql_get_tmp_buf (size_t size)
 
void nonscr_display_error (char *buffer, int buf_length)
 
char * csql_edit_contents_get ()
 
static int csql_edit_contents_expand (int required_size)
 
int csql_edit_contents_append (const char *str, bool flag_append_new_line)
 
void csql_walk_statement (const char *str)
 
bool csql_is_statement_complete (void)
 
bool csql_is_statement_in_block (void)
 
void csql_edit_contents_clear ()
 
void csql_edit_contents_finalize ()
 
int csql_edit_read_file (FILE *fp)
 
int csql_edit_write_file (FILE *fp)
 
const char * csql_errmsg (int code)
 

Variables

static char ** iq_More_lines
 
static int iq_Num_more_lines = 0
 
static jmp_buf iq_Jmp_buf
 
static CSQL_EDIT_CONTENTS csql_Edit_contents = { NULL, 0, 0, CSQL_STATE_GENERAL }
 
static CSQL_ERR_MSG_MAP csql_Err_msg_map []
 

Macro Definition Documentation

#define DEFAULT_DB_ERROR_MSG_LEVEL   3 /* current max */

Definition at line 60 of file csql_support.c.

Referenced by csql_errmsg().

#define MORE_LINE_EXPANSION_UNIT   40

Definition at line 53 of file csql_support.c.

Referenced by csql_append_more_line().

#define TAB_STOP   8

Definition at line 50 of file csql_support.c.

Referenced by csql_append_more_line().

Typedef Documentation

Enumeration Type Documentation

Enumerator
CSQL_STATE_GENERAL 
CSQL_STATE_C_COMMENT 
CSQL_STATE_CPP_COMMENT 
CSQL_STATE_SQL_COMMENT 
CSQL_STATE_SINGLE_QUOTE 
CSQL_STATE_MYSQL_QUOTE 
CSQL_STATE_DOUBLE_QUOTE_IDENTIFIER 
CSQL_STATE_BACKTICK_IDENTIFIER 
CSQL_STATE_BRACKET_IDENTIFIER 
CSQL_STATE_STATEMENT_END 

Definition at line 62 of file csql_support.c.

Function Documentation

int csql_append_more_line ( int  indent,
const char *  line 
)
void csql_check_server_down ( void  )
void csql_display_csql_err ( int  line_no,
int  col_no 
)
void csql_display_session_err ( DB_SESSION session,
int  line_no 
)
int csql_edit_contents_append ( const char *  str,
bool  flag_append_new_line 
)

Definition at line 938 of file csql_support.c.

References CSQL_EDIT_CONTENTS::contents, csql_edit_contents_expand(), CSQL_FAILURE, CSQL_SUCCESS, CSQL_EDIT_CONTENTS::data_size, NULL, and strlen.

Referenced by csql_do_session_cmd(), csql_edit_read_file(), and start_csql().

Here is the caller graph for this function:

void csql_edit_contents_clear ( void  )

Definition at line 1214 of file csql_support.c.

References CSQL_STATE_GENERAL, CSQL_EDIT_CONTENTS::data_size, and CSQL_EDIT_CONTENTS::state.

Referenced by csql_do_session_cmd(), csql_edit_contents_finalize(), csql_invoke_system_editor(), and start_csql().

Here is the caller graph for this function:

static int csql_edit_contents_expand ( int  required_size)
static

Definition at line 906 of file csql_support.c.

References CSQL_EDIT_CONTENTS::alloc_size, CSQL_EDIT_CONTENTS::contents, CSQL_ERR_NO_MORE_MEMORY, csql_Error_code, CSQL_FAILURE, CSQL_SUCCESS, and NULL.

Referenced by csql_edit_contents_append().

Here is the caller graph for this function:

void csql_edit_contents_finalize ( void  )

Definition at line 1221 of file csql_support.c.

References CSQL_EDIT_CONTENTS::alloc_size, CSQL_EDIT_CONTENTS::contents, csql_edit_contents_clear(), and free_and_init.

Referenced by start_csql().

Here is the caller graph for this function:

char* csql_edit_contents_get ( void  )

Definition at line 896 of file csql_support.c.

References CSQL_EDIT_CONTENTS::contents, and CSQL_EDIT_CONTENTS::data_size.

Referenced by csql_execute_statements(), and display_buffer().

Here is the caller graph for this function:

int csql_edit_read_file ( FILE *  fp)

Definition at line 1235 of file csql_support.c.

References csql_edit_contents_append(), CSQL_FAILURE, CSQL_SUCCESS, intl_is_bom_magic(), NULL, and strlen.

Referenced by csql_invoke_system_editor(), and csql_read_file().

Here is the caller graph for this function:

int csql_edit_write_file ( FILE *  fp)
const char* csql_errmsg ( int  code)

Definition at line 1310 of file csql_support.c.

References CSQL_E_UNKNOWN_TEXT, CSQL_ERR_OS_ERROR, CSQL_ERR_SQL_ERROR, csql_get_message(), db_error_string(), DEFAULT_DB_ERROR_MSG_LEVEL, i, and NULL.

Referenced by nonscr_display_error().

Here is the caller graph for this function:

void csql_fputs ( const char *  str,
FILE *  fp 
)
void csql_fputs_console_conv ( const char *  str,
FILE *  fp 
)
void csql_free_more_lines ( void  )

Definition at line 714 of file csql_support.c.

References free_and_init, i, iq_More_lines, iq_Num_more_lines, and NULL.

Referenced by csql_get_sys_param(), csql_help_menu(), csql_help_schema(), csql_help_trigger(), csql_set_plan_dump(), csql_set_sys_param(), and csql_set_trace().

Here is the caller graph for this function:

char* csql_get_real_path ( const char *  pathname)

Definition at line 160 of file csql_support.c.

References csql_get_user_home(), NO_ERROR, and NULL.

Referenced by csql_change_working_directory(), csql_read_file(), and csql_write_file().

Here is the caller graph for this function:

char* csql_get_tmp_buf ( size_t  size)

Definition at line 779 of file csql_support.c.

References CSQL_ERR_NO_MORE_MEMORY, csql_Error_code, free_and_init, and NULL.

Referenced by csql_invoke_system_editor(), and csql_print_buffer().

Here is the caller graph for this function:

static int csql_get_user_home ( char *  homebuf,
int  bufsize 
)
static

Definition at line 126 of file csql_support.c.

References ER_FAILED, NO_ERROR, and NULL.

Referenced by csql_get_real_path().

Here is the caller graph for this function:

void csql_invoke_system ( const char *  command)

Definition at line 226 of file csql_support.c.

References CSQL_ERR_OS_ERROR, csql_Error_code, csql_Scratch_text, nonscr_display_error(), and SCRATCH_TEXT_LEN.

Referenced by csql_do_session_cmd(), csql_invoke_system_editor(), and csql_print_buffer().

Here is the caller graph for this function:

bool csql_is_statement_complete ( void  )

Definition at line 1175 of file csql_support.c.

References CSQL_STATE_STATEMENT_END, and CSQL_EDIT_CONTENTS::state.

Referenced by start_csql().

Here is the caller graph for this function:

bool csql_is_statement_in_block ( void  )
void csql_pclose ( FILE *  pf,
FILE *  fd 
)

Definition at line 444 of file csql_support.c.

Referenced by csql_display_more_lines(), csql_display_trace(), csql_dump_alltran(), csql_help_info(), display_buffer(), display_empty_result(), and write_results_to_stream().

Here is the caller graph for this function:

static void iq_format_err ( char *  string,
int  buf_size,
int  line_no,
int  col_no 
)
static

Definition at line 462 of file csql_support.c.

References CSQL_EXACT_POSITION_ERR_FORMAT, CSQL_START_POSITION_ERR_FORMAT, MSGCAT_CATALOG_CSQL, MSGCAT_CSQL_SET_CSQL, and msgcat_message().

Referenced by csql_display_csql_err(), and csql_display_session_err().

Here is the caller graph for this function:

static bool iq_input_device_is_a_tty ( void  )
static

Definition at line 113 of file csql_support.c.

References csql_Input_fp.

Referenced by csql_popen().

Here is the caller graph for this function:

static bool iq_output_device_is_a_tty ( void  )
static

Definition at line 102 of file csql_support.c.

References csql_Output_fp.

Referenced by csql_invoke_system_editor(), and csql_popen().

Here is the caller graph for this function:

static void iq_pipe_handler ( int  sig_no)
static

Definition at line 741 of file csql_support.c.

References iq_Jmp_buf.

Referenced by csql_display_more_lines().

Here is the caller graph for this function:

Variable Documentation

CSQL_EDIT_CONTENTS csql_Edit_contents = { NULL, 0, 0, CSQL_STATE_GENERAL }
static

Definition at line 85 of file csql_support.c.

CSQL_ERR_MSG_MAP csql_Err_msg_map[]
static
Initial value:
= {
}

Definition at line 1287 of file csql_support.c.

jmp_buf iq_Jmp_buf
static

Definition at line 58 of file csql_support.c.

Referenced by csql_display_more_lines(), and iq_pipe_handler().

char** iq_More_lines
static
int iq_Num_more_lines = 0
static