1058
1139
if (!ev || !ev->is_valid())
1143
if (!force_opt) /* then mysqlbinlog dies */
1145
*error= "Found invalid event in binary log";
1148
ev= new Unknown_log_event(buf, description_event);
1061
1150
*error= "Found invalid event in binary log";
1160
Log_event::print_header()
1163
void Log_event::print_header(IO_CACHE* file,
1164
PRINT_EVENT_INFO* print_event_info,
1165
bool is_more __attribute__((unused)))
1168
my_off_t hexdump_from= print_event_info->hexdump_from;
1170
my_b_printf(file, "#");
1171
print_timestamp(file);
1172
my_b_printf(file, " server id %d end_log_pos %s ", server_id,
1173
llstr(log_pos,llbuff));
1175
/* mysqlbinlog --hexdump */
1176
if (print_event_info->hexdump_from)
1178
my_b_printf(file, "\n");
1179
uchar *ptr= (uchar*)temp_buf;
1181
uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
1184
/* Header len * 4 >= header len * (2 chars + space + extra space) */
1185
char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
1186
char *c, char_string[16+1]= {0};
1188
/* Pretty-print event common header if header is exactly 19 bytes */
1189
if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
1191
char emit_buf[256]; // Enough for storing one line
1192
my_b_printf(file, "# Position Timestamp Type Master ID "
1193
"Size Master Pos Flags \n");
1194
int const bytes_written=
1195
snprintf(emit_buf, sizeof(emit_buf),
1196
"# %8.8lx %02x %02x %02x %02x %02x "
1197
"%02x %02x %02x %02x %02x %02x %02x %02x "
1198
"%02x %02x %02x %02x %02x %02x\n",
1199
(unsigned long) hexdump_from,
1200
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1201
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1202
ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
1203
assert(bytes_written >= 0);
1204
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1205
my_b_write(file, (uchar*) emit_buf, bytes_written);
1206
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1207
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1210
/* Rest of event (without common header) */
1211
for (i= 0, c= char_string, h=hex_string;
1215
snprintf(h, 4, "%02x ", *ptr);
1218
*c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
1223
my_b_printf() does not support full printf() formats, so we
1224
have to do it this way.
1226
TODO: Rewrite my_b_printf() to support full printf() syntax.
1229
int const bytes_written=
1230
snprintf(emit_buf, sizeof(emit_buf),
1231
"# %8.8lx %-48.48s |%16s|\n",
1232
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1233
hex_string, char_string);
1234
assert(bytes_written >= 0);
1235
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1236
my_b_write(file, (uchar*) emit_buf, bytes_written);
1242
else if (i % 8 == 7) *h++ = ' ';
1249
int const bytes_written=
1250
snprintf(emit_buf, sizeof(emit_buf),
1251
"# %8.8lx %-48.48s |%s|\n",
1252
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1253
hex_string, char_string);
1254
assert(bytes_written >= 0);
1255
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1256
my_b_write(file, (uchar*) emit_buf, bytes_written);
1259
need a # to prefix the rest of printouts for example those of
1260
Rows_log_event::print_helper().
1262
my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
1268
void Log_event::print_base64(IO_CACHE* file,
1269
PRINT_EVENT_INFO* print_event_info,
1272
const uchar *ptr= (const uchar *)temp_buf;
1273
uint32_t size= uint4korr(ptr + EVENT_LEN_OFFSET);
1275
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1276
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1278
fprintf(stderr, "\nError: Out of memory. "
1279
"Could not print correct binlog event.\n");
1283
if (base64_encode(ptr, (size_t) size, tmp_str))
1288
if (my_b_tell(file) == 0)
1289
my_b_printf(file, "\nBINLOG '\n");
1291
my_b_printf(file, "%s\n", tmp_str);
1294
my_b_printf(file, "'%s\n", print_event_info->delimiter);
1296
my_free(tmp_str, MYF(0));
1302
Log_event::print_timestamp()
1305
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
1310
#ifdef MYSQL_SERVER // This is always false
1312
localtime_r(ts,(res= &tm_tmp));
1317
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
1327
#endif /* MYSQL_CLIENT */
1330
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1067
1331
inline Log_event::enum_skip_reason
1068
1332
Log_event::continue_group(Relay_log_info *rli)
1936
Query_log_event::print().
1939
print the catalog ??
1941
void Query_log_event::print_query_header(IO_CACHE* file,
1942
PRINT_EVENT_INFO* print_event_info)
1944
// TODO: print the catalog ??
1945
char buff[40],*end; // Enough for SET TIMESTAMP
1946
bool different_db= 1;
1949
if (!print_event_info->short_form)
1951
print_header(file, print_event_info, false);
1952
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
1953
get_type_str(), (ulong) thread_id, (ulong) exec_time,
1957
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
1959
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
1960
memcpy(print_event_info->db, db, db_len + 1);
1961
if (db[0] && different_db)
1962
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
1965
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
1966
end= strmov(end, print_event_info->delimiter);
1968
my_b_write(file, (uchar*) buff, (uint) (end-buff));
1969
if ((!print_event_info->thread_id_printed ||
1970
((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
1971
thread_id != print_event_info->thread_id)))
1973
// If --short-form, print deterministic value instead of pseudo_thread_id.
1974
my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
1975
short_form ? 999999999 : (ulong)thread_id,
1976
print_event_info->delimiter);
1977
print_event_info->thread_id= thread_id;
1978
print_event_info->thread_id_printed= 1;
1982
If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
1983
print (remember we don't produce mixed relay logs so there cannot be
1984
5.0 events before that one so there is nothing to reset).
1986
if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
1988
/* tmp is a bitmask of bits which have changed. */
1989
if (likely(print_event_info->flags2_inited))
1990
/* All bits which have changed */
1991
tmp= (print_event_info->flags2) ^ flags2;
1992
else /* that's the first Query event we read */
1994
print_event_info->flags2_inited= 1;
1995
tmp= ~((uint32_t)0); /* all bits have changed */
1998
if (unlikely(tmp)) /* some bits have changed */
2001
my_b_printf(file, "SET ");
2002
print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
2003
"@@session.foreign_key_checks", &need_comma);
2004
print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
2005
"@@session.sql_auto_is_null", &need_comma);
2006
print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
2007
"@@session.unique_checks", &need_comma);
2008
my_b_printf(file,"%s\n", print_event_info->delimiter);
2009
print_event_info->flags2= flags2;
2014
Now the session variables;
2015
it's more efficient to pass SQL_MODE as a number instead of a
2016
comma-separated list.
2017
FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
2018
variables (they have no global version; they're not listed in
2019
sql_class.h), The tests below work for pure binlogs or pure relay
2020
logs. Won't work for mixed relay logs but we don't create mixed
2021
relay logs (that is, there is no relay log with a format change
2022
except within the 3 first events, which mysqlbinlog handles
2023
gracefully). So this code should always be good.
2026
if (print_event_info->auto_increment_increment != auto_increment_increment ||
2027
print_event_info->auto_increment_offset != auto_increment_offset)
2029
my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
2030
auto_increment_increment,auto_increment_offset,
2031
print_event_info->delimiter);
2032
print_event_info->auto_increment_increment= auto_increment_increment;
2033
print_event_info->auto_increment_offset= auto_increment_offset;
2036
/* TODO: print the catalog when we feature SET CATALOG */
2038
if (likely(charset_inited) &&
2039
(unlikely(!print_event_info->charset_inited ||
2040
memcmp(print_event_info->charset, charset, 6))))
2042
const CHARSET_INFO * const cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2045
/* for mysql client */
2046
my_b_printf(file, "/*!\\C %s */%s\n",
2047
cs_info->csname, print_event_info->delimiter);
2049
my_b_printf(file,"SET "
2050
"@@session.character_set_client=%d,"
2051
"@@session.collation_connection=%d,"
2052
"@@session.collation_server=%d"
2055
uint2korr(charset+2),
2056
uint2korr(charset+4),
2057
print_event_info->delimiter);
2058
memcpy(print_event_info->charset, charset, 6);
2059
print_event_info->charset_inited= 1;
2063
if (memcmp(print_event_info->time_zone_str, time_zone_str, time_zone_len+1))
2065
my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2066
time_zone_str, print_event_info->delimiter);
2067
memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
2070
if (lc_time_names_number != print_event_info->lc_time_names_number)
2072
my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
2073
lc_time_names_number, print_event_info->delimiter);
2074
print_event_info->lc_time_names_number= lc_time_names_number;
2076
if (charset_database_number != print_event_info->charset_database_number)
2078
if (charset_database_number)
2079
my_b_printf(file, "SET @@session.collation_database=%d%s\n",
2080
charset_database_number, print_event_info->delimiter);
2082
my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
2083
print_event_info->delimiter);
2084
print_event_info->charset_database_number= charset_database_number;
2089
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2091
Write_on_release_cache cache(&print_event_info->head_cache, file);
2093
print_query_header(&cache, print_event_info);
2094
my_b_write(&cache, (uchar*) query, q_len);
2095
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
2097
#endif /* MYSQL_CLIENT */
1665
2101
Query_log_event::do_apply_event()
2104
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1667
2106
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1669
2108
return do_apply_event(rli, query, q_len);
1835
2274
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);
2277
rli->report(ERROR_LEVEL, expected_error,
2279
Query partially completed on the master (error on master: %d) \
2280
and was aborted. There is a chance that your master is inconsistent at this \
2281
point. If you are sure that your master is ok, run this query manually on the \
2282
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
2283
START SLAVE; . Query: '%s'", expected_error, thd->query);
1847
2284
thd->is_slave_error= 1;
2289
/* If the query was not ignored, it is printed to the general log */
2290
if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
2291
general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
1852
2293
compare_errors:
1988
2430
return(Log_event::do_shall_skip(rli));
1992
2436
/**************************************************************************
1993
2437
Start_log_event_v3 methods
1994
2438
**************************************************************************/
2440
#ifndef MYSQL_CLIENT
1996
2441
Start_log_event_v3::Start_log_event_v3()
1997
2442
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
1998
2443
artificial_event(0), dont_set_created(0)
2000
2445
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2004
2450
Start_log_event_v3::pack_info()
2453
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2007
2454
void Start_log_event_v3::pack_info(Protocol *protocol)
2009
2456
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: ");
2457
pos= strmov(buf, "Server ver: ");
2458
pos= strmov(pos, server_version);
2459
pos= strmov(pos, ", Binlog ver: ");
2013
2460
pos= int10_to_str(binlog_version, pos, 10);
2014
2461
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2467
Start_log_event_v3::print()
2471
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2473
Write_on_release_cache cache(&print_event_info->head_cache, file,
2474
Write_on_release_cache::FLUSH_F);
2476
if (!print_event_info->short_form)
2478
print_header(&cache, print_event_info, false);
2479
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2480
binlog_version, server_version);
2481
print_timestamp(&cache);
2483
my_b_printf(&cache," at startup");
2484
my_b_printf(&cache, "\n");
2485
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
2486
my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
2487
"Most probably mysqld crashed writing it.\n");
2489
if (!artificial_event && created)
2491
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
2493
This is for mysqlbinlog: like in replication, we want to delete the stale
2494
tmp files left by an unclean shutdown of mysqld (temporary tables)
2495
and rollback unfinished transaction.
2496
Probably this can be done with RESET CONNECTION (syntax to be defined).
2498
my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
2500
my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
2504
print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
2505
!print_event_info->short_form)
2507
my_b_printf(&cache, "BINLOG '\n");
2508
print_base64(&cache, print_event_info, false);
2509
print_event_info->printed_fd_event= true;
2513
#endif /* MYSQL_CLIENT */
2019
2516
Start_log_event_v3::Start_log_event_v3()
2542
3049
if (need_db && db && db_len)
2544
pos= my_stpcpy(pos, "use `");
3051
pos= strmov(pos, "use `");
2545
3052
memcpy(pos, db, db_len);
2546
pos= my_stpcpy(pos+db_len, "`; ");
3053
pos= strmov(pos+db_len, "`; ");
2549
pos= my_stpcpy(pos, "LOAD DATA ");
3056
pos= strmov(pos, "LOAD DATA ");
2552
3059
*fn_start= pos;
2554
3061
if (check_fname_outside_temp_buf())
2555
pos= my_stpcpy(pos, "LOCAL ");
2556
pos= my_stpcpy(pos, "INFILE '");
3062
pos= strmov(pos, "LOCAL ");
3063
pos= strmov(pos, "INFILE '");
2557
3064
memcpy(pos, fname, fname_len);
2558
pos= my_stpcpy(pos+fname_len, "' ");
3065
pos= strmov(pos+fname_len, "' ");
2560
3067
if (sql_ex.opt_flags & REPLACE_FLAG)
2561
pos= my_stpcpy(pos, " REPLACE ");
3068
pos= strmov(pos, " REPLACE ");
2562
3069
else if (sql_ex.opt_flags & IGNORE_FLAG)
2563
pos= my_stpcpy(pos, " IGNORE ");
3070
pos= strmov(pos, " IGNORE ");
2565
pos= my_stpcpy(pos ,"INTO");
3072
pos= strmov(pos ,"INTO");
2570
pos= my_stpcpy(pos ," Table `");
3077
pos= strmov(pos ," TABLE `");
2571
3078
memcpy(pos, table_name, table_name_len);
2572
3079
pos+= table_name_len;
2574
3081
/* We have to create all optinal fields as the default is not empty */
2575
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3082
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2576
3083
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2577
3084
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2578
pos= my_stpcpy(pos, " OPTIONALLY ");
2579
pos= my_stpcpy(pos, " ENCLOSED BY ");
3085
pos= strmov(pos, " OPTIONALLY ");
3086
pos= strmov(pos, " ENCLOSED BY ");
2580
3087
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2582
pos= my_stpcpy(pos, " ESCAPED BY ");
3089
pos= strmov(pos, " ESCAPED BY ");
2583
3090
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2585
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3092
pos= strmov(pos, " LINES TERMINATED BY ");
2586
3093
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2587
3094
if (sql_ex.line_start_len)
2589
pos= my_stpcpy(pos, " STARTING BY ");
3096
pos= strmov(pos, " STARTING BY ");
2590
3097
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2593
3100
if ((long) skip_lines > 0)
2595
pos= my_stpcpy(pos, " IGNORE ");
3102
pos= strmov(pos, " IGNORE ");
2596
3103
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2597
pos= my_stpcpy(pos," LINES ");
3104
pos= strmov(pos," LINES ");
2600
3107
if (num_fields)
2603
3110
const char *field= fields;
2604
pos= my_stpcpy(pos, " (");
3111
pos= strmov(pos, " (");
2605
3112
for (i = 0; i < num_fields; i++)
3346
Load_log_event::print()
3350
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
3352
print(file, print_event_info, 0);
3356
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
3359
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3361
if (!print_event_info->short_form)
3363
print_header(&cache, print_event_info, false);
3364
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3365
thread_id, exec_time);
3368
bool different_db= 1;
3372
If the database is different from the one of the previous statement, we
3373
need to print the "use" command, and we update the last_db.
3374
But if commented, the "use" is going to be commented so we should not
3377
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
3379
memcpy(print_event_info->db, db, db_len + 1);
3382
if (db && db[0] && different_db)
3383
my_b_printf(&cache, "%suse %s%s\n",
3384
commented ? "# " : "",
3385
db, print_event_info->delimiter);
3387
if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
3388
my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
3389
commented ? "# " : "", (ulong)thread_id,
3390
print_event_info->delimiter);
3391
my_b_printf(&cache, "%sLOAD DATA ",
3392
commented ? "# " : "");
3393
if (check_fname_outside_temp_buf())
3394
my_b_printf(&cache, "LOCAL ");
3395
my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
3397
if (sql_ex.opt_flags & REPLACE_FLAG)
3398
my_b_printf(&cache," REPLACE ");
3399
else if (sql_ex.opt_flags & IGNORE_FLAG)
3400
my_b_printf(&cache," IGNORE ");
3402
my_b_printf(&cache, "INTO TABLE `%s`", table_name);
3403
my_b_printf(&cache, " FIELDS TERMINATED BY ");
3404
pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
3406
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3407
my_b_printf(&cache," OPTIONALLY ");
3408
my_b_printf(&cache, " ENCLOSED BY ");
3409
pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
3411
my_b_printf(&cache, " ESCAPED BY ");
3412
pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
3414
my_b_printf(&cache," LINES TERMINATED BY ");
3415
pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
3418
if (sql_ex.line_start)
3420
my_b_printf(&cache," STARTING BY ");
3421
pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
3423
if ((long) skip_lines > 0)
3424
my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
3429
const char* field = fields;
3430
my_b_printf(&cache, " (");
3431
for (i = 0; i < num_fields; i++)
3434
my_b_printf(&cache, ",");
3435
my_b_printf(&cache, field);
3437
field += field_lens[i] + 1;
3439
my_b_printf(&cache, ")");
3442
my_b_printf(&cache, "%s\n", print_event_info->delimiter);
3445
#endif /* MYSQL_CLIENT */
3447
#ifndef MYSQL_CLIENT
2835
3450
Load_log_event::set_fields()
3351
4003
Intvar_log_event::write()
4006
#ifndef MYSQL_CLIENT
3354
4007
bool Intvar_log_event::write(IO_CACHE* file)
3356
unsigned char buf[9];
3357
buf[I_TYPE_OFFSET]= (unsigned char) type;
4010
buf[I_TYPE_OFFSET]= (uchar) type;
3358
4011
int8store(buf + I_VAL_OFFSET, val);
3359
4012
return (write_header(file, sizeof(buf)) ||
3360
4013
my_b_safe_write(file, buf, sizeof(buf)));
3365
4019
Intvar_log_event::print()
4023
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4027
Write_on_release_cache cache(&print_event_info->head_cache, file,
4028
Write_on_release_cache::FLUSH_F);
4030
if (!print_event_info->short_form)
4032
print_header(&cache, print_event_info, false);
4033
my_b_printf(&cache, "\tIntvar\n");
4036
my_b_printf(&cache, "SET ");
4038
case LAST_INSERT_ID_EVENT:
4039
msg="LAST_INSERT_ID";
4041
case INSERT_ID_EVENT:
4044
case INVALID_INT_EVENT:
4045
default: // cannot happen
4049
my_b_printf(&cache, "%s=%s%s\n",
4050
msg, llstr(val,llbuff), print_event_info->delimiter);
3369
4056
Intvar_log_event::do_apply_event()
4059
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3372
4060
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
4131
#ifndef MYSQL_CLIENT
3439
4132
bool Rand_log_event::write(IO_CACHE* file)
3441
unsigned char buf[16];
3442
4135
int8store(buf + RAND_SEED1_OFFSET, seed1);
3443
4136
int8store(buf + RAND_SEED2_OFFSET, seed2);
3444
4137
return (write_header(file, sizeof(buf)) ||
3445
4138
my_b_safe_write(file, buf, sizeof(buf)));
4144
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4146
Write_on_release_cache cache(&print_event_info->head_cache, file,
4147
Write_on_release_cache::FLUSH_F);
4149
char llbuff[22],llbuff2[22];
4150
if (!print_event_info->short_form)
4152
print_header(&cache, print_event_info, false);
4153
my_b_printf(&cache, "\tRand\n");
4155
my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
4156
llstr(seed1, llbuff),llstr(seed2, llbuff2),
4157
print_event_info->delimiter);
4159
#endif /* MYSQL_CLIENT */
4162
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3449
4163
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
4234
#ifndef MYSQL_CLIENT
3516
4235
bool Xid_log_event::write(IO_CACHE* file)
3518
4237
return write_header(file, sizeof(xid)) ||
3519
my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
4238
my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
4244
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4246
Write_on_release_cache cache(&print_event_info->head_cache, file,
4247
Write_on_release_cache::FLUSH_F);
4249
if (!print_event_info->short_form)
4252
int64_t10_to_str(xid, buf, 10);
4254
print_header(&cache, print_event_info, false);
4255
my_b_printf(&cache, "\tXid = %s\n", buf);
4257
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4259
#endif /* MYSQL_CLIENT */
4262
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3523
4263
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4265
/* For a slave Xid_log_event is COMMIT */
4266
general_log_print(thd, COM_QUERY,
4267
"COMMIT /* implicit, from Xid_log_event */");
3525
4268
return end_trans(thd, COMMIT);
3702
4449
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3704
4451
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) ||
4452
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
4453
my_b_safe_write(file, (uchar*) name, name_len) ||
4454
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3708
4455
my_b_safe_write(file, pos, val_len));
4461
User_var_log_event::print()
4465
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4467
Write_on_release_cache cache(&print_event_info->head_cache, file,
4468
Write_on_release_cache::FLUSH_F);
4470
if (!print_event_info->short_form)
4472
print_header(&cache, print_event_info, false);
4473
my_b_printf(&cache, "\tUser_var\n");
4476
my_b_printf(&cache, "SET @`");
4477
my_b_write(&cache, (uchar*) name, (uint) (name_len));
4478
my_b_printf(&cache, "`");
4482
my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
4489
char real_buf[FMT_G_BUFSIZE(14)];
4490
float8get(real_val, val);
4491
sprintf(real_buf, "%.14g", real_val);
4492
my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
4496
int64_t10_to_str(uint8korr(val), int_buf, -10);
4497
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
4499
case DECIMAL_RESULT:
4502
int str_len= sizeof(str_buf) - 1;
4503
int precision= (int)val[0];
4504
int scale= (int)val[1];
4505
decimal_digit_t dec_buf[10];
4510
bin2decimal((uchar*) val+2, &dec, precision, scale);
4511
decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
4512
str_buf[str_len]= 0;
4513
my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
4519
Let's express the string in hex. That's the most robust way. If we
4520
print it in character form instead, we need to escape it with
4521
character_set_client which we don't know (we will know it in 5.0, but
4522
in 4.1 we don't know it easily when we are printing
4523
User_var_log_event). Explanation why we would need to bother with
4524
character_set_client (quoting Bar):
4525
> Note, the parser doesn't switch to another unescaping mode after
4526
> it has met a character set introducer.
4527
> For example, if an SJIS client says something like:
4528
> SET @a= _ucs2 \0a\0b'
4529
> the string constant is still unescaped according to SJIS, not
4530
> according to UCS2.
4533
const CHARSET_INFO *cs;
4535
if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4536
break; // no error, as we are 'void'
4537
str_to_hex(hex_str, val, val_len);
4539
For proper behaviour when mysqlbinlog|mysql, we need to explicitely
4540
specify the variable's collation. It will however cause problems when
4541
people want to mysqlbinlog|mysql into another server not supporting the
4542
character set. But there's not much to do about this and it's unlikely.
4544
if (!(cs= get_charset(charset_number, MYF(0))))
4546
Generate an unusable command (=> syntax error) is probably the best
4547
thing we can do here.
4549
my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
4551
my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
4552
cs->csname, hex_str, cs->name,
4553
print_event_info->delimiter);
3714
4568
User_var_log_event::do_apply_event()
4571
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3717
4572
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3805
4660
return continue_group(rli);
4662
#endif /* !MYSQL_CLIENT */
3809
4665
/**************************************************************************
3810
4666
Slave_log_event methods
3811
4667
**************************************************************************/
4669
#ifdef HAVE_REPLICATION
4671
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
4673
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
4675
if (print_event_info->short_form)
4677
print_header(&cache, print_event_info, false);
4678
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4682
#ifndef MYSQL_CLIENT
3813
4683
void Slave_log_event::pack_info(Protocol *protocol)
3815
4685
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=");
4686
pos= strmov(buf, "host=");
4687
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4688
pos= strmov(pos, ",port=");
3819
4689
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=");
4690
pos= strmov(pos, ",log=");
4691
pos= strmov(pos, master_log);
4692
pos= strmov(pos, ",pos=");
3823
4693
pos= int64_t10_to_str(master_pos, pos, 10);
3824
4694
protocol->store(buf, pos-buf, &my_charset_bin);
4696
#endif /* !MYSQL_CLIENT */
4699
#ifndef MYSQL_CLIENT
3830
4702
re-write this better without holding both locks at the same time
5003
Create_file_log_event::print()
5007
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
5010
Write_on_release_cache cache(&print_event_info->head_cache, file);
5012
if (print_event_info->short_form)
5014
if (enable_local && check_fname_outside_temp_buf())
5015
Load_log_event::print(file, print_event_info);
5021
Load_log_event::print(file, print_event_info,
5022
!check_fname_outside_temp_buf());
5024
That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
5025
SHOW BINLOG EVENTS we don't.
5027
my_b_printf(&cache, "#");
5030
my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len);
5034
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
5036
print(file, print_event_info, 0);
5038
#endif /* MYSQL_CLIENT */
4084
5042
Create_file_log_event::pack_info()
5045
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4087
5046
void Create_file_log_event::pack_info(Protocol *protocol)
4089
5048
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4090
pos= my_stpcpy(buf, "db=");
5049
pos= strmov(buf, "db=");
4091
5050
memcpy(pos, db, db_len);
4092
pos= my_stpcpy(pos + db_len, ";table=");
5051
pos= strmov(pos + db_len, ";table=");
4093
5052
memcpy(pos, table_name, table_name_len);
4094
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5053
pos= strmov(pos + table_name_len, ";file_id=");
4095
5054
pos= int10_to_str((long) file_id, pos, 10);
4096
pos= my_stpcpy(pos, ";block_len=");
5055
pos= strmov(pos, ";block_len=");
4097
5056
pos= int10_to_str((long) block_len, pos, 10);
4098
5057
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5059
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4103
5063
Create_file_log_event::do_apply_event()
5066
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4106
5067
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4108
5069
char proc_info[17+FN_REFLEN+10], *fname_buf;
4123
5084
MYF(MY_WME|MY_NABP)))
4125
5086
rli->report(ERROR_LEVEL, my_errno,
4126
_("Error in Create_file event: could not open file '%s'"),
5087
"Error in Create_file event: could not open file '%s'",
4131
5092
// a trick to avoid allocating another buffer
4132
5093
fname= fname_buf;
4133
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5094
fname_len= (uint) (strmov(ext, ".data") - fname);
4134
5095
if (write_base(&file))
4136
my_stpcpy(ext, ".info"); // to have it right in the error message
5097
strmov(ext, ".info"); // to have it right in the error message
4137
5098
rli->report(ERROR_LEVEL, my_errno,
4138
_("Error in Create_file event: could not write to file '%s'"),
5099
"Error in Create_file event: could not write to file '%s'",
4142
5103
end_io_cache(&file);
4143
5104
my_close(fd, MYF(0));
4145
5106
// fname_buf now already has .data, not .info, because we did our trick
4146
5107
my_delete(fname_buf, MYF(0)); // old copy may exist already
4147
5108
if ((fd= my_create(fname_buf, CREATE_MODE,
4148
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
5109
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4151
5112
rli->report(ERROR_LEVEL, my_errno,
4152
_("Error in Create_file event: could not open file '%s'"),
5113
"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)))
5117
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4158
5119
rli->report(ERROR_LEVEL, my_errno,
4159
_("Error in Create_file event: write to '%s' failed"),
5120
"Error in Create_file event: write to '%s' failed",
4180
5142
Append_block_log_event ctor
5145
#ifndef MYSQL_CLIENT
4183
5146
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4184
5147
const char *db_arg,
4185
unsigned char *block_arg,
4186
uint32_t block_len_arg,
4187
5150
bool using_trans)
4188
5151
:Log_event(thd_arg,0, using_trans), block(block_arg),
4189
5152
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4195
5159
Append_block_log_event ctor
4198
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5162
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4199
5163
const Format_description_log_event* description_event)
4200
5164
:Log_event(buf, description_event),block(0)
4202
5166
uint8_t common_header_len= description_event->common_header_len;
4203
5167
uint8_t append_block_header_len=
4204
5168
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4205
uint32_t total_header_len= common_header_len+append_block_header_len;
5169
uint total_header_len= common_header_len+append_block_header_len;
4206
5170
if (len < total_header_len)
4208
5172
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4209
block= (unsigned char*)buf + total_header_len;
5173
block= (uchar*)buf + total_header_len;
4210
5174
block_len= len - total_header_len;
4216
5180
Append_block_log_event::write()
5183
#ifndef MYSQL_CLIENT
4219
5184
bool Append_block_log_event::write(IO_CACHE* file)
4221
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5186
uchar buf[APPEND_BLOCK_HEADER_LEN];
4222
5187
int4store(buf + AB_FILE_ID_OFFSET, file_id);
4223
5188
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4224
5189
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4225
my_b_safe_write(file, (unsigned char*) block, block_len));
5190
my_b_safe_write(file, (uchar*) block, block_len));
5196
Append_block_log_event::print()
5200
void Append_block_log_event::print(FILE* file,
5201
PRINT_EVENT_INFO* print_event_info)
5203
Write_on_release_cache cache(&print_event_info->head_cache, file);
5205
if (print_event_info->short_form)
5207
print_header(&cache, print_event_info, false);
5208
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5209
get_type_str(), file_id, block_len);
5211
#endif /* MYSQL_CLIENT */
4230
5215
Append_block_log_event::pack_info()
5218
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4233
5219
void Append_block_log_event::pack_info(Protocol *protocol)
4237
5223
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
4239
5225
protocol->store(buf, length, &my_charset_bin);
4334
5323
Delete_file_log_event::write()
5326
#ifndef MYSQL_CLIENT
4337
5327
bool Delete_file_log_event::write(IO_CACHE* file)
4339
unsigned char buf[DELETE_FILE_HEADER_LEN];
5329
uchar buf[DELETE_FILE_HEADER_LEN];
4340
5330
int4store(buf + DF_FILE_ID_OFFSET, file_id);
4341
5331
return (write_header(file, sizeof(buf)) ||
4342
5332
my_b_safe_write(file, buf, sizeof(buf)));
5338
Delete_file_log_event::print()
5342
void Delete_file_log_event::print(FILE* file,
5343
PRINT_EVENT_INFO* print_event_info)
5345
Write_on_release_cache cache(&print_event_info->head_cache, file);
5347
if (print_event_info->short_form)
5349
print_header(&cache, print_event_info, false);
5350
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5352
#endif /* MYSQL_CLIENT */
4347
5355
Delete_file_log_event::pack_info()
5358
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4350
5359
void Delete_file_log_event::pack_info(Protocol *protocol)
4354
5363
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4355
5364
protocol->store(buf, (int32_t) length, &my_charset_bin);
4359
5369
Delete_file_log_event::do_apply_event()
5372
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4362
5373
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4364
5375
char fname[FN_REFLEN+10];
4365
5376
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4366
5377
(void) my_delete(fname, MYF(MY_WME));
4367
my_stpcpy(ext, ".info");
5378
strmov(ext, ".info");
4368
5379
(void) my_delete(fname, MYF(MY_WME));
5382
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4373
5385
/**************************************************************************
4406
5420
Execute_load_log_event::write()
5423
#ifndef MYSQL_CLIENT
4409
5424
bool Execute_load_log_event::write(IO_CACHE* file)
4411
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5426
uchar buf[EXEC_LOAD_HEADER_LEN];
4412
5427
int4store(buf + EL_FILE_ID_OFFSET, file_id);
4413
5428
return (write_header(file, sizeof(buf)) ||
4414
5429
my_b_safe_write(file, buf, sizeof(buf)));
5435
Execute_load_log_event::print()
5439
void Execute_load_log_event::print(FILE* file,
5440
PRINT_EVENT_INFO* print_event_info)
5442
Write_on_release_cache cache(&print_event_info->head_cache, file);
5444
if (print_event_info->short_form)
5446
print_header(&cache, print_event_info, false);
5447
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
4419
5453
Execute_load_log_event::pack_info()
5456
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4422
5457
void Execute_load_log_event::pack_info(Protocol *protocol)
4426
5461
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4427
5462
protocol->store(buf, (int32_t) length, &my_charset_bin);
5554
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4523
5557
/**************************************************************************
4524
5558
Begin_load_query_log_event methods
4525
5559
**************************************************************************/
5561
#ifndef MYSQL_CLIENT
4527
5562
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)
5563
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5564
uint block_len_arg, bool using_trans)
4530
5565
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4533
5568
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4537
5573
Begin_load_query_log_event::
4538
Begin_load_query_log_event(const char* buf, uint32_t len,
5574
Begin_load_query_log_event(const char* buf, uint len,
4539
5575
const Format_description_log_event* desc_event)
4540
5576
:Append_block_log_event(buf, len, desc_event)
5581
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4545
5582
int Begin_load_query_log_event::get_create_or_append() const
4547
5584
return 1; /* create the file */
5586
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5589
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4551
5590
Log_event::enum_skip_reason
4552
5591
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5653
#ifndef MYSQL_CLIENT
4612
5655
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4614
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5657
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4615
5658
int4store(buf, file_id);
4616
5659
int4store(buf + 4, fn_pos_start);
4617
5660
int4store(buf + 4 + 4, fn_pos_end);
4618
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5661
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4619
5662
return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
5668
void Execute_load_query_log_event::print(FILE* file,
5669
PRINT_EVENT_INFO* print_event_info)
5671
print(file, print_event_info, 0);
5675
Prints the query as LOAD DATA LOCAL and with rewritten filename.
5677
void Execute_load_query_log_event::print(FILE* file,
5678
PRINT_EVENT_INFO* print_event_info,
5679
const char *local_fname)
5681
Write_on_release_cache cache(&print_event_info->head_cache, file);
5683
print_query_header(&cache, print_event_info);
5687
my_b_write(&cache, (uchar*) query, fn_pos_start);
5688
my_b_printf(&cache, " LOCAL INFILE \'");
5689
my_b_printf(&cache, local_fname);
5690
my_b_printf(&cache, "\'");
5691
if (dup_handling == LOAD_DUP_REPLACE)
5692
my_b_printf(&cache, " REPLACE");
5693
my_b_printf(&cache, " INTO");
5694
my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
5695
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5699
my_b_write(&cache, (uchar*) query, q_len);
5700
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5703
if (!print_event_info->short_form)
5704
my_b_printf(&cache, "# file_id: %d \n", file_id);
5709
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4623
5710
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4625
5712
char *buf, *pos;
5758
6890
const char *const vpart= buf + common_header_len + post_header_len;
5760
6892
/* 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;
6893
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
6894
m_dblen= *(uchar*) ptr_dblen;
5764
6896
/* 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;
6897
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
6898
m_tbllen= *(uchar*) ptr_tbllen;
5768
6900
/* 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;
6901
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
6902
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5771
6903
m_colcnt= net_field_length(&ptr_after_colcnt);
5773
6905
/* 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),
6906
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5775
6907
&m_dbnam, (uint) m_dblen + 1,
5776
6908
&m_tblnam, (uint) m_tbllen + 1,
5777
6909
&m_coltype, (uint) m_colcnt,
5785
6917
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5787
6919
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5788
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
6920
bytes_read= ptr_after_colcnt - (uchar *)buf;
5789
6921
if (bytes_read < event_len)
5791
6923
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5792
6924
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),
6925
uint num_null_bytes= (m_colcnt + 7) / 8;
6926
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5795
6927
&m_null_bits, num_null_bytes,
5796
6928
&m_field_metadata, m_field_metadata_size,
5798
6930
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5799
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
6931
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5800
6932
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5807
6940
Table_map_log_event::~Table_map_log_event()
5809
free(m_meta_memory);
6942
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
6943
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5991
7126
assert(m_dblen < 128);
5992
7127
assert(m_tbllen < 128);
5994
unsigned char const dbuf[]= { (unsigned char) m_dblen };
5995
unsigned char const tbuf[]= { (unsigned char) m_tbllen };
7129
uchar const dbuf[]= { (uchar) m_dblen };
7130
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);
7132
uchar cbuf[sizeof(m_colcnt)];
7133
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5999
7134
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
6002
7137
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);
7139
uchar mbuf[sizeof(m_field_metadata_size)];
7140
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
6007
7142
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
6008
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7143
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
6009
7144
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
6010
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7145
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
6011
7146
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
6012
7147
my_b_safe_write(file, m_coltype, m_colcnt) ||
6013
7148
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
6014
7149
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
6015
7150
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7154
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6020
7157
Print some useful information for the SHOW BINARY LOG information
7161
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6024
7162
void Table_map_log_event::pack_info(Protocol *protocol)
6993
8215
set_if_smaller(ident_len,FN_REFLEN-1);
6994
8216
log_ident= buf + header_size;
8223
The default values for these variables should be values that are
8224
*incorrect*, i.e., values that cannot occur in an event. This way,
8225
they will always be printed for the first event.
8227
st_print_event_info::st_print_event_info()
8228
:flags2_inited(0), sql_mode_inited(0),
8229
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
8230
lc_time_names_number(~0),
8231
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8232
thread_id(0), thread_id_printed(false),
8233
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
8236
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
8237
program's startup, but these explicit memset() is for the day someone
8238
creates dynamic instances.
8240
memset(db, 0, sizeof(db));
8241
memset(charset, 0, sizeof(charset));
8242
memset(time_zone_str, 0, sizeof(time_zone_str));
8245
myf const flags = MYF(MY_WME | MY_NABP);
8246
open_cached_file(&head_cache, NULL, NULL, 0, flags);
8247
open_cached_file(&body_cache, NULL, NULL, 0, flags);