118
126
static void inline slave_rows_error_report(enum loglevel level, int ha_error,
119
127
Relay_log_info const *rli, THD *thd,
120
Table *table, const char * type,
128
TABLE *table, const char * type,
121
129
const char *log_name, ulong pos)
123
131
const char *handler_error= HA_ERR(ha_error);
124
132
char buff[MAX_SLAVE_ERRMSG], *slider;
125
133
const char *buff_end= buff + sizeof(buff);
127
List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
135
List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
131
139
for (err= it++, slider= buff; err && slider < buff_end - 1;
132
140
slider += len, err= it++)
134
142
len= snprintf(slider, buff_end - slider,
135
_(" %s, Error_code: %d;"), err->msg, err->code);
143
" %s, Error_code: %d;", err->msg, err->code);
138
146
rli->report(level, thd->is_error()? thd->main_da.sql_errno() : 0,
139
_("Could not execute %s event on table %s.%s;"
140
"%s handler error %s; "
141
"the event's master log %s, end_log_pos %lu"),
147
"Could not execute %s event on table %s.%s;"
148
"%s handler error %s; "
149
"the event's master log %s, end_log_pos %lu",
142
150
type, table->s->db.str,
143
151
table->s->table_name.str,
145
handler_error == NULL? _("<unknown>") : handler_error,
153
handler_error == NULL? "<unknown>" : handler_error,
151
159
Cache that will automatically be written to a dedicated file on
1058
1147
if (!ev || !ev->is_valid())
1151
if (!force_opt) /* then mysqlbinlog dies */
1153
*error= "Found invalid event in binary log";
1156
ev= new Unknown_log_event(buf, description_event);
1061
1158
*error= "Found invalid event in binary log";
1168
Log_event::print_header()
1171
void Log_event::print_header(IO_CACHE* file,
1172
PRINT_EVENT_INFO* print_event_info,
1173
bool is_more __attribute__((unused)))
1176
my_off_t hexdump_from= print_event_info->hexdump_from;
1178
my_b_printf(file, "#");
1179
print_timestamp(file);
1180
my_b_printf(file, " server id %d end_log_pos %s ", server_id,
1181
llstr(log_pos,llbuff));
1183
/* mysqlbinlog --hexdump */
1184
if (print_event_info->hexdump_from)
1186
my_b_printf(file, "\n");
1187
uchar *ptr= (uchar*)temp_buf;
1189
uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
1192
/* Header len * 4 >= header len * (2 chars + space + extra space) */
1193
char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
1194
char *c, char_string[16+1]= {0};
1196
/* Pretty-print event common header if header is exactly 19 bytes */
1197
if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
1199
char emit_buf[256]; // Enough for storing one line
1200
my_b_printf(file, "# Position Timestamp Type Master ID "
1201
"Size Master Pos Flags \n");
1202
int const bytes_written=
1203
snprintf(emit_buf, sizeof(emit_buf),
1204
"# %8.8lx %02x %02x %02x %02x %02x "
1205
"%02x %02x %02x %02x %02x %02x %02x %02x "
1206
"%02x %02x %02x %02x %02x %02x\n",
1207
(unsigned long) hexdump_from,
1208
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1209
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1210
ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
1211
assert(bytes_written >= 0);
1212
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1213
my_b_write(file, (uchar*) emit_buf, bytes_written);
1214
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1215
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1218
/* Rest of event (without common header) */
1219
for (i= 0, c= char_string, h=hex_string;
1223
snprintf(h, 4, "%02x ", *ptr);
1226
*c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
1231
my_b_printf() does not support full printf() formats, so we
1232
have to do it this way.
1234
TODO: Rewrite my_b_printf() to support full printf() syntax.
1237
int const bytes_written=
1238
snprintf(emit_buf, sizeof(emit_buf),
1239
"# %8.8lx %-48.48s |%16s|\n",
1240
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1241
hex_string, char_string);
1242
assert(bytes_written >= 0);
1243
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1244
my_b_write(file, (uchar*) emit_buf, bytes_written);
1250
else if (i % 8 == 7) *h++ = ' ';
1257
int const bytes_written=
1258
snprintf(emit_buf, sizeof(emit_buf),
1259
"# %8.8lx %-48.48s |%s|\n",
1260
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1261
hex_string, char_string);
1262
assert(bytes_written >= 0);
1263
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1264
my_b_write(file, (uchar*) emit_buf, bytes_written);
1267
need a # to prefix the rest of printouts for example those of
1268
Rows_log_event::print_helper().
1270
my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
1276
void Log_event::print_base64(IO_CACHE* file,
1277
PRINT_EVENT_INFO* print_event_info,
1280
const uchar *ptr= (const uchar *)temp_buf;
1281
uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
1283
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1284
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1286
fprintf(stderr, "\nError: Out of memory. "
1287
"Could not print correct binlog event.\n");
1291
if (base64_encode(ptr, (size_t) size, tmp_str))
1296
if (my_b_tell(file) == 0)
1297
my_b_printf(file, "\nBINLOG '\n");
1299
my_b_printf(file, "%s\n", tmp_str);
1302
my_b_printf(file, "'%s\n", print_event_info->delimiter);
1304
my_free(tmp_str, MYF(0));
1310
Log_event::print_timestamp()
1313
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
1318
#ifdef MYSQL_SERVER // This is always false
1320
localtime_r(ts,(res= &tm_tmp));
1325
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
1335
#endif /* MYSQL_CLIENT */
1338
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1067
1339
inline Log_event::enum_skip_reason
1068
1340
Log_event::continue_group(Relay_log_info *rli)
1482
1760
This is used by the SQL slave thread to prepare the event before execution.
1484
Query_log_event::Query_log_event(const char* buf, uint32_t event_len,
1762
Query_log_event::Query_log_event(const char* buf, uint event_len,
1485
1763
const Format_description_log_event
1486
1764
*description_event,
1487
1765
Log_event_type event_type)
1488
:Log_event(buf, description_event), data_buf(0), query(NULL),
1489
db(NULL), catalog_len(0), status_vars_len(0),
1766
:Log_event(buf, description_event), data_buf(0), query(NullS),
1767
db(NullS), catalog_len(0), status_vars_len(0),
1490
1768
flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1491
1769
auto_increment_increment(1), auto_increment_offset(1),
1492
1770
time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1496
uint8_t common_header_len, post_header_len;
1774
uint8 common_header_len, post_header_len;
1497
1775
Log_event::Byte *start;
1498
1776
const Log_event::Byte *end;
1499
1777
bool catalog_nz= 1;
1944
Query_log_event::print().
1947
print the catalog ??
1949
void Query_log_event::print_query_header(IO_CACHE* file,
1950
PRINT_EVENT_INFO* print_event_info)
1952
// TODO: print the catalog ??
1953
char buff[40],*end; // Enough for SET TIMESTAMP
1954
bool different_db= 1;
1957
if (!print_event_info->short_form)
1959
print_header(file, print_event_info, false);
1960
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
1961
get_type_str(), (ulong) thread_id, (ulong) exec_time,
1965
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
1967
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
1968
memcpy(print_event_info->db, db, db_len + 1);
1969
if (db[0] && different_db)
1970
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
1973
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
1974
end= strmov(end, print_event_info->delimiter);
1976
my_b_write(file, (uchar*) buff, (uint) (end-buff));
1977
if ((!print_event_info->thread_id_printed ||
1978
((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
1979
thread_id != print_event_info->thread_id)))
1981
// If --short-form, print deterministic value instead of pseudo_thread_id.
1982
my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
1983
short_form ? 999999999 : (ulong)thread_id,
1984
print_event_info->delimiter);
1985
print_event_info->thread_id= thread_id;
1986
print_event_info->thread_id_printed= 1;
1990
If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
1991
print (remember we don't produce mixed relay logs so there cannot be
1992
5.0 events before that one so there is nothing to reset).
1994
if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
1996
/* tmp is a bitmask of bits which have changed. */
1997
if (likely(print_event_info->flags2_inited))
1998
/* All bits which have changed */
1999
tmp= (print_event_info->flags2) ^ flags2;
2000
else /* that's the first Query event we read */
2002
print_event_info->flags2_inited= 1;
2003
tmp= ~((uint32)0); /* all bits have changed */
2006
if (unlikely(tmp)) /* some bits have changed */
2009
my_b_printf(file, "SET ");
2010
print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
2011
"@@session.foreign_key_checks", &need_comma);
2012
print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
2013
"@@session.sql_auto_is_null", &need_comma);
2014
print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
2015
"@@session.unique_checks", &need_comma);
2016
my_b_printf(file,"%s\n", print_event_info->delimiter);
2017
print_event_info->flags2= flags2;
2022
Now the session variables;
2023
it's more efficient to pass SQL_MODE as a number instead of a
2024
comma-separated list.
2025
FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
2026
variables (they have no global version; they're not listed in
2027
sql_class.h), The tests below work for pure binlogs or pure relay
2028
logs. Won't work for mixed relay logs but we don't create mixed
2029
relay logs (that is, there is no relay log with a format change
2030
except within the 3 first events, which mysqlbinlog handles
2031
gracefully). So this code should always be good.
2034
if (print_event_info->auto_increment_increment != auto_increment_increment ||
2035
print_event_info->auto_increment_offset != auto_increment_offset)
2037
my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
2038
auto_increment_increment,auto_increment_offset,
2039
print_event_info->delimiter);
2040
print_event_info->auto_increment_increment= auto_increment_increment;
2041
print_event_info->auto_increment_offset= auto_increment_offset;
2044
/* TODO: print the catalog when we feature SET CATALOG */
2046
if (likely(charset_inited) &&
2047
(unlikely(!print_event_info->charset_inited ||
2048
bcmp((uchar*) print_event_info->charset, (uchar*) charset, 6))))
2050
CHARSET_INFO *cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2053
/* for mysql client */
2054
my_b_printf(file, "/*!\\C %s */%s\n",
2055
cs_info->csname, print_event_info->delimiter);
2057
my_b_printf(file,"SET "
2058
"@@session.character_set_client=%d,"
2059
"@@session.collation_connection=%d,"
2060
"@@session.collation_server=%d"
2063
uint2korr(charset+2),
2064
uint2korr(charset+4),
2065
print_event_info->delimiter);
2066
memcpy(print_event_info->charset, charset, 6);
2067
print_event_info->charset_inited= 1;
2071
if (bcmp((uchar*) print_event_info->time_zone_str,
2072
(uchar*) time_zone_str, time_zone_len+1))
2074
my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2075
time_zone_str, print_event_info->delimiter);
2076
memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
2079
if (lc_time_names_number != print_event_info->lc_time_names_number)
2081
my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
2082
lc_time_names_number, print_event_info->delimiter);
2083
print_event_info->lc_time_names_number= lc_time_names_number;
2085
if (charset_database_number != print_event_info->charset_database_number)
2087
if (charset_database_number)
2088
my_b_printf(file, "SET @@session.collation_database=%d%s\n",
2089
charset_database_number, print_event_info->delimiter);
2091
my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
2092
print_event_info->delimiter);
2093
print_event_info->charset_database_number= charset_database_number;
2098
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2100
Write_on_release_cache cache(&print_event_info->head_cache, file);
2102
print_query_header(&cache, print_event_info);
2103
my_b_write(&cache, (uchar*) query, q_len);
2104
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
2106
#endif /* MYSQL_CLIENT */
1665
2110
Query_log_event::do_apply_event()
2113
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1667
2115
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1669
2117
return do_apply_event(rli, query, q_len);
1835
2283
clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
1838
rli->report(ERROR_LEVEL, expected_error,
1839
_("Query partially completed on the master "
1840
"(error on master: %d) and was aborted. There is a "
1841
"chance that your master is inconsistent at this "
1842
"point. If you are sure that your master is ok, run "
1843
"this query manually on the slave and then restart the "
1844
"slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; "
1845
"START SLAVE; . Query: '%s'"),
1846
expected_error, thd->query);
2286
rli->report(ERROR_LEVEL, expected_error,
2288
Query partially completed on the master (error on master: %d) \
2289
and was aborted. There is a chance that your master is inconsistent at this \
2290
point. If you are sure that your master is ok, run this query manually on the \
2291
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
2292
START SLAVE; . Query: '%s'", expected_error, thd->query);
1847
2293
thd->is_slave_error= 1;
2298
/* If the query was not ignored, it is printed to the general log */
2299
if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
2300
general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
1852
2302
compare_errors:
1988
2439
return(Log_event::do_shall_skip(rli));
1992
2445
/**************************************************************************
1993
2446
Start_log_event_v3 methods
1994
2447
**************************************************************************/
2449
#ifndef MYSQL_CLIENT
1996
2450
Start_log_event_v3::Start_log_event_v3()
1997
2451
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
1998
2452
artificial_event(0), dont_set_created(0)
2000
2454
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2004
2459
Start_log_event_v3::pack_info()
2462
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2007
2463
void Start_log_event_v3::pack_info(Protocol *protocol)
2009
2465
char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
2010
pos= my_stpcpy(buf, "Server ver: ");
2011
pos= my_stpcpy(pos, server_version);
2012
pos= my_stpcpy(pos, ", Binlog ver: ");
2466
pos= strmov(buf, "Server ver: ");
2467
pos= strmov(pos, server_version);
2468
pos= strmov(pos, ", Binlog ver: ");
2013
2469
pos= int10_to_str(binlog_version, pos, 10);
2014
2470
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2476
Start_log_event_v3::print()
2480
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2482
Write_on_release_cache cache(&print_event_info->head_cache, file,
2483
Write_on_release_cache::FLUSH_F);
2485
if (!print_event_info->short_form)
2487
print_header(&cache, print_event_info, false);
2488
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2489
binlog_version, server_version);
2490
print_timestamp(&cache);
2492
my_b_printf(&cache," at startup");
2493
my_b_printf(&cache, "\n");
2494
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
2495
my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
2496
"Most probably mysqld crashed writing it.\n");
2498
if (!artificial_event && created)
2500
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
2502
This is for mysqlbinlog: like in replication, we want to delete the stale
2503
tmp files left by an unclean shutdown of mysqld (temporary tables)
2504
and rollback unfinished transaction.
2505
Probably this can be done with RESET CONNECTION (syntax to be defined).
2507
my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
2509
my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
2513
print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
2514
!print_event_info->short_form)
2516
my_b_printf(&cache, "BINLOG '\n");
2517
print_base64(&cache, print_event_info, false);
2518
print_event_info->printed_fd_event= true;
2522
#endif /* MYSQL_CLIENT */
2019
2525
Start_log_event_v3::Start_log_event_v3()
2542
3058
if (need_db && db && db_len)
2544
pos= my_stpcpy(pos, "use `");
3060
pos= strmov(pos, "use `");
2545
3061
memcpy(pos, db, db_len);
2546
pos= my_stpcpy(pos+db_len, "`; ");
3062
pos= strmov(pos+db_len, "`; ");
2549
pos= my_stpcpy(pos, "LOAD DATA ");
3065
pos= strmov(pos, "LOAD DATA ");
2552
3068
*fn_start= pos;
2554
3070
if (check_fname_outside_temp_buf())
2555
pos= my_stpcpy(pos, "LOCAL ");
2556
pos= my_stpcpy(pos, "INFILE '");
3071
pos= strmov(pos, "LOCAL ");
3072
pos= strmov(pos, "INFILE '");
2557
3073
memcpy(pos, fname, fname_len);
2558
pos= my_stpcpy(pos+fname_len, "' ");
3074
pos= strmov(pos+fname_len, "' ");
2560
3076
if (sql_ex.opt_flags & REPLACE_FLAG)
2561
pos= my_stpcpy(pos, " REPLACE ");
3077
pos= strmov(pos, " REPLACE ");
2562
3078
else if (sql_ex.opt_flags & IGNORE_FLAG)
2563
pos= my_stpcpy(pos, " IGNORE ");
3079
pos= strmov(pos, " IGNORE ");
2565
pos= my_stpcpy(pos ,"INTO");
3081
pos= strmov(pos ,"INTO");
2570
pos= my_stpcpy(pos ," Table `");
3086
pos= strmov(pos ," TABLE `");
2571
3087
memcpy(pos, table_name, table_name_len);
2572
3088
pos+= table_name_len;
2574
3090
/* We have to create all optinal fields as the default is not empty */
2575
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3091
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2576
3092
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2577
3093
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2578
pos= my_stpcpy(pos, " OPTIONALLY ");
2579
pos= my_stpcpy(pos, " ENCLOSED BY ");
3094
pos= strmov(pos, " OPTIONALLY ");
3095
pos= strmov(pos, " ENCLOSED BY ");
2580
3096
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2582
pos= my_stpcpy(pos, " ESCAPED BY ");
3098
pos= strmov(pos, " ESCAPED BY ");
2583
3099
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2585
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3101
pos= strmov(pos, " LINES TERMINATED BY ");
2586
3102
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2587
3103
if (sql_ex.line_start_len)
2589
pos= my_stpcpy(pos, " STARTING BY ");
3105
pos= strmov(pos, " STARTING BY ");
2590
3106
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2593
3109
if ((long) skip_lines > 0)
2595
pos= my_stpcpy(pos, " IGNORE ");
3111
pos= strmov(pos, " IGNORE ");
2596
3112
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2597
pos= my_stpcpy(pos," LINES ");
3113
pos= strmov(pos," LINES ");
2600
3116
if (num_fields)
2603
3119
const char *field= fields;
2604
pos= my_stpcpy(pos, " (");
3120
pos= strmov(pos, " (");
2605
3121
for (i = 0; i < num_fields; i++)
3355
Load_log_event::print()
3359
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
3361
print(file, print_event_info, 0);
3365
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
3368
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3370
if (!print_event_info->short_form)
3372
print_header(&cache, print_event_info, false);
3373
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3374
thread_id, exec_time);
3377
bool different_db= 1;
3381
If the database is different from the one of the previous statement, we
3382
need to print the "use" command, and we update the last_db.
3383
But if commented, the "use" is going to be commented so we should not
3386
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
3388
memcpy(print_event_info->db, db, db_len + 1);
3391
if (db && db[0] && different_db)
3392
my_b_printf(&cache, "%suse %s%s\n",
3393
commented ? "# " : "",
3394
db, print_event_info->delimiter);
3396
if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
3397
my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
3398
commented ? "# " : "", (ulong)thread_id,
3399
print_event_info->delimiter);
3400
my_b_printf(&cache, "%sLOAD DATA ",
3401
commented ? "# " : "");
3402
if (check_fname_outside_temp_buf())
3403
my_b_printf(&cache, "LOCAL ");
3404
my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
3406
if (sql_ex.opt_flags & REPLACE_FLAG)
3407
my_b_printf(&cache," REPLACE ");
3408
else if (sql_ex.opt_flags & IGNORE_FLAG)
3409
my_b_printf(&cache," IGNORE ");
3411
my_b_printf(&cache, "INTO TABLE `%s`", table_name);
3412
my_b_printf(&cache, " FIELDS TERMINATED BY ");
3413
pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
3415
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3416
my_b_printf(&cache," OPTIONALLY ");
3417
my_b_printf(&cache, " ENCLOSED BY ");
3418
pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
3420
my_b_printf(&cache, " ESCAPED BY ");
3421
pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
3423
my_b_printf(&cache," LINES TERMINATED BY ");
3424
pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
3427
if (sql_ex.line_start)
3429
my_b_printf(&cache," STARTING BY ");
3430
pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
3432
if ((long) skip_lines > 0)
3433
my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
3438
const char* field = fields;
3439
my_b_printf(&cache, " (");
3440
for (i = 0; i < num_fields; i++)
3443
my_b_printf(&cache, ",");
3444
my_b_printf(&cache, field);
3446
field += field_lens[i] + 1;
3448
my_b_printf(&cache, ")");
3451
my_b_printf(&cache, "%s\n", print_event_info->delimiter);
3454
#endif /* MYSQL_CLIENT */
3456
#ifndef MYSQL_CLIENT
2835
3459
Load_log_event::set_fields()
3351
4012
Intvar_log_event::write()
4015
#ifndef MYSQL_CLIENT
3354
4016
bool Intvar_log_event::write(IO_CACHE* file)
3356
unsigned char buf[9];
3357
buf[I_TYPE_OFFSET]= (unsigned char) type;
4019
buf[I_TYPE_OFFSET]= (uchar) type;
3358
4020
int8store(buf + I_VAL_OFFSET, val);
3359
4021
return (write_header(file, sizeof(buf)) ||
3360
4022
my_b_safe_write(file, buf, sizeof(buf)));
3365
4028
Intvar_log_event::print()
4032
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4036
Write_on_release_cache cache(&print_event_info->head_cache, file,
4037
Write_on_release_cache::FLUSH_F);
4039
if (!print_event_info->short_form)
4041
print_header(&cache, print_event_info, false);
4042
my_b_printf(&cache, "\tIntvar\n");
4045
my_b_printf(&cache, "SET ");
4047
case LAST_INSERT_ID_EVENT:
4048
msg="LAST_INSERT_ID";
4050
case INSERT_ID_EVENT:
4053
case INVALID_INT_EVENT:
4054
default: // cannot happen
4058
my_b_printf(&cache, "%s=%s%s\n",
4059
msg, llstr(val,llbuff), print_event_info->delimiter);
3369
4065
Intvar_log_event::do_apply_event()
4068
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3372
4069
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
4140
#ifndef MYSQL_CLIENT
3439
4141
bool Rand_log_event::write(IO_CACHE* file)
3441
unsigned char buf[16];
3442
4144
int8store(buf + RAND_SEED1_OFFSET, seed1);
3443
4145
int8store(buf + RAND_SEED2_OFFSET, seed2);
3444
4146
return (write_header(file, sizeof(buf)) ||
3445
4147
my_b_safe_write(file, buf, sizeof(buf)));
4153
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4155
Write_on_release_cache cache(&print_event_info->head_cache, file,
4156
Write_on_release_cache::FLUSH_F);
4158
char llbuff[22],llbuff2[22];
4159
if (!print_event_info->short_form)
4161
print_header(&cache, print_event_info, false);
4162
my_b_printf(&cache, "\tRand\n");
4164
my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
4165
llstr(seed1, llbuff),llstr(seed2, llbuff2),
4166
print_event_info->delimiter);
4168
#endif /* MYSQL_CLIENT */
4171
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3449
4172
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
3509
4236
:Log_event(buf, description_event)
3511
4238
buf+= description_event->common_header_len;
3512
memcpy(&xid, buf, sizeof(xid));
4239
memcpy((char*) &xid, buf, sizeof(xid));
4243
#ifndef MYSQL_CLIENT
3516
4244
bool Xid_log_event::write(IO_CACHE* file)
3518
4246
return write_header(file, sizeof(xid)) ||
3519
my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
3523
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4247
my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
4253
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4255
Write_on_release_cache cache(&print_event_info->head_cache, file,
4256
Write_on_release_cache::FLUSH_F);
4258
if (!print_event_info->short_form)
4261
int64_t10_to_str(xid, buf, 10);
4263
print_header(&cache, print_event_info, false);
4264
my_b_printf(&cache, "\tXid = %s\n", buf);
4266
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4268
#endif /* MYSQL_CLIENT */
4271
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4272
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4274
/* For a slave Xid_log_event is COMMIT */
4275
general_log_print(thd, COM_QUERY,
4276
"COMMIT /* implicit, from Xid_log_event */");
3525
4277
return end_trans(thd, COMMIT);
3702
4458
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3704
4460
return (write_header(file, event_length) ||
3705
my_b_safe_write(file, (unsigned char*) buf, sizeof(buf)) ||
3706
my_b_safe_write(file, (unsigned char*) name, name_len) ||
3707
my_b_safe_write(file, (unsigned char*) buf1, buf1_length) ||
4461
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
4462
my_b_safe_write(file, (uchar*) name, name_len) ||
4463
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3708
4464
my_b_safe_write(file, pos, val_len));
4470
User_var_log_event::print()
4474
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4476
Write_on_release_cache cache(&print_event_info->head_cache, file,
4477
Write_on_release_cache::FLUSH_F);
4479
if (!print_event_info->short_form)
4481
print_header(&cache, print_event_info, false);
4482
my_b_printf(&cache, "\tUser_var\n");
4485
my_b_printf(&cache, "SET @`");
4486
my_b_write(&cache, (uchar*) name, (uint) (name_len));
4487
my_b_printf(&cache, "`");
4491
my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
4498
char real_buf[FMT_G_BUFSIZE(14)];
4499
float8get(real_val, val);
4500
my_sprintf(real_buf, (real_buf, "%.14g", real_val));
4501
my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
4505
int64_t10_to_str(uint8korr(val), int_buf, -10);
4506
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
4508
case DECIMAL_RESULT:
4511
int str_len= sizeof(str_buf) - 1;
4512
int precision= (int)val[0];
4513
int scale= (int)val[1];
4514
decimal_digit_t dec_buf[10];
4519
bin2decimal((uchar*) val+2, &dec, precision, scale);
4520
decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
4521
str_buf[str_len]= 0;
4522
my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
4528
Let's express the string in hex. That's the most robust way. If we
4529
print it in character form instead, we need to escape it with
4530
character_set_client which we don't know (we will know it in 5.0, but
4531
in 4.1 we don't know it easily when we are printing
4532
User_var_log_event). Explanation why we would need to bother with
4533
character_set_client (quoting Bar):
4534
> Note, the parser doesn't switch to another unescaping mode after
4535
> it has met a character set introducer.
4536
> For example, if an SJIS client says something like:
4537
> SET @a= _ucs2 \0a\0b'
4538
> the string constant is still unescaped according to SJIS, not
4539
> according to UCS2.
4544
if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4545
break; // no error, as we are 'void'
4546
str_to_hex(hex_str, val, val_len);
4548
For proper behaviour when mysqlbinlog|mysql, we need to explicitely
4549
specify the variable's collation. It will however cause problems when
4550
people want to mysqlbinlog|mysql into another server not supporting the
4551
character set. But there's not much to do about this and it's unlikely.
4553
if (!(cs= get_charset(charset_number, MYF(0))))
4555
Generate an unusable command (=> syntax error) is probably the best
4556
thing we can do here.
4558
my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
4560
my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
4561
cs->csname, hex_str, cs->name,
4562
print_event_info->delimiter);
3714
4577
User_var_log_event::do_apply_event()
4580
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3717
4581
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3720
const CHARSET_INFO *charset;
4584
CHARSET_INFO *charset;
3721
4585
if (!(charset= get_charset(charset_number, MYF(MY_WME))))
3723
4587
LEX_STRING user_var_name;
3805
4669
return continue_group(rli);
4671
#endif /* !MYSQL_CLIENT */
3809
4674
/**************************************************************************
3810
4675
Slave_log_event methods
3811
4676
**************************************************************************/
4678
#ifdef HAVE_REPLICATION
4680
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
4682
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
4684
if (print_event_info->short_form)
4686
print_header(&cache, print_event_info, false);
4687
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4691
#ifndef MYSQL_CLIENT
3813
4692
void Slave_log_event::pack_info(Protocol *protocol)
3815
4694
char buf[256+HOSTNAME_LENGTH], *pos;
3816
pos= my_stpcpy(buf, "host=");
3817
pos= my_stpncpy(pos, master_host, HOSTNAME_LENGTH);
3818
pos= my_stpcpy(pos, ",port=");
4695
pos= strmov(buf, "host=");
4696
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4697
pos= strmov(pos, ",port=");
3819
4698
pos= int10_to_str((long) master_port, pos, 10);
3820
pos= my_stpcpy(pos, ",log=");
3821
pos= my_stpcpy(pos, master_log);
3822
pos= my_stpcpy(pos, ",pos=");
4699
pos= strmov(pos, ",log=");
4700
pos= strmov(pos, master_log);
4701
pos= strmov(pos, ",pos=");
3823
4702
pos= int64_t10_to_str(master_pos, pos, 10);
3824
4703
protocol->store(buf, pos-buf, &my_charset_bin);
4705
#endif /* !MYSQL_CLIENT */
4708
#ifndef MYSQL_CLIENT
3830
4711
re-write this better without holding both locks at the same time
5012
Create_file_log_event::print()
5016
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
5019
Write_on_release_cache cache(&print_event_info->head_cache, file);
5021
if (print_event_info->short_form)
5023
if (enable_local && check_fname_outside_temp_buf())
5024
Load_log_event::print(file, print_event_info);
5030
Load_log_event::print(file, print_event_info,
5031
!check_fname_outside_temp_buf());
5033
That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
5034
SHOW BINLOG EVENTS we don't.
5036
my_b_printf(&cache, "#");
5039
my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len);
5043
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
5045
print(file, print_event_info, 0);
5047
#endif /* MYSQL_CLIENT */
4084
5051
Create_file_log_event::pack_info()
5054
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4087
5055
void Create_file_log_event::pack_info(Protocol *protocol)
4089
5057
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4090
pos= my_stpcpy(buf, "db=");
5058
pos= strmov(buf, "db=");
4091
5059
memcpy(pos, db, db_len);
4092
pos= my_stpcpy(pos + db_len, ";table=");
5060
pos= strmov(pos + db_len, ";table=");
4093
5061
memcpy(pos, table_name, table_name_len);
4094
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5062
pos= strmov(pos + table_name_len, ";file_id=");
4095
5063
pos= int10_to_str((long) file_id, pos, 10);
4096
pos= my_stpcpy(pos, ";block_len=");
5064
pos= strmov(pos, ";block_len=");
4097
5065
pos= int10_to_str((long) block_len, pos, 10);
4098
5066
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5068
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4103
5072
Create_file_log_event::do_apply_event()
5075
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4106
5076
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4108
5078
char proc_info[17+FN_REFLEN+10], *fname_buf;
4123
5093
MYF(MY_WME|MY_NABP)))
4125
5095
rli->report(ERROR_LEVEL, my_errno,
4126
_("Error in Create_file event: could not open file '%s'"),
5096
"Error in Create_file event: could not open file '%s'",
4131
5101
// a trick to avoid allocating another buffer
4132
5102
fname= fname_buf;
4133
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5103
fname_len= (uint) (strmov(ext, ".data") - fname);
4134
5104
if (write_base(&file))
4136
my_stpcpy(ext, ".info"); // to have it right in the error message
5106
strmov(ext, ".info"); // to have it right in the error message
4137
5107
rli->report(ERROR_LEVEL, my_errno,
4138
_("Error in Create_file event: could not write to file '%s'"),
5108
"Error in Create_file event: could not write to file '%s'",
4142
5112
end_io_cache(&file);
4143
5113
my_close(fd, MYF(0));
4145
5115
// fname_buf now already has .data, not .info, because we did our trick
4146
5116
my_delete(fname_buf, MYF(0)); // old copy may exist already
4147
5117
if ((fd= my_create(fname_buf, CREATE_MODE,
4148
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
5118
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4151
5121
rli->report(ERROR_LEVEL, my_errno,
4152
_("Error in Create_file event: could not open file '%s'"),
5122
"Error in Create_file event: could not open file '%s'",
4156
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5126
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4158
5128
rli->report(ERROR_LEVEL, my_errno,
4159
_("Error in Create_file event: write to '%s' failed"),
5129
"Error in Create_file event: write to '%s' failed",
4180
5151
Append_block_log_event ctor
5154
#ifndef MYSQL_CLIENT
4183
5155
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4184
5156
const char *db_arg,
4185
unsigned char *block_arg,
4186
uint32_t block_len_arg,
4187
5159
bool using_trans)
4188
5160
:Log_event(thd_arg,0, using_trans), block(block_arg),
4189
5161
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4195
5168
Append_block_log_event ctor
4198
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5171
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4199
5172
const Format_description_log_event* description_event)
4200
5173
:Log_event(buf, description_event),block(0)
4202
uint8_t common_header_len= description_event->common_header_len;
4203
uint8_t append_block_header_len=
5175
uint8 common_header_len= description_event->common_header_len;
5176
uint8 append_block_header_len=
4204
5177
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4205
uint32_t total_header_len= common_header_len+append_block_header_len;
5178
uint total_header_len= common_header_len+append_block_header_len;
4206
5179
if (len < total_header_len)
4208
5181
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4209
block= (unsigned char*)buf + total_header_len;
5182
block= (uchar*)buf + total_header_len;
4210
5183
block_len= len - total_header_len;
4216
5189
Append_block_log_event::write()
5192
#ifndef MYSQL_CLIENT
4219
5193
bool Append_block_log_event::write(IO_CACHE* file)
4221
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5195
uchar buf[APPEND_BLOCK_HEADER_LEN];
4222
5196
int4store(buf + AB_FILE_ID_OFFSET, file_id);
4223
5197
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4224
5198
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4225
my_b_safe_write(file, (unsigned char*) block, block_len));
5199
my_b_safe_write(file, (uchar*) block, block_len));
5205
Append_block_log_event::print()
5209
void Append_block_log_event::print(FILE* file,
5210
PRINT_EVENT_INFO* print_event_info)
5212
Write_on_release_cache cache(&print_event_info->head_cache, file);
5214
if (print_event_info->short_form)
5216
print_header(&cache, print_event_info, false);
5217
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5218
get_type_str(), file_id, block_len);
5220
#endif /* MYSQL_CLIENT */
4230
5224
Append_block_log_event::pack_info()
5227
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4233
5228
void Append_block_log_event::pack_info(Protocol *protocol)
4237
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
5232
length= (uint) my_sprintf(buf,
5233
(buf, ";file_id=%u;block_len=%u", file_id,
4239
5235
protocol->store(buf, length, &my_charset_bin);
4334
5333
Delete_file_log_event::write()
5336
#ifndef MYSQL_CLIENT
4337
5337
bool Delete_file_log_event::write(IO_CACHE* file)
4339
unsigned char buf[DELETE_FILE_HEADER_LEN];
5339
uchar buf[DELETE_FILE_HEADER_LEN];
4340
5340
int4store(buf + DF_FILE_ID_OFFSET, file_id);
4341
5341
return (write_header(file, sizeof(buf)) ||
4342
5342
my_b_safe_write(file, buf, sizeof(buf)));
5348
Delete_file_log_event::print()
5352
void Delete_file_log_event::print(FILE* file,
5353
PRINT_EVENT_INFO* print_event_info)
5355
Write_on_release_cache cache(&print_event_info->head_cache, file);
5357
if (print_event_info->short_form)
5359
print_header(&cache, print_event_info, false);
5360
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5362
#endif /* MYSQL_CLIENT */
4347
5365
Delete_file_log_event::pack_info()
5368
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4350
5369
void Delete_file_log_event::pack_info(Protocol *protocol)
4354
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4355
protocol->store(buf, (int32_t) length, &my_charset_bin);
5373
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5374
protocol->store(buf, (int32) length, &my_charset_bin);
4359
5379
Delete_file_log_event::do_apply_event()
4362
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
5382
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5383
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4364
5385
char fname[FN_REFLEN+10];
4365
5386
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4366
5387
(void) my_delete(fname, MYF(MY_WME));
4367
my_stpcpy(ext, ".info");
5388
strmov(ext, ".info");
4368
5389
(void) my_delete(fname, MYF(MY_WME));
5392
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4373
5395
/**************************************************************************
4406
5430
Execute_load_log_event::write()
5433
#ifndef MYSQL_CLIENT
4409
5434
bool Execute_load_log_event::write(IO_CACHE* file)
4411
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5436
uchar buf[EXEC_LOAD_HEADER_LEN];
4412
5437
int4store(buf + EL_FILE_ID_OFFSET, file_id);
4413
5438
return (write_header(file, sizeof(buf)) ||
4414
5439
my_b_safe_write(file, buf, sizeof(buf)));
5445
Execute_load_log_event::print()
5449
void Execute_load_log_event::print(FILE* file,
5450
PRINT_EVENT_INFO* print_event_info)
5452
Write_on_release_cache cache(&print_event_info->head_cache, file);
5454
if (print_event_info->short_form)
5456
print_header(&cache, print_event_info, false);
5457
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
4419
5463
Execute_load_log_event::pack_info()
5466
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4422
5467
void Execute_load_log_event::pack_info(Protocol *protocol)
4426
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4427
protocol->store(buf, (int32_t) length, &my_charset_bin);
5471
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5472
protocol->store(buf, (int32) length, &my_charset_bin);
5564
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4523
5567
/**************************************************************************
4524
5568
Begin_load_query_log_event methods
4525
5569
**************************************************************************/
5571
#ifndef MYSQL_CLIENT
4527
5572
Begin_load_query_log_event::
4528
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, unsigned char* block_arg,
4529
uint32_t block_len_arg, bool using_trans)
5573
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5574
uint block_len_arg, bool using_trans)
4530
5575
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4533
5578
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4537
5583
Begin_load_query_log_event::
4538
Begin_load_query_log_event(const char* buf, uint32_t len,
5584
Begin_load_query_log_event(const char* buf, uint len,
4539
5585
const Format_description_log_event* desc_event)
4540
5586
:Append_block_log_event(buf, len, desc_event)
5591
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4545
5592
int Begin_load_query_log_event::get_create_or_append() const
4547
5594
return 1; /* create the file */
5596
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5599
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4551
5600
Log_event::enum_skip_reason
4552
5601
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5663
#ifndef MYSQL_CLIENT
4612
5665
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4614
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5667
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4615
5668
int4store(buf, file_id);
4616
5669
int4store(buf + 4, fn_pos_start);
4617
5670
int4store(buf + 4 + 4, fn_pos_end);
4618
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5671
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4619
5672
return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
5678
void Execute_load_query_log_event::print(FILE* file,
5679
PRINT_EVENT_INFO* print_event_info)
5681
print(file, print_event_info, 0);
5685
Prints the query as LOAD DATA LOCAL and with rewritten filename.
5687
void Execute_load_query_log_event::print(FILE* file,
5688
PRINT_EVENT_INFO* print_event_info,
5689
const char *local_fname)
5691
Write_on_release_cache cache(&print_event_info->head_cache, file);
5693
print_query_header(&cache, print_event_info);
5697
my_b_write(&cache, (uchar*) query, fn_pos_start);
5698
my_b_printf(&cache, " LOCAL INFILE \'");
5699
my_b_printf(&cache, local_fname);
5700
my_b_printf(&cache, "\'");
5701
if (dup_handling == LOAD_DUP_REPLACE)
5702
my_b_printf(&cache, " REPLACE");
5703
my_b_printf(&cache, " INTO");
5704
my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
5705
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5709
my_b_write(&cache, (uchar*) query, q_len);
5710
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5713
if (!print_event_info->short_form)
5714
my_b_printf(&cache, "# file_id: %d \n", file_id);
5719
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4623
5720
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4625
5722
char *buf, *pos;
5758
6900
const char *const vpart= buf + common_header_len + post_header_len;
5760
6902
/* Extract the length of the various parts from the buffer */
5761
unsigned char const *const ptr_dblen= (unsigned char const*)vpart + 0;
5762
m_dblen= *(unsigned char*) ptr_dblen;
6903
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
6904
m_dblen= *(uchar*) ptr_dblen;
5764
6906
/* Length of database name + counter + terminating null */
5765
unsigned char const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
5766
m_tbllen= *(unsigned char*) ptr_tbllen;
6907
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
6908
m_tbllen= *(uchar*) ptr_tbllen;
5768
6910
/* Length of table name + counter + terminating null */
5769
unsigned char const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
5770
unsigned char *ptr_after_colcnt= (unsigned char*) ptr_colcnt;
6911
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
6912
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5771
6913
m_colcnt= net_field_length(&ptr_after_colcnt);
5773
6915
/* Allocate mem for all fields in one go. If fails, caught in is_valid() */
5774
m_memory= (unsigned char*) my_multi_malloc(MYF(MY_WME),
6916
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5775
6917
&m_dbnam, (uint) m_dblen + 1,
5776
6918
&m_tblnam, (uint) m_tbllen + 1,
5777
6919
&m_coltype, (uint) m_colcnt,
5785
6927
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5787
6929
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5788
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
6930
bytes_read= ptr_after_colcnt - (uchar *)buf;
5789
6931
if (bytes_read < event_len)
5791
6933
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5792
6934
assert(m_field_metadata_size <= (m_colcnt * 2));
5793
uint32_t num_null_bytes= (m_colcnt + 7) / 8;
5794
m_meta_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
6935
uint num_null_bytes= (m_colcnt + 7) / 8;
6936
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5795
6937
&m_null_bits, num_null_bytes,
5796
6938
&m_field_metadata, m_field_metadata_size,
5798
6940
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5799
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
6941
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5800
6942
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5807
6950
Table_map_log_event::~Table_map_log_event()
5809
free(m_meta_memory);
6952
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
6953
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5835
6979
pthread_mutex_unlock(&LOCK_thread_count);
5837
6981
if (!(memory= my_multi_malloc(MYF(MY_WME),
5838
&table_list, (uint) sizeof(RPL_TableList),
6982
&table_list, (uint) sizeof(RPL_TABLE_LIST),
5839
6983
&db_mem, (uint) NAME_LEN + 1,
5840
6984
&tname_mem, (uint) NAME_LEN + 1,
5842
6986
return(HA_ERR_OUT_OF_MEM);
5844
memset(table_list, 0, sizeof(*table_list));
6988
bzero(table_list, sizeof(*table_list));
5845
6989
table_list->db = db_mem;
5846
6990
table_list->alias= table_list->table_name = tname_mem;
5847
6991
table_list->lock_type= TL_WRITE;
5848
6992
table_list->next_global= table_list->next_local= 0;
5849
6993
table_list->table_id= m_table_id;
5850
6994
table_list->updating= 1;
5851
my_stpcpy(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
5852
my_stpcpy(table_list->table_name, m_tblnam);
6995
strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
6996
strmov(table_list->table_name, m_tblnam);
5856
7000
if (!rpl_filter->db_ok(table_list->db) ||
5857
7001
(rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list)))
7003
my_free(memory, MYF(MY_WME));
5991
7136
assert(m_dblen < 128);
5992
7137
assert(m_tbllen < 128);
5994
unsigned char const dbuf[]= { (unsigned char) m_dblen };
5995
unsigned char const tbuf[]= { (unsigned char) m_tbllen };
7139
uchar const dbuf[]= { (uchar) m_dblen };
7140
uchar const tbuf[]= { (uchar) m_tbllen };
5997
unsigned char cbuf[sizeof(m_colcnt)];
5998
unsigned char *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
7142
uchar cbuf[sizeof(m_colcnt)];
7143
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5999
7144
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
6002
7147
Store the size of the field metadata.
6004
unsigned char mbuf[sizeof(m_field_metadata_size)];
6005
unsigned char *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
7149
uchar mbuf[sizeof(m_field_metadata_size)];
7150
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
6007
7152
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
6008
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7153
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
6009
7154
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
6010
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7155
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
6011
7156
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
6012
7157
my_b_safe_write(file, m_coltype, m_colcnt) ||
6013
7158
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
6014
7159
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
6015
7160
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7164
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6020
7167
Print some useful information for the SHOW BINARY LOG information
7171
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6024
7172
void Table_map_log_event::pack_info(Protocol *protocol)
6907
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
8111
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
8114
void Update_rows_log_event::print(FILE *file,
8115
PRINT_EVENT_INFO* print_event_info)
8117
Rows_log_event::print_helper(file, print_event_info, "Update_rows");
8122
Incident_log_event::Incident_log_event(const char *buf, uint event_len,
6908
8123
const Format_description_log_event *descr_event)
6909
8124
: Log_event(buf, descr_event)
6911
uint8_t const common_header_len=
8126
uint8 const common_header_len=
6912
8127
descr_event->common_header_len;
6913
uint8_t const post_header_len=
8128
uint8 const post_header_len=
6914
8129
descr_event->post_header_len[INCIDENT_EVENT-1];
6916
8131
m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
6917
8132
char const *ptr= buf + common_header_len + post_header_len;
6918
8133
char const *const str_end= buf + event_len;
6919
uint8_t len= 0; // Assignment to keep compiler happy
8134
uint8 len= 0; // Assignment to keep compiler happy
6920
8135
const char *str= NULL; // Assignment to keep compiler happy
6921
8136
read_str(&ptr, str_end, &str, &len);
6922
8137
m_message.str= const_cast<char*>(str);
6984
8216
return(write_str(file, m_message.str, m_message.length));
6987
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
8219
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8220
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6988
8221
const Format_description_log_event* description_event)
6989
8222
:Log_event(buf, description_event)
6991
uint8_t header_size= description_event->common_header_len;
8224
uint8 header_size= description_event->common_header_len;
6992
8225
ident_len = event_len - header_size;
6993
8226
set_if_smaller(ident_len,FN_REFLEN-1);
6994
8227
log_ident= buf + header_size;
8234
The default values for these variables should be values that are
8235
*incorrect*, i.e., values that cannot occur in an event. This way,
8236
they will always be printed for the first event.
8238
st_print_event_info::st_print_event_info()
8239
:flags2_inited(0), sql_mode_inited(0),
8240
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
8241
lc_time_names_number(~0),
8242
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8243
thread_id(0), thread_id_printed(false),
8244
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
8247
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
8248
program's startup, but these explicit bzero() is for the day someone
8249
creates dynamic instances.
8251
bzero(db, sizeof(db));
8252
bzero(charset, sizeof(charset));
8253
bzero(time_zone_str, sizeof(time_zone_str));
8256
myf const flags = MYF(MY_WME | MY_NABP);
8257
open_cached_file(&head_cache, NULL, NULL, 0, flags);
8258
open_cached_file(&body_cache, NULL, NULL, 0, flags);