40 #if defined (SUPPRESS_STRLEN_WARNING) 41 #define strlen(s1) ((int) strlen(s1)) 48 #define MAX_SHORT_DISPLAY_LENGTH 6 49 #define MAX_INTEGER_DISPLAY_LENGTH 11 50 #define MAX_BIGINT_DISPLAY_LENGTH 20 51 #define MAX_FLOAT_DISPLAY_LENGTH (FLT_DIG + 7) 52 #define MAX_DOUBLE_DISPLAY_LENGTH (DBL_DIG + 9) 53 #define MAX_TIME_DISPLAY_LENGTH 11 54 #define MAX_TIMEZONE_DISPLAY_LENGTH 18 55 #define MAX_UTIME_DISPLAY_LENGTH 25 56 #define MAX_TIMESTAMPTZ_DISPLAY_LENGTH \ 57 (MAX_UTIME_DISPLAY_LENGTH + MAX_TIMEZONE_DISPLAY_LENGTH) 58 #define MAX_DATETIME_DISPLAY_LENGTH 29 59 #define MAX_DATETIMETZ_DISPLAY_LENGTH \ 60 (MAX_DATETIME_DISPLAY_LENGTH + MAX_TIMEZONE_DISPLAY_LENGTH) 61 #define MAX_DATE_DISPLAY_LENGTH 10 62 #define MAX_MONETARY_DISPLAY_LENGTH 20 63 #define MAX_DEFAULT_DISPLAY_LENGTH 20 64 #define STRING_TYPE_PREFIX_SUFFIX_LENGTH 2 65 #define NSTRING_TYPE_PREFIX_SUFFIX_LENGTH 3 66 #define BIT_TYPE_PREFIX_SUFFIX_LENGTH 3 162 bool loaddb_output,
char column_enclosure);
166 static int calculate_width (
int column_width,
int string_width,
int origin_width,
DB_TYPE attr_type,
bool is_null);
191 int *attr_name_lengths =
NULL;
194 char **attr_names =
NULL;
195 int *attr_lengths =
NULL;
197 int max_attr_name_length = 0;
221 attr_names = (
char **) malloc (
sizeof (
char *) * num_attrs);
222 if (attr_names ==
NULL)
227 for (i = 0; i < num_attrs; i++)
229 attr_names[
i] = (
char *)
NULL;
231 attr_name_lengths = (
int *) malloc (
sizeof (
int) * num_attrs);
232 attr_lengths = (
int *) malloc (
sizeof (
int) * num_attrs);
234 if (attr_name_lengths ==
NULL || attr_lengths ==
NULL || attr_types ==
NULL)
242 max_attr_name_length = 0;
251 attr_names[
i] = (
char *) malloc (7);
252 if (attr_names[i] ==
NULL)
257 strcpy (attr_names[0],
"Result");
261 bool is_console_conv =
false;
266 char *attr_name_console_encoded =
NULL;
267 int attr_name_console_length = -1;
271 (temp,
strlen (temp), &attr_name_console_encoded, &attr_name_console_length) ==
NO_ERROR)
273 if (attr_name_console_encoded !=
NULL)
276 attr_names[
i] = attr_name_console_encoded;
277 is_console_conv =
true;
282 if (!is_console_conv)
285 if (attr_names[i] ==
NULL)
291 attr_name_lengths[
i] =
strlen (attr_names[i]);
292 max_attr_name_length = MAX (max_attr_name_length, attr_name_lengths[i]);
295 switch (attr_types[i])
368 if (attr_names !=
NULL)
370 for (i = 0; i < num_attrs; i++)
372 if (attr_names[i] !=
NULL)
379 if (attr_name_lengths !=
NULL)
383 if (attr_lengths !=
NULL)
387 if (attr_types !=
NULL)
405 if (attr_names !=
NULL)
407 for (i = 0; i < num_attrs; i++)
409 if (attr_names[i] !=
NULL)
416 if (attr_name_lengths !=
NULL)
420 if (attr_lengths !=
NULL)
424 if (attr_types !=
NULL)
440 int table_size = DIM (csql_Cmd_string_table);
442 for (i = 0; i < table_size; i++)
444 if (csql_Cmd_string_table[i].stmt_type == stmt_type)
446 return (csql_Cmd_string_table[i].cmd_string);
449 return default_string;
496 bool loaddb_output,
char column_enclosure)
508 val = (
char **) malloc (
sizeof (
char *) * num_attrs);
514 memset (val, 0,
sizeof (
char *) * num_attrs);
516 len = (
int *) malloc (
sizeof (
int) * num_attrs);
522 memset (len, 0,
sizeof (
int) * num_attrs);
527 for (i = 0; i < num_attrs; i++)
561 val[
i] = (
char *) malloc (5);
567 strcpy (val[i],
"NULL");
571 val[
i] = (
char *) malloc (40);
577 sprintf (val[i],
"pointer value (%p)", (
void *)
db_get_pointer (&db_value));
581 val[
i] = (
char *) malloc (40);
587 sprintf (val[i],
"error code (%d)",
db_get_error (&db_value));
599 int async_ws, iso_lvl;
604 val[
i] = (
char *) malloc (128);
611 if (iso_lvl < 1 || iso_lvl > 6)
621 val[
i] = (
char *) malloc (9);
627 strcpy (val[i],
"INFINITE");
634 if (query_output ==
true)
638 else if (loaddb_output ==
true)
658 if (len[i] == 0 && val[i])
678 for (i = 0; i < num_attrs; i++)
695 return ((
char **)
NULL);
730 typedef char **value_array;
731 volatile value_array val;
745 char *refined_attr_name =
NULL;
750 char csql_column_delimiter;
754 val = (
char **)
NULL;
767 #if !defined(WINDOWS) 795 for (i = 0; i < num_attrs; i++)
798 if (refined_attr_name !=
NULL)
800 fprintf (pf,
"%s", refined_attr_name);
805 fprintf (pf,
"UNKNOWN");
808 if (i == num_attrs - 1)
814 fprintf (pf,
"%c", csql_column_delimiter);
820 fprintf (pf,
"%%class [ ] (");
821 for (i = 0; i < num_attrs; i++)
824 if (refined_attr_name !=
NULL)
826 fprintf (pf,
"[%s]", refined_attr_name);
831 fprintf (pf,
"UNKNOWN");
834 if (i == num_attrs - 1)
846 for (n = i = 0; i < num_attrs; i++)
848 fprintf (pf,
" %*s", (
int) (attr_lengths[i]), attr_names[i]);
849 n += 2 + ((attr_lengths[
i] > 0) ? attr_lengths[i] : -attr_lengths[i]);
859 for (object_no = 1;; object_no++)
865 for (i = 0; i < num_attrs; i++)
889 fprintf (pf,
"<%05d>", object_no);
890 for (i = 0; i < num_attrs; i++)
892 fprintf (pf,
"%*c", (
int) ((i == 0) ? 1 : 8),
' ');
893 fprintf (pf,
"%*s: %s\n", (
int) (-max_attr_name_length), attr_names[i], val[i]);
899 for (i = 0; i < num_attrs - 1; i++)
901 fprintf (pf,
"%s\t", val[i]);
903 fprintf (pf,
"%s\n", val[i]);
907 for (i = 0; i < num_attrs - 1; i++)
911 fprintf (pf,
"%s\n", val[i]);
917 for (i = 0; i < num_attrs; i++)
919 if (strcmp (
"NULL", val[i]) == 0)
929 value_width =
calculate_width (column_width, csql_string_width, len[i], attr_types[i], is_null);
932 (attr_lengths[
i] > 0) ? MAX (attr_lengths[i] - (value_width),
933 0) : MIN (attr_lengths[i] + (value_width), 0);
936 if (padding_size > 0)
939 fprintf (pf,
"%*s", (
int) padding_size,
"");
945 value[value_width - 1] =
'\'';
948 fwrite (value, 1, value_width, pf);
950 if (padding_size < 0)
953 fprintf (pf,
"%*s", (
int) (-padding_size),
"");
993 #if !defined(WINDOWS) 999 #if !defined(WINDOWS) 1006 for (i = 0; i < num_attrs; i++)
1030 if (column_width > 0)
1034 result = column_width;
1050 result = column_width;
1057 result = string_width;
1073 result = string_width;
1078 result = origin_width;
1081 if (result > origin_width)
1083 result = origin_width;
1187 to = (
char *) malloc (length + 1);
1191 return ((
char *)
NULL);
1194 memcpy (to, from, length);
const char * csql_get_message(int message_index)
DB_C_FLOAT db_get_float(const DB_VALUE *value)
#define TRAN_ISO_LVL_BITS
#define MSGCAT_CATALOG_CSQL
static int calculate_width(int column_width, int string_width, int origin_width, DB_TYPE attr_type, bool is_null)
static char * uncontrol_strdup(const char *from)
static bool is_string_type(DB_TYPE type)
int db_get_int(const DB_VALUE *value)
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)
char * csql_db_value_as_string(DB_VALUE *value, int *length, bool plain_string, CSQL_OUTPUT_TYPE output_type, char cloumn_enclosure)
static CSQL_CMD_STRING_TABLE csql_Cmd_string_table[]
static char ** get_current_result(int **len, const CUR_RESULT_INFO *result_info, bool plain_output, bool query_output, bool loaddb_output, char column_enclosure)
DB_QUERY_TYPE * db_query_format_next(DB_QUERY_TYPE *query_type)
void csql_fputs(const char *str, FILE *fp)
#define MAX_UTIME_DISPLAY_LENGTH
char * db_query_format_name(DB_QUERY_TYPE *query_type)
static bool is_nstring_type(DB_TYPE type)
static bool is_bit_type(DB_TYPE type)
void csql_check_server_down(void)
int db_query_first_tuple(DB_QUERY_RESULT *result)
static bool is_type_that_has_suffix(DB_TYPE type)
static bool is_cuttable_type_by_string_width(DB_TYPE type)
static int write_results_to_stream(const CSQL_ARGUMENT *csql_arg, FILE *fp, const CUR_RESULT_INFO *result_info)
#define MAX_DOUBLE_DISPLAY_LENGTH
#define MAX_DATETIMETZ_DISPLAY_LENGTH
void csql_display_csql_err(int line_no, int col_no)
CUBRID_STMT_TYPE stmt_type
CUBRID_STMT_TYPE curr_stmt_type
#define MSGCAT_CSQL_SET_CSQL
#define TM_TRAN_READ_FETCH_VERSION()
static jmp_buf csql_Jmp_buf
#define MAX_INTEGER_DISPLAY_LENGTH
#define STRING_TYPE_PREFIX_SUFFIX_LENGTH
char csql_Scratch_text[SCRATCH_TEXT_LEN]
need_clear_type need_clear
int pr_clear_value(DB_VALUE *value)
FILE * csql_popen(const char *cmd, FILE *fd)
static char * uncontrol_strndup(const char *from, int length)
#define MAX_MONETARY_DISPLAY_LENGTH
static const char * csql_Isolation_level_string[]
#define MAX_SHORT_DISPLAY_LENGTH
void csql_pclose(FILE *pf, FILE *fd)
static void(* csql_pipe_save)(int sig)
static void display_empty_result(int stmt_type, int line_no)
DB_QUERY_RESULT * query_result
static void error(const char *msg)
#define MAX_FLOAT_DISPLAY_LENGTH
int db_query_next_tuple(DB_QUERY_RESULT *result)
char csql_Pager_cmd[PATH_MAX]
int(* csql_text_utf8_to_console)(const char *, const int, char **, int *)
int csql_get_column_width(const char *column_name)
#define free_and_init(ptr)
#define BIT_TYPE_PREFIX_SUFFIX_LENGTH
#define MAX_DATETIME_DISPLAY_LENGTH
#define MAX_BIGINT_DISPLAY_LENGTH
int db_query_set_copy_tplvalue(DB_QUERY_RESULT *result, int copy)
#define MAX_DATE_DISPLAY_LENGTH
#define MAX_DEFAULT_DISPLAY_LENGTH
#define DB_VALUE_TYPE(value)
void nonscr_display_error(char *buffer, int buf_length)
static void csql_pipe_handler(int sig_no)
int db_make_null(DB_VALUE *value)
char * msgcat_message(int cat_id, int set_id, int msg_id)
#define MAX_TIME_DISPLAY_LENGTH
int db_get_error(const DB_VALUE *value)
int db_query_get_tuple_value(DB_QUERY_RESULT *result, int index, DB_VALUE *value)
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)
DB_TYPE db_query_format_type(DB_QUERY_TYPE *query_type)
#define TRAN_ASYNC_WS_BIT
static const char * csql_cmd_string(CUBRID_STMT_TYPE stmt_type, const char *default_string)
DB_C_POINTER db_get_pointer(const DB_VALUE *value)
#define NSTRING_TYPE_PREFIX_SUFFIX_LENGTH
#define MAX_TIMESTAMPTZ_DISPLAY_LENGTH
SIGNAL_HANDLER_FUNCTION os_set_signal_handler(const int sig_no, SIGNAL_HANDLER_FUNCTION sig_handler)