~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log_event.cc

  • Committer: Monty Taylor
  • Date: 2008-08-02 01:03:15 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802010315-65h5938pymg9d99z
Moved m4 macros to top-level m4 dir, per GNU standards (and where gettext wanted it :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
 
#ifndef MYSQL_CLIENT
18
 
 
19
 
#include <drizzled/server_includes.h>
 
17
#ifdef MYSQL_CLIENT
 
18
 
 
19
#include "mysql_priv.h"
 
20
 
 
21
#else
 
22
 
 
23
#ifdef USE_PRAGMA_IMPLEMENTATION
 
24
#pragma implementation                          // gcc: Class implementation
 
25
#endif
 
26
 
 
27
#include "mysql_priv.h"
 
28
#include "slave.h"
20
29
#include "rpl_rli.h"
21
30
#include "rpl_mi.h"
22
31
#include "rpl_filter.h"
25
34
#include <mysys/my_dir.h>
26
35
#include <drizzled/drizzled_error_messages.h>
27
36
 
28
 
#endif /* !MYSQL_CLIENT */
 
37
#endif /* MYSQL_CLIENT */
29
38
 
30
39
#include <mysys/base64.h>
31
40
#include <mysys/my_bitmap.h>
124
133
  char buff[MAX_SLAVE_ERRMSG], *slider;
125
134
  const char *buff_end= buff + sizeof(buff);
126
135
  uint len;
127
 
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
128
 
  DRIZZLE_ERROR *err;
 
136
  List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
 
137
  MYSQL_ERROR *err;
129
138
  buff[0]= 0;
130
139
 
131
140
  for (err= it++, slider= buff; err && slider < buff_end - 1;
337
346
  buf = int10_to_str(event_server_id, buf, 10);
338
347
  *buf++ = '-';
339
348
  res= int10_to_str(file_id, buf, 10);
340
 
  stpcpy(res, ext);                             // Add extension last
 
349
  strmov(res, ext);                             // Add extension last
341
350
  return res;                                   // Pointer to extension
342
351
}
343
352
#endif
429
438
    to= octet2hex(to, from, len);
430
439
  }
431
440
  else
432
 
    to= stpcpy(to, "\"\"");
 
441
    to= strmov(to, "\"\"");
433
442
  return to;                               // pointer to end 0 of 'to'
434
443
}
435
444
 
442
451
*/
443
452
 
444
453
int
445
 
append_query_string(const CHARSET_INFO * const csinfo,
 
454
append_query_string(CHARSET_INFO *csinfo,
446
455
                    String const *from, String *to)
447
456
{
448
457
  char *beg, *ptr;
1362
1371
  if (!(flags & LOG_EVENT_SUPPRESS_USE_F)
1363
1372
      && db && db_len)
1364
1373
  {
1365
 
    pos= stpcpy(buf, "use `");
 
1374
    pos= strmov(buf, "use `");
1366
1375
    memcpy(pos, db, db_len);
1367
 
    pos= stpcpy(pos+db_len, "`; ");
 
1376
    pos= strmov(pos+db_len, "`; ");
1368
1377
  }
1369
1378
  if (query && q_len)
1370
1379
  {
1922
1931
  */
1923
1932
 
1924
1933
  /* A 2nd variable part; this is common to all versions */ 
1925
 
  memcpy(start, end, data_len);          // Copy db and query
 
1934
  memcpy((char*) start, end, data_len);          // Copy db and query
1926
1935
  start[data_len]= '\0';              // End query with \0 (For safetly)
1927
1936
  db= (char *)start;
1928
1937
  query= (char *)(start + db_len + 1);
1962
1971
      my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
1963
1972
  }
1964
1973
 
1965
 
  end=int10_to_str((long) when, stpcpy(buff,"SET TIMESTAMP="),10);
1966
 
  end= stpcpy(end, print_event_info->delimiter);
 
1974
  end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
 
1975
  end= strmov(end, print_event_info->delimiter);
1967
1976
  *end++='\n';
1968
1977
  my_b_write(file, (uchar*) buff, (uint) (end-buff));
1969
1978
  if ((!print_event_info->thread_id_printed ||
2037
2046
 
2038
2047
  if (likely(charset_inited) &&
2039
2048
      (unlikely(!print_event_info->charset_inited ||
2040
 
                memcmp(print_event_info->charset, charset, 6))))
 
2049
                memcmp((uchar*) print_event_info->charset, (uchar*) charset, 6))))
2041
2050
  {
2042
 
    const CHARSET_INFO * const cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
 
2051
    CHARSET_INFO *cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2043
2052
    if (cs_info)
2044
2053
    {
2045
2054
      /* for mysql client */
2060
2069
  }
2061
2070
  if (time_zone_len)
2062
2071
  {
2063
 
    if (memcmp(print_event_info->time_zone_str, time_zone_str, time_zone_len+1))
 
2072
    if (memcmp((uchar*) print_event_info->time_zone_str,
 
2073
               (uchar*) time_zone_str, time_zone_len+1))
2064
2074
    {
2065
2075
      my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2066
2076
                  time_zone_str, print_event_info->delimiter);
2243
2253
        thd->variables.lc_time_names= &my_locale_en_US;
2244
2254
      if (charset_database_number)
2245
2255
      {
2246
 
        const CHARSET_INFO *cs;
 
2256
        CHARSET_INFO *cs;
2247
2257
        if (!(cs= get_charset(charset_database_number, MYF(0))))
2248
2258
        {
2249
2259
          char buf[20];
2454
2464
void Start_log_event_v3::pack_info(Protocol *protocol)
2455
2465
{
2456
2466
  char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
2457
 
  pos= stpcpy(buf, "Server ver: ");
2458
 
  pos= stpcpy(pos, server_version);
2459
 
  pos= stpcpy(pos, ", Binlog ver: ");
 
2467
  pos= strmov(buf, "Server ver: ");
 
2468
  pos= strmov(pos, server_version);
 
2469
  pos= strmov(pos, ", Binlog ver: ");
2460
2470
  pos= int10_to_str(binlog_version, pos, 10);
2461
2471
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2462
2472
}
2688
2698
      describes what those old master versions send.
2689
2699
    */
2690
2700
    if (binlog_ver==1)
2691
 
      stpcpy(server_version, server_ver ? server_ver : "3.23");
 
2701
      strmov(server_version, server_ver ? server_ver : "3.23");
2692
2702
    else
2693
 
      stpcpy(server_version, server_ver ? server_ver : "4.0");
 
2703
      strmov(server_version, server_ver ? server_ver : "4.0");
2694
2704
    common_header_len= binlog_ver==1 ? OLD_HEADER_LEN :
2695
2705
      LOG_EVENT_MINIMAL_HEADER_LEN;
2696
2706
    /*
2879
2889
  */
2880
2890
  uchar buff[FORMAT_DESCRIPTION_HEADER_LEN];
2881
2891
  int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version);
2882
 
  memcpy(buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
 
2892
  memcpy((char*) buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
2883
2893
  if (!dont_set_created)
2884
2894
    created= when= get_time();
2885
2895
  int4store(buff + ST_CREATED_OFFSET,created);
2886
2896
  buff[ST_COMMON_HEADER_LEN_OFFSET]= LOG_EVENT_HEADER_LEN;
2887
 
  memcpy(buff+ST_COMMON_HEADER_LEN_OFFSET+1, post_header_len,
 
2897
  memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET+1, (uchar*) post_header_len,
2888
2898
         LOG_EVENT_TYPES);
2889
2899
  return (write_header(file, sizeof(buff)) ||
2890
2900
          my_b_safe_write(file, buff, sizeof(buff)));
3048
3058
 
3049
3059
  if (need_db && db && db_len)
3050
3060
  {
3051
 
    pos= stpcpy(pos, "use `");
 
3061
    pos= strmov(pos, "use `");
3052
3062
    memcpy(pos, db, db_len);
3053
 
    pos= stpcpy(pos+db_len, "`; ");
 
3063
    pos= strmov(pos+db_len, "`; ");
3054
3064
  }
3055
3065
 
3056
 
  pos= stpcpy(pos, "LOAD DATA ");
 
3066
  pos= strmov(pos, "LOAD DATA ");
3057
3067
 
3058
3068
  if (fn_start)
3059
3069
    *fn_start= pos;
3060
3070
 
3061
3071
  if (check_fname_outside_temp_buf())
3062
 
    pos= stpcpy(pos, "LOCAL ");
3063
 
  pos= stpcpy(pos, "INFILE '");
 
3072
    pos= strmov(pos, "LOCAL ");
 
3073
  pos= strmov(pos, "INFILE '");
3064
3074
  memcpy(pos, fname, fname_len);
3065
 
  pos= stpcpy(pos+fname_len, "' ");
 
3075
  pos= strmov(pos+fname_len, "' ");
3066
3076
 
3067
3077
  if (sql_ex.opt_flags & REPLACE_FLAG)
3068
 
    pos= stpcpy(pos, " REPLACE ");
 
3078
    pos= strmov(pos, " REPLACE ");
3069
3079
  else if (sql_ex.opt_flags & IGNORE_FLAG)
3070
 
    pos= stpcpy(pos, " IGNORE ");
 
3080
    pos= strmov(pos, " IGNORE ");
3071
3081
 
3072
 
  pos= stpcpy(pos ,"INTO");
 
3082
  pos= strmov(pos ,"INTO");
3073
3083
 
3074
3084
  if (fn_end)
3075
3085
    *fn_end= pos;
3076
3086
 
3077
 
  pos= stpcpy(pos ," TABLE `");
 
3087
  pos= strmov(pos ," TABLE `");
3078
3088
  memcpy(pos, table_name, table_name_len);
3079
3089
  pos+= table_name_len;
3080
3090
 
3081
3091
  /* We have to create all optinal fields as the default is not empty */
3082
 
  pos= stpcpy(pos, "` FIELDS TERMINATED BY ");
 
3092
  pos= strmov(pos, "` FIELDS TERMINATED BY ");
3083
3093
  pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
3084
3094
  if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3085
 
    pos= stpcpy(pos, " OPTIONALLY ");
3086
 
  pos= stpcpy(pos, " ENCLOSED BY ");
 
3095
    pos= strmov(pos, " OPTIONALLY ");
 
3096
  pos= strmov(pos, " ENCLOSED BY ");
3087
3097
  pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
3088
3098
 
3089
 
  pos= stpcpy(pos, " ESCAPED BY ");
 
3099
  pos= strmov(pos, " ESCAPED BY ");
3090
3100
  pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
3091
3101
 
3092
 
  pos= stpcpy(pos, " LINES TERMINATED BY ");
 
3102
  pos= strmov(pos, " LINES TERMINATED BY ");
3093
3103
  pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
3094
3104
  if (sql_ex.line_start_len)
3095
3105
  {
3096
 
    pos= stpcpy(pos, " STARTING BY ");
 
3106
    pos= strmov(pos, " STARTING BY ");
3097
3107
    pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
3098
3108
  }
3099
3109
 
3100
3110
  if ((long) skip_lines > 0)
3101
3111
  {
3102
 
    pos= stpcpy(pos, " IGNORE ");
 
3112
    pos= strmov(pos, " IGNORE ");
3103
3113
    pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
3104
 
    pos= stpcpy(pos," LINES ");    
 
3114
    pos= strmov(pos," LINES ");    
3105
3115
  }
3106
3116
 
3107
3117
  if (num_fields)
3108
3118
  {
3109
3119
    uint i;
3110
3120
    const char *field= fields;
3111
 
    pos= stpcpy(pos, " (");
 
3121
    pos= strmov(pos, " (");
3112
3122
    for (i = 0; i < num_fields; i++)
3113
3123
    {
3114
3124
      if (i)
3567
3577
      "data truncated" warning but which is absorbed and never gets to the
3568
3578
      error log); still we init it to avoid a Valgrind message.
3569
3579
    */
3570
 
    drizzle_reset_errors(thd, 0);
 
3580
    mysql_reset_errors(thd, 0);
3571
3581
 
3572
3582
    TABLE_LIST tables;
3573
 
    memset(&tables, 0, sizeof(tables));
 
3583
    memset((char*) &tables, 0, sizeof(tables));
3574
3584
    tables.db= thd->strmake(thd->db, thd->db_length);
3575
3585
    tables.alias = tables.table_name = (char*) table_name;
3576
3586
    tables.lock_type = TL_WRITE;
4109
4119
void Rand_log_event::pack_info(Protocol *protocol)
4110
4120
{
4111
4121
  char buf1[256], *pos;
4112
 
  pos= stpcpy(buf1,"rand_seed1=");
 
4122
  pos= strmov(buf1,"rand_seed1=");
4113
4123
  pos= int10_to_str((long) seed1, pos, 10);
4114
 
  pos= stpcpy(pos, ",rand_seed2=");
 
4124
  pos= strmov(pos, ",rand_seed2=");
4115
4125
  pos= int10_to_str((long) seed2, pos, 10);
4116
4126
  protocol->store(buf1, (uint) (pos-buf1), &my_charset_bin);
4117
4127
}
4205
4215
void Xid_log_event::pack_info(Protocol *protocol)
4206
4216
{
4207
4217
  char buf[128], *pos;
4208
 
  pos= stpcpy(buf, "COMMIT /* xid=");
 
4218
  pos= strmov(buf, "COMMIT /* xid=");
4209
4219
  pos= int64_t10_to_str(xid, pos, 10);
4210
 
  pos= stpcpy(pos, " */");
 
4220
  pos= strmov(pos, " */");
4211
4221
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
4212
4222
}
4213
4223
#endif
4227
4237
  :Log_event(buf, description_event)
4228
4238
{
4229
4239
  buf+= description_event->common_header_len;
4230
 
  memcpy(&xid, buf, sizeof(xid));
 
4240
  memcpy((char*) &xid, buf, sizeof(xid));
4231
4241
}
4232
4242
 
4233
4243
 
4295
4305
  {
4296
4306
    if (!(buf= (char*) my_malloc(val_offset + 5, MYF(MY_WME))))
4297
4307
      return;
4298
 
    stpcpy(buf + val_offset, "NULL");
 
4308
    strmov(buf + val_offset, "NULL");
4299
4309
    event_len= val_offset + 4;
4300
4310
  }
4301
4311
  else
4332
4342
      /* 15 is for 'COLLATE' and other chars */
4333
4343
      buf= (char*) my_malloc(event_len+val_len*2+1+2*MY_CS_NAME_SIZE+15,
4334
4344
                             MYF(MY_WME));
4335
 
      const CHARSET_INFO *cs;
 
4345
      CHARSET_INFO *cs;
4336
4346
      if (!buf)
4337
4347
        return;
4338
4348
      if (!(cs= get_charset(charset_number, MYF(0))))
4339
4349
      {
4340
 
        stpcpy(buf+val_offset, "???");
 
4350
        strmov(buf+val_offset, "???");
4341
4351
        event_len+= 3;
4342
4352
      }
4343
4353
      else
4530
4540
        > according to UCS2.
4531
4541
      */
4532
4542
      char *hex_str;
4533
 
      const CHARSET_INFO *cs;
 
4543
      CHARSET_INFO *cs;
4534
4544
 
4535
4545
      if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4536
4546
        break; // no error, as we are 'void'
4572
4582
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
4573
4583
{
4574
4584
  Item *it= 0;
4575
 
  const CHARSET_INFO *charset;
 
4585
  CHARSET_INFO *charset;
4576
4586
  if (!(charset= get_charset(charset_number, MYF(MY_WME))))
4577
4587
    return 1;
4578
4588
  LEX_STRING user_var_name;
4683
4693
void Slave_log_event::pack_info(Protocol *protocol)
4684
4694
{
4685
4695
  char buf[256+HOSTNAME_LENGTH], *pos;
4686
 
  pos= stpcpy(buf, "host=");
4687
 
  pos= stpncpy(pos, master_host, HOSTNAME_LENGTH);
4688
 
  pos= stpcpy(pos, ",port=");
 
4696
  pos= strmov(buf, "host=");
 
4697
  pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
 
4698
  pos= strmov(pos, ",port=");
4689
4699
  pos= int10_to_str((long) master_port, pos, 10);
4690
 
  pos= stpcpy(pos, ",log=");
4691
 
  pos= stpcpy(pos, master_log);
4692
 
  pos= stpcpy(pos, ",pos=");
 
4700
  pos= strmov(pos, ",log=");
 
4701
  pos= strmov(pos, master_log);
 
4702
  pos= strmov(pos, ",pos=");
4693
4703
  pos= int64_t10_to_str(master_pos, pos, 10);
4694
4704
  protocol->store(buf, pos-buf, &my_charset_bin);
4695
4705
}
5046
5056
void Create_file_log_event::pack_info(Protocol *protocol)
5047
5057
{
5048
5058
  char buf[NAME_LEN*2 + 30 + 21*2], *pos;
5049
 
  pos= stpcpy(buf, "db=");
 
5059
  pos= strmov(buf, "db=");
5050
5060
  memcpy(pos, db, db_len);
5051
 
  pos= stpcpy(pos + db_len, ";table=");
 
5061
  pos= strmov(pos + db_len, ";table=");
5052
5062
  memcpy(pos, table_name, table_name_len);
5053
 
  pos= stpcpy(pos + table_name_len, ";file_id=");
 
5063
  pos= strmov(pos + table_name_len, ";file_id=");
5054
5064
  pos= int10_to_str((long) file_id, pos, 10);
5055
 
  pos= stpcpy(pos, ";block_len=");
 
5065
  pos= strmov(pos, ";block_len=");
5056
5066
  pos= int10_to_str((long) block_len, pos, 10);
5057
5067
  protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5058
5068
}
5072
5082
  IO_CACHE file;
5073
5083
  int error = 1;
5074
5084
 
5075
 
  memset(&file, 0, sizeof(file));
5076
 
  fname_buf= stpcpy(proc_info, "Making temp file ");
 
5085
  memset((char*)&file, 0, sizeof(file));
 
5086
  fname_buf= strmov(proc_info, "Making temp file ");
5077
5087
  ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
5078
5088
  thd_proc_info(thd, proc_info);
5079
5089
  my_delete(fname_buf, MYF(0)); // old copy may exist already
5091
5101
  
5092
5102
  // a trick to avoid allocating another buffer
5093
5103
  fname= fname_buf;
5094
 
  fname_len= (uint) (stpcpy(ext, ".data") - fname);
 
5104
  fname_len= (uint) (strmov(ext, ".data") - fname);
5095
5105
  if (write_base(&file))
5096
5106
  {
5097
 
    stpcpy(ext, ".info"); // to have it right in the error message
 
5107
    strmov(ext, ".info"); // to have it right in the error message
5098
5108
    rli->report(ERROR_LEVEL, my_errno,
5099
5109
                "Error in Create_file event: could not write to file '%s'",
5100
5110
                fname_buf);
5245
5255
  int fd;
5246
5256
  int error = 1;
5247
5257
 
5248
 
  fname= stpcpy(proc_info, "Making temp file ");
 
5258
  fname= strmov(proc_info, "Making temp file ");
5249
5259
  slave_load_file_stem(fname, file_id, server_id, ".data");
5250
5260
  thd_proc_info(thd, proc_info);
5251
5261
  if (get_create_or_append())
5375
5385
  char fname[FN_REFLEN+10];
5376
5386
  char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
5377
5387
  (void) my_delete(fname, MYF(MY_WME));
5378
 
  stpcpy(ext, ".info");
 
5388
  strmov(ext, ".info");
5379
5389
  (void) my_delete(fname, MYF(MY_WME));
5380
5390
  return 0;
5381
5391
}
5715
5725
  pos= buf;
5716
5726
  if (db && db_len)
5717
5727
  {
5718
 
    pos= stpcpy(buf, "use `");
 
5728
    pos= strmov(buf, "use `");
5719
5729
    memcpy(pos, db, db_len);
5720
 
    pos= stpcpy(pos+db_len, "`; ");
 
5730
    pos= strmov(pos+db_len, "`; ");
5721
5731
  }
5722
5732
  if (query && q_len)
5723
5733
  {
5724
5734
    memcpy(pos, query, q_len);
5725
5735
    pos+= q_len;
5726
5736
  }
5727
 
  pos= stpcpy(pos, " ;file_id=");
 
5737
  pos= strmov(pos, " ;file_id=");
5728
5738
  pos= int10_to_str((long) file_id, pos, 10);
5729
5739
  protocol->store(buf, pos-buf, &my_charset_bin);
5730
5740
  my_free(buf, MYF(MY_ALLOW_ZERO_PTR));
6982
6992
  table_list->next_global= table_list->next_local= 0;
6983
6993
  table_list->table_id= m_table_id;
6984
6994
  table_list->updating= 1;
6985
 
  stpcpy(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
6986
 
  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);
6987
6997
 
6988
6998
  int error= 0;
6989
6999
 
7391
7401
     values filled in and one flag to handle the case that the default
7392
7402
     values should be checked. Maybe these two flags can be combined.
7393
7403
  */
7394
 
  if ((error= prepare_record(table, &m_cols, m_width, true)))
 
7404
  if ((error= prepare_record(table, &m_cols, m_width,
 
7405
                             table->file->ht->db_type != DB_TYPE_NDBCLUSTER)))
7395
7406
    return(error);
7396
7407
  
7397
7408
  /* unpack row into table->record[0] */