| 1059 | */ |
| 1060 | |
| 1061 | bool MYSQL_QUERY_LOG::write(time_t event_time, const char *user_host, |
| 1062 | uint user_host_len, my_thread_id thread_id, |
| 1063 | const char *command_type, uint command_type_len, |
| 1064 | const char *sql_text, uint sql_text_len) |
| 1065 | { |
| 1066 | char buff[32]; |
| 1067 | uint length= 0; |
| 1068 | char local_time_buff[MAX_TIME_SIZE]; |
| 1069 | struct tm start; |
| 1070 | uint time_buff_len= 0; |
| 1071 | |
| 1072 | mysql_mutex_lock(&LOCK_log); |
| 1073 | |
| 1074 | /* Test if someone closed between the is_open test and lock */ |
| 1075 | if (is_open()) |
| 1076 | { |
| 1077 | /* for testing output of timestamp and thread id */ |
| 1078 | DBUG_EXECUTE_IF("reset_log_last_time", last_time= 0;); |
| 1079 | |
| 1080 | /* Note that my_b_write() assumes it knows the length for this */ |
| 1081 | if (event_time != last_time) |
| 1082 | { |
| 1083 | last_time= event_time; |
| 1084 | |
| 1085 | localtime_r(&event_time, &start); |
| 1086 | |
| 1087 | time_buff_len= my_snprintf(local_time_buff, MAX_TIME_SIZE, |
| 1088 | "%02d%02d%02d %2d:%02d:%02d\t", |
| 1089 | start.tm_year % 100, start.tm_mon + 1, |
| 1090 | start.tm_mday, start.tm_hour, |
| 1091 | start.tm_min, start.tm_sec); |
| 1092 | |
| 1093 | if (my_b_write(&log_file, (uchar*) local_time_buff, time_buff_len)) |
| 1094 | goto err; |
| 1095 | } |
| 1096 | else |
| 1097 | if (my_b_write(&log_file, (uchar*) "\t\t" ,2) < 0) |
| 1098 | goto err; |
| 1099 | |
| 1100 | length= my_snprintf(buff, 32, "%5lu ", thread_id); |
| 1101 | |
| 1102 | if (my_b_write(&log_file, (uchar*) buff, length)) |
| 1103 | goto err; |
| 1104 | |
| 1105 | if (my_b_write(&log_file, (uchar*) command_type, command_type_len)) |
| 1106 | goto err; |
| 1107 | |
| 1108 | if (my_b_write(&log_file, (uchar*) "\t", 1)) |
| 1109 | goto err; |
| 1110 | |
| 1111 | /* sql_text */ |
| 1112 | if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len)) |
| 1113 | goto err; |
| 1114 | |
| 1115 | if (my_b_write(&log_file, (uchar*) "\n", 1) || |
| 1116 | flush_io_cache(&log_file)) |
| 1117 | goto err; |
| 1118 | } |
no test coverage detected