3075
3053
/**************************************************************************
3076
Intvar_log_event methods
3077
**************************************************************************/
3080
Intvar_log_event::pack_info()
3083
void Intvar_log_event::pack_info(Protocol *protocol)
3085
char buf[256], *pos;
3086
pos= strmake(buf, get_var_type_name(), sizeof(buf)-23);
3088
pos= int64_t10_to_str(val, pos, -10);
3089
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
3094
Intvar_log_event::Intvar_log_event()
3097
Intvar_log_event::Intvar_log_event(const char* buf,
3098
const Format_description_log_event* description_event)
3099
:Log_event(buf, description_event)
3101
buf+= description_event->common_header_len;
3102
type= buf[I_TYPE_OFFSET];
3103
val= uint8korr(buf+I_VAL_OFFSET);
3108
Intvar_log_event::get_var_type_name()
3111
const char* Intvar_log_event::get_var_type_name()
3114
case LAST_INSERT_ID_EVENT: return "LAST_INSERT_ID";
3115
case INSERT_ID_EVENT: return "INSERT_ID";
3116
default: /* impossible */ return "UNKNOWN";
3122
Intvar_log_event::write()
3125
bool Intvar_log_event::write(IO_CACHE* file)
3127
unsigned char buf[9];
3128
buf[I_TYPE_OFFSET]= (unsigned char) type;
3129
int8store(buf + I_VAL_OFFSET, val);
3130
return (write_header(file, sizeof(buf)) ||
3131
my_b_safe_write(file, buf, sizeof(buf)));
3136
Intvar_log_event::print()
3140
Intvar_log_event::do_apply_event()
3143
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
3146
We are now in a statement until the associated query log event has
3149
const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
3152
case LAST_INSERT_ID_EVENT:
3153
session->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1;
3154
session->first_successful_insert_id_in_prev_stmt= val;
3156
case INSERT_ID_EVENT:
3157
session->force_one_auto_inc_interval(val);
3163
int Intvar_log_event::do_update_pos(Relay_log_info *rli)
3165
rli->inc_event_relay_log_pos();
3170
Log_event::enum_skip_reason
3171
Intvar_log_event::do_shall_skip(Relay_log_info *rli)
3174
It is a common error to set the slave skip counter to 1 instead of
3175
2 when recovering from an insert which used a auto increment,
3176
rand, or user var. Therefore, if the slave skip counter is 1, we
3177
just say that this event should be skipped by ignoring it, meaning
3178
that we do not change the value of the slave skip counter since it
3179
will be decreased by the following insert event.
3181
return continue_group(rli);
3185
/**************************************************************************
3186
Rand_log_event methods
3187
**************************************************************************/
3189
void Rand_log_event::pack_info(Protocol *protocol)
3191
char buf1[256], *pos;
3192
pos= my_stpcpy(buf1,"rand_seed1=");
3193
pos= int10_to_str((long) seed1, pos, 10);
3194
pos= my_stpcpy(pos, ",rand_seed2=");
3195
pos= int10_to_str((long) seed2, pos, 10);
3196
protocol->store(buf1, (uint) (pos-buf1), &my_charset_bin);
3200
Rand_log_event::Rand_log_event(const char* buf,
3201
const Format_description_log_event* description_event)
3202
:Log_event(buf, description_event)
3204
buf+= description_event->common_header_len;
3205
seed1= uint8korr(buf+RAND_SEED1_OFFSET);
3206
seed2= uint8korr(buf+RAND_SEED2_OFFSET);
3210
bool Rand_log_event::write(IO_CACHE* file)
3212
unsigned char buf[16];
3213
int8store(buf + RAND_SEED1_OFFSET, seed1);
3214
int8store(buf + RAND_SEED2_OFFSET, seed2);
3215
return (write_header(file, sizeof(buf)) ||
3216
my_b_safe_write(file, buf, sizeof(buf)));
3220
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
3223
We are now in a statement until the associated query log event has
3226
const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
3228
session->rand.seed1= (ulong) seed1;
3229
session->rand.seed2= (ulong) seed2;
3233
int Rand_log_event::do_update_pos(Relay_log_info *rli)
3235
rli->inc_event_relay_log_pos();
3240
Log_event::enum_skip_reason
3241
Rand_log_event::do_shall_skip(Relay_log_info *rli)
3244
It is a common error to set the slave skip counter to 1 instead of
3245
2 when recovering from an insert which used a auto increment,
3246
rand, or user var. Therefore, if the slave skip counter is 1, we
3247
just say that this event should be skipped by ignoring it, meaning
3248
that we do not change the value of the slave skip counter since it
3249
will be decreased by the following insert event.
3251
return continue_group(rli);
3255
/**************************************************************************
3256
3054
Xid_log_event methods
3257
3055
**************************************************************************/
3310
3108
/**************************************************************************
3311
User_var_log_event methods
3312
**************************************************************************/
3314
void User_var_log_event::pack_info(Protocol* protocol)
3317
uint32_t val_offset= 4 + name_len;
3318
uint32_t event_len= val_offset;
3322
if (!(buf= (char*) my_malloc(val_offset + 5, MYF(MY_WME))))
3324
my_stpcpy(buf + val_offset, "NULL");
3325
event_len= val_offset + 4;
3332
float8get(real_val, val);
3333
if (!(buf= (char*) my_malloc(val_offset + MY_GCVT_MAX_FIELD_WIDTH + 1,
3336
event_len+= my_gcvt(real_val, MY_GCVT_ARG_DOUBLE, MY_GCVT_MAX_FIELD_WIDTH,
3337
buf + val_offset, NULL);
3340
if (!(buf= (char*) my_malloc(val_offset + 22, MYF(MY_WME))))
3342
event_len= int64_t10_to_str(uint8korr(val), buf + val_offset,-10)-buf;
3344
case DECIMAL_RESULT:
3346
if (!(buf= (char*) my_malloc(val_offset + DECIMAL_MAX_STR_LENGTH,
3349
String str(buf+val_offset, DECIMAL_MAX_STR_LENGTH, &my_charset_bin);
3351
binary2my_decimal(E_DEC_FATAL_ERROR, (unsigned char*) (val+2), &dec, val[0],
3353
my_decimal2string(E_DEC_FATAL_ERROR, &dec, 0, 0, 0, &str);
3354
event_len= str.length() + val_offset;
3358
/* 15 is for 'COLLATE' and other chars */
3359
buf= (char*) my_malloc(event_len+val_len*2+1+2*MY_CS_NAME_SIZE+15,
3361
const CHARSET_INFO *cs;
3364
if (!(cs= get_charset(charset_number, MYF(0))))
3366
my_stpcpy(buf+val_offset, "???");
3371
char *p= strxmov(buf + val_offset, "_", cs->csname, " ", NULL);
3372
p= str_to_hex(p, val, val_len);
3373
p= strxmov(p, " COLLATE ", cs->name, NULL);
3385
memcpy(buf+2, name, name_len);
3386
buf[2+name_len]= '`';
3387
buf[3+name_len]= '=';
3388
protocol->store(buf, event_len, &my_charset_bin);
3393
User_var_log_event::
3394
User_var_log_event(const char* buf,
3395
const Format_description_log_event* description_event)
3396
:Log_event(buf, description_event)
3398
buf+= description_event->common_header_len;
3399
name_len= uint4korr(buf);
3400
name= (char *) buf + UV_NAME_LEN_SIZE;
3401
buf+= UV_NAME_LEN_SIZE + name_len;
3402
is_null= (bool) *buf;
3405
type= STRING_RESULT;
3406
charset_number= my_charset_bin.number;
3412
type= (Item_result) buf[UV_VAL_IS_NULL];
3413
charset_number= uint4korr(buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE);
3414
val_len= uint4korr(buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
3415
UV_CHARSET_NUMBER_SIZE);
3416
val= (char *) (buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
3417
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE);
3422
bool User_var_log_event::write(IO_CACHE* file)
3424
char buf[UV_NAME_LEN_SIZE];
3425
char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
3426
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
3427
unsigned char buf2[(8 > DECIMAL_MAX_FIELD_SIZE + 2) ? 8 : DECIMAL_MAX_FIELD_SIZE +2], *pos= buf2;
3428
uint32_t buf1_length;
3431
int4store(buf, name_len);
3433
if ((buf1[0]= is_null))
3436
val_len= 0; // Length of 'pos'
3441
int4store(buf1 + 2, charset_number);
3445
float8store(buf2, *(double*) val);
3448
int8store(buf2, *(int64_t*) val);
3450
case DECIMAL_RESULT:
3452
my_decimal *dec= (my_decimal *)val;
3453
dec->fix_buffer_pointer();
3454
buf2[0]= (char)(dec->intg + dec->frac);
3455
buf2[1]= (char)dec->frac;
3456
decimal2bin((decimal_t*)val, buf2+2, buf2[0], buf2[1]);
3457
val_len= decimal_bin_size(buf2[0], buf2[1]) + 2;
3461
pos= (unsigned char*) val;
3468
int4store(buf1 + 2 + UV_CHARSET_NUMBER_SIZE, val_len);
3472
/* Length of the whole event */
3473
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3475
return (write_header(file, event_length) ||
3476
my_b_safe_write(file, (unsigned char*) buf, sizeof(buf)) ||
3477
my_b_safe_write(file, (unsigned char*) name, name_len) ||
3478
my_b_safe_write(file, (unsigned char*) buf1, buf1_length) ||
3479
my_b_safe_write(file, pos, val_len));
3485
User_var_log_event::do_apply_event()
3488
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3491
const CHARSET_INFO *charset;
3492
if (!(charset= get_charset(charset_number, MYF(MY_WME))))
3494
LEX_STRING user_var_name;
3495
user_var_name.str= name;
3496
user_var_name.length= name_len;
3501
We are now in a statement until the associated query log event has
3504
const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
3508
it= new Item_null();
3514
float8get(real_val, val);
3515
it= new Item_float(real_val, 0);
3516
val= (char*) &real_val; // Pointer to value in native format
3520
int_val= (int64_t) uint8korr(val);
3521
it= new Item_int(int_val);
3522
val= (char*) &int_val; // Pointer to value in native format
3525
case DECIMAL_RESULT:
3527
Item_decimal *dec= new Item_decimal((unsigned char*) val+2, val[0], val[1]);
3529
val= (char *)dec->val_decimal(NULL);
3530
val_len= sizeof(my_decimal);
3534
it= new Item_string(val, val_len, charset);
3542
Item_func_set_user_var e(user_var_name, it);
3544
Item_func_set_user_var can't substitute something else on its place =>
3545
0 can be passed as last argument (reference on item)
3547
e.fix_fields(session, 0);
3549
A variable can just be considered as a table with
3550
a single record and with a single column. Thus, like
3551
a column value, it could always have IMPLICIT derivation.
3553
e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0);
3554
free_root(session->mem_root,0);
3559
int User_var_log_event::do_update_pos(Relay_log_info *rli)
3561
rli->inc_event_relay_log_pos();
3565
Log_event::enum_skip_reason
3566
User_var_log_event::do_shall_skip(Relay_log_info *rli)
3569
It is a common error to set the slave skip counter to 1 instead
3570
of 2 when recovering from an insert which used a auto increment,
3571
rand, or user var. Therefore, if the slave skip counter is 1, we
3572
just say that this event should be skipped by ignoring it, meaning
3573
that we do not change the value of the slave skip counter since it
3574
will be decreased by the following insert event.
3576
return continue_group(rli);
3580
/**************************************************************************
3581
3109
Slave_log_event methods
3582
3110
**************************************************************************/