45 #if defined (SUPPRESS_STRLEN_WARNING) 46 #define strlen(s1) ((int) strlen(s1)) 53 #define MORE_LINE_EXPANSION_UNIT 40 60 #define DEFAULT_DB_ERROR_MSG_LEVEL 3 89 static void iq_format_err (
char *
string,
int buf_size,
int line_no,
int col_no);
118 #if !defined(WINDOWS) 128 struct passwd *ptr =
NULL;
129 uid_t userid = getuid ();
133 while ((ptr = getpwent ()) !=
NULL)
135 if (userid == ptr->pw_uid)
137 snprintf (homedir, homedir_size,
"%s", ptr->pw_dir);
163 if (pathname ==
NULL)
168 while (isspace (pathname[0]))
173 if (pathname[0] ==
'\0')
178 return (
char *) pathname;
180 static char real_path[PATH_MAX];
183 if (pathname ==
NULL)
188 while (isspace (pathname[0]))
193 if (pathname[0] ==
'\0')
201 if (pathname[0] ==
'~')
208 snprintf (real_path,
sizeof (real_path),
"%s%s", home, &pathname[1]);
212 snprintf (real_path,
sizeof (real_path),
"%s", pathname);
228 bool error_found =
false;
230 if (system (command) == 127)
286 fclose (file.release ());
293 file.reset (fopen (filename.c_str (),
"r"));
331 for (flag =
false; *str !=
'\0'; str++)
335 putc ((flag) ?
'>' :
'<', fp);
359 char *conv_buf =
NULL;
360 const char *conv_buf_ptr =
NULL;
361 int conv_buf_size = 0;
371 conv_buf_ptr = conv_buf;
380 if (conv_buf !=
NULL)
407 if (cmd ==
NULL || cmd[0] ==
'\0')
414 pf = popen (cmd,
"w");
446 #if !defined(WINDOWS) 467 snprintf (
string, buf_size,
471 snprintf (
string, buf_size,
473 strcat (
string,
"\n");
559 char *conv_buf =
NULL;
560 int conv_buf_size = 0;
565 line = (conv_buf !=
NULL) ? conv_buf : line;
579 t_lines = (
char **) malloc (
sizeof (
char *) * new_num);
583 t_lines = (
char **) realloc (
iq_More_lines,
sizeof (
char *) * new_num);
588 if (conv_buf !=
NULL)
599 for (i = exp_len = 0, q = line; *q !=
'\0'; q++)
621 if (conv_buf !=
NULL)
634 for (i = 0, q = line; *q !=
'\0'; q++)
658 if (conv_buf !=
NULL)
679 #if !defined(WINDOWS) 680 void (*iq_pipe_save) (
int sig);
704 #if !defined(WINDOWS) 705 signal (SIGPIPE, iq_pipe_save);
728 iq_Num_more_lines = 0;
781 static char buf[1024];
782 static char *bufp =
NULL;
783 static size_t bufsize = 0;
785 if (size + 1 <
sizeof (buf))
796 if (size + 1 < bufsize)
808 bufp = (
char *) malloc (bufsize);
832 int remaining = buf_length;
836 char *con_buf_ptr =
NULL;
837 int con_buf_size = 0;
839 strncpy (buffer,
"\n", remaining);
840 remaining -=
strlen (
"\n");
843 strncat (buffer, msg, remaining);
844 remaining -=
strlen (msg);
847 len_errmsg =
strlen (errmsg);
852 if (con_buf_ptr !=
NULL)
854 errmsg = con_buf_ptr;
855 len_errmsg = con_buf_size;
859 if (len_errmsg > (remaining - 3) )
863 const char *separator =
"......";
864 int separator_len =
strlen (separator);
866 print_len = (remaining - 3 - separator_len) / 2;
867 strncat (buffer, errmsg, print_len);
868 strcat (buffer, separator);
869 strncat (buffer, errmsg + len_errmsg - print_len, print_len);
870 remaining -= (print_len * 2 + separator_len);
874 strncat (buffer, errmsg, remaining);
875 remaining -= len_errmsg;
878 if (con_buf_ptr !=
NULL)
883 strncat (buffer,
"\n\n", remaining);
884 remaining -=
strlen (
"\n\n");
886 buffer[buf_length - 1] =
'\0';
900 return ((
char *)
"");
908 int new_alloc_size = csql_Edit_contents.
alloc_size;
909 if (new_alloc_size >= required_size)
912 if (new_alloc_size <= 0)
914 new_alloc_size = 1024;
916 while (new_alloc_size < required_size)
920 csql_Edit_contents.
contents = (
char *) realloc (csql_Edit_contents.
contents, new_alloc_size);
927 csql_Edit_contents.
alloc_size = new_alloc_size;
940 int str_len, new_data_size;
946 new_data_size = csql_Edit_contents.
data_size + str_len;
951 memcpy (csql_Edit_contents.
contents + csql_Edit_contents.
data_size, str, str_len);
952 csql_Edit_contents.
data_size = new_data_size;
953 if (flag_append_new_line)
971 bool include_stmt =
false;
972 bool is_last_stmt_valid =
true;
995 str_length =
strlen (str);
997 for (p = str; p < str + str_length; p++)
1005 if (*(p + 1) ==
'/')
1011 if (*(p + 1) ==
'*')
1017 is_last_stmt_valid =
true;
1020 if (*(p + 1) ==
'-')
1026 is_last_stmt_valid =
true;
1030 is_last_stmt_valid =
true;
1041 is_last_stmt_valid =
true;
1045 is_last_stmt_valid =
true;
1049 is_last_stmt_valid =
true;
1052 include_stmt =
true;
1053 is_last_stmt_valid =
false;
1064 if (!is_last_stmt_valid)
1066 is_last_stmt_valid =
true;
1073 if (*p ==
'*' && *(p + 1) ==
'/')
1100 else if (*p ==
'\'')
1102 if (*(p + 1) ==
'\'')
1121 if (*(p + 1) ==
'\"')
1161 if (include_stmt && !is_last_stmt_valid
1167 csql_Edit_contents.
state = state;
1237 char line_buf[1024];
1238 bool is_first_read_line =
true;
1240 while (fgets (line_buf,
sizeof (line_buf), fp) !=
NULL)
1242 char *line_begin = line_buf;
1249 is_first_read_line =
false;
1266 int remain_size = csql_Edit_contents.
data_size;
1268 while (remain_size > 0)
1270 write_len = (int) fwrite (p + (csql_Edit_contents.
data_size - remain_size), 1, remain_size, fp);
1276 remain_size -= write_len;
1317 return (strerror (errno));
1322 return ((msg ==
NULL) ?
"" : msg);
1328 msg_map_size = DIM (csql_Err_msg_map);
1329 for (i = 0; i < msg_map_size; i++)
1331 if (code == csql_Err_msg_map[i].error_code)
const char * csql_get_message(int message_index)
static int iq_Num_more_lines
#define MSGCAT_CATALOG_CSQL
void csql_edit_contents_finalize()
const char * csql_errmsg(int code)
char * csql_edit_contents_get()
void csql_display_csql_err(int line_no, int col_no)
void csql_fputs(const char *str, FILE *fp)
static CSQL_EDIT_CONTENTS csql_Edit_contents
static jmp_buf iq_Jmp_buf
static char ** iq_More_lines
DB_SESSION_ERROR * db_get_next_error(DB_SESSION_ERROR *errors, int *line, int *col)
FILE * csql_popen(const char *cmd, FILE *fd)
char * csql_get_tmp_buf(size_t size)
void csql_check_server_down(void)
bool csql_is_statement_complete(void)
void nonscr_display_error(char *buffer, int buf_length)
void logddl_set_err_msg(char *msg)
int csql_append_more_line(int indent, const char *line)
int csql_edit_write_file(FILE *fp)
std::unique_ptr< FILE, file_closer > auto_close_file
bool csql_is_statement_in_block(void)
#define DEFAULT_DB_ERROR_MSG_LEVEL
void csql_invoke_system(const char *command)
void csql_walk_statement(const char *str)
static int csql_get_user_home(char *homebuf, int bufsize)
const char * db_error_string(int level)
CSQL_STATEMENT_STATE state
static int csql_edit_contents_expand(int required_size)
enum csql_statement_state CSQL_STATEMENT_STATE
bool intl_is_bom_magic(const char *buf, const int size)
int csql_edit_contents_append(const char *str, bool flag_append_new_line)
void csql_display_more_lines(const char *title)
void csql_free_more_lines(void)
static bool iq_output_device_is_a_tty(void)
#define MSGCAT_CSQL_SET_CSQL
char csql_Scratch_text[SCRATCH_TEXT_LEN]
static CSQL_ERR_MSG_MAP csql_Err_msg_map[]
void csql_display_session_err(DB_SESSION *session, int line_no)
void csql_fputs_console_conv(const char *str, FILE *fp)
char csql_Pager_cmd[PATH_MAX]
std::pair< std::string, FILE * > open_temp_file(const char *prefix, const char *mode="w", int flags=0)
int csql_invoke_system_editor(void)
std::unique_ptr< const char, file_deleter > auto_delete_file
int(* csql_text_utf8_to_console)(const char *, const int, char **, int *)
char * csql_get_real_path(const char *pathname)
#define free_and_init(ptr)
void csql_exit(int exit_status)
bool prm_get_bool_value(PARAM_ID prm_id)
#define ER_TM_SERVER_DOWN_UNILATERALLY_ABORTED
void csql_edit_contents_clear()
char * msgcat_message(int cat_id, int set_id, int msg_id)
static void iq_pipe_handler(int sig_no)
static bool iq_input_device_is_a_tty(void)
void csql_pclose(FILE *pf, FILE *fd)
static void iq_format_err(char *string, int buf_size, int line_no, int col_no)
char csql_Editor_cmd[PATH_MAX]
DB_SESSION_ERROR * db_get_errors(DB_SESSION *session)
int csql_edit_read_file(FILE *fp)
#define MORE_LINE_EXPANSION_UNIT