~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_class.cc

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
 
21
17
/*****************************************************************************
25
21
**
26
22
*****************************************************************************/
27
23
#include <drizzled/server_includes.h>
28
 
#include <drizzled/rpl_rli.h>
29
 
#include <drizzled/rpl_record.h>
30
 
#include <drizzled/log_event.h>
 
24
#include "rpl_rli.h"
 
25
#include "rpl_record.h"
 
26
#include "log_event.h"
31
27
#include <sys/stat.h>
32
28
#include <mysys/thr_alarm.h>
33
29
#include <mysys/mysys_err.h>
34
 
#include <drizzled/error.h>
35
 
#include <drizzled/query_id.h>
36
 
#include <drizzled/data_home.h>
 
30
#include <drizzled/drizzled_error_messages.h>
37
31
 
38
 
extern scheduler_functions thread_scheduler;
39
32
/*
40
33
  The following is used to initialise Table_ident with a internal
41
34
  table name
43
36
char internal_table_name[2]= "*";
44
37
char empty_c_string[1]= {0};    /* used for not defined db */
45
38
 
46
 
const char * const Session::DEFAULT_WHERE= "field list";
 
39
const char * const THD::DEFAULT_WHERE= "field list";
47
40
 
48
41
 
49
42
/*****************************************************************************
66
59
** User variables
67
60
****************************************************************************/
68
61
 
69
 
extern "C" unsigned char *get_var_key(user_var_entry *entry, size_t *length,
 
62
extern "C" uchar *get_var_key(user_var_entry *entry, size_t *length,
70
63
                              bool not_used __attribute__((unused)))
71
64
{
72
65
  *length= entry->name.length;
73
 
  return (unsigned char*) entry->name.str;
 
66
  return (uchar*) entry->name.str;
74
67
}
75
68
 
76
69
extern "C" void free_user_var(user_var_entry *entry)
77
70
{
78
71
  char *pos= (char*) entry+ALIGN_SIZE(sizeof(*entry));
79
72
  if (entry->value && entry->value != pos)
80
 
    free(entry->value);
81
 
  free((char*) entry);
 
73
    my_free(entry->value, MYF(0));
 
74
  my_free((char*) entry,MYF(0));
82
75
}
83
76
 
84
77
bool Key_part_spec::operator==(const Key_part_spec& other) const
92
85
  Construct an (almost) deep copy of this key. Only those
93
86
  elements that are known to never change are not copied.
94
87
  If out of memory, a partial copy is returned and an error is set
95
 
  in Session.
 
88
  in THD.
96
89
*/
97
90
 
98
91
Key::Key(const Key &rhs, MEM_ROOT *mem_root)
109
102
  Construct an (almost) deep copy of this foreign key. Only those
110
103
  elements that are known to never change are not copied.
111
104
  If out of memory, a partial copy is returned and an error is set
112
 
  in Session.
 
105
  in THD.
113
106
*/
114
107
 
115
108
Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root)
190
183
}
191
184
 
192
185
 
193
 
/*
194
 
  Check if the foreign key options are compatible with columns
195
 
  on which the FK is created.
196
 
 
197
 
  RETURN
198
 
    0   Key valid
199
 
    1   Key invalid
200
 
*/
201
 
bool Foreign_key::validate(List<Create_field> &table_fields)
202
 
{
203
 
  Create_field  *sql_field;
204
 
  Key_part_spec *column;
205
 
  List_iterator<Key_part_spec> cols(columns);
206
 
  List_iterator<Create_field> it(table_fields);
207
 
  while ((column= cols++))
208
 
  {
209
 
    it.rewind();
210
 
    while ((sql_field= it++) &&
211
 
           my_strcasecmp(system_charset_info,
212
 
                         column->field_name.str,
213
 
                         sql_field->field_name)) {}
214
 
    if (!sql_field)
215
 
    {
216
 
      my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.str);
217
 
      return true;
218
 
    }
219
 
    if (type == Key::FOREIGN_KEY && sql_field->vcol_info)
220
 
    {
221
 
      if (delete_opt == FK_OPTION_SET_NULL)
222
 
      {
223
 
        my_error(ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN, MYF(0), 
224
 
                 "ON DELETE SET NULL");
225
 
        return true;
226
 
      }
227
 
      if (update_opt == FK_OPTION_SET_NULL)
228
 
      {
229
 
        my_error(ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN, MYF(0), 
230
 
                 "ON UPDATE SET NULL");
231
 
        return true;
232
 
      }
233
 
      if (update_opt == FK_OPTION_CASCADE)
234
 
      {
235
 
        my_error(ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN, MYF(0), 
236
 
                 "ON UPDATE CASCADE");
237
 
        return true;
238
 
      }
239
 
    }
240
 
  }
241
 
  return false;
242
 
}
243
 
 
244
 
 
245
186
/****************************************************************************
246
187
** Thread specific functions
247
188
****************************************************************************/
260
201
{
261
202
  char filename[FN_REFLEN];
262
203
  File fd = create_temp_file(filename, mysql_tmpdir, prefix,
263
 
                             O_CREAT | O_EXCL | O_RDWR,
 
204
                             O_CREAT | O_EXCL | O_RDWR | O_TEMPORARY,
264
205
                             MYF(MY_WME));
265
206
  if (fd >= 0) {
 
207
    /*
 
208
      This can be removed once the following bug is fixed:
 
209
      Bug #28903  create_temp_file() doesn't honor O_TEMPORARY option
 
210
                  (file not removed) (Unix)
 
211
    */
266
212
    unlink(filename);
267
213
  }
268
214
 
271
217
 
272
218
 
273
219
extern "C"
274
 
int session_in_lock_tables(const Session *session)
275
 
{
276
 
  return test(session->in_lock_tables);
277
 
}
278
 
 
279
 
 
280
 
extern "C"
281
 
int session_tablespace_op(const Session *session)
282
 
{
283
 
  return test(session->tablespace_op);
284
 
}
285
 
 
286
 
 
287
 
/**
288
 
   Set the process info field of the Session structure.
289
 
 
290
 
   This function is used by plug-ins. Internally, the
291
 
   Session::set_proc_info() function should be used.
292
 
 
293
 
   @see Session::set_proc_info
294
 
 */
295
 
extern "C" void
296
 
set_session_proc_info(Session *session, const char *info)
297
 
{
298
 
  session->set_proc_info(info);
299
 
}
300
 
 
301
 
extern "C"
302
 
const char *get_session_proc_info(Session *session)
303
 
{
304
 
  return session->get_proc_info();
305
 
}
306
 
 
307
 
extern "C"
308
 
void **session_ha_data(const Session *session, const struct handlerton *hton)
309
 
{
310
 
  return (void **) &session->ha_data[hton->slot].ha_ptr;
311
 
}
312
 
 
313
 
extern "C"
314
 
int64_t session_test_options(const Session *session, int64_t test_options)
315
 
{
316
 
  return session->options & test_options;
317
 
}
318
 
 
319
 
extern "C"
320
 
int session_sql_command(const Session *session)
321
 
{
322
 
  return (int) session->lex->sql_command;
323
 
}
324
 
 
325
 
extern "C"
326
 
int session_tx_isolation(const Session *session)
327
 
{
328
 
  return (int) session->variables.tx_isolation;
329
 
}
330
 
 
331
 
extern "C"
332
 
void session_inc_row_count(Session *session)
333
 
{
334
 
  session->row_count++;
 
220
int thd_in_lock_tables(const THD *thd)
 
221
{
 
222
  return test(thd->in_lock_tables);
 
223
}
 
224
 
 
225
 
 
226
extern "C"
 
227
int thd_tablespace_op(const THD *thd)
 
228
{
 
229
  return test(thd->tablespace_op);
 
230
}
 
231
 
 
232
 
 
233
extern "C"
 
234
const char *set_thd_proc_info(THD *thd, const char *info,
 
235
                              const char *calling_function __attribute__((unused)),
 
236
                              const char *calling_file __attribute__((unused)),
 
237
                              const unsigned int calling_line __attribute__((unused)))
 
238
{
 
239
  const char *old_info= thd->get_proc_info();
 
240
  thd->set_proc_info(info);
 
241
  return old_info;
 
242
}
 
243
 
 
244
extern "C"
 
245
void **thd_ha_data(const THD *thd, const struct handlerton *hton)
 
246
{
 
247
  return (void **) &thd->ha_data[hton->slot].ha_ptr;
 
248
}
 
249
 
 
250
extern "C"
 
251
int64_t thd_test_options(const THD *thd, int64_t test_options)
 
252
{
 
253
  return thd->options & test_options;
 
254
}
 
255
 
 
256
extern "C"
 
257
int thd_sql_command(const THD *thd)
 
258
{
 
259
  return (int) thd->lex->sql_command;
 
260
}
 
261
 
 
262
extern "C"
 
263
int thd_tx_isolation(const THD *thd)
 
264
{
 
265
  return (int) thd->variables.tx_isolation;
 
266
}
 
267
 
 
268
extern "C"
 
269
void thd_inc_row_count(THD *thd)
 
270
{
 
271
  thd->row_count++;
335
272
}
336
273
 
337
274
/**
363
300
*/
364
301
 
365
302
void
366
 
Diagnostics_area::set_ok_status(Session *session, ha_rows affected_rows_arg,
 
303
Diagnostics_area::set_ok_status(THD *thd, ha_rows affected_rows_arg,
367
304
                                uint64_t last_insert_id_arg,
368
305
                                const char *message_arg)
369
306
{
376
313
    return;
377
314
  /** Only allowed to report success if has not yet reported an error */
378
315
 
379
 
  m_server_status= session->server_status;
380
 
  m_total_warn_count= session->total_warn_count;
 
316
  m_server_status= thd->server_status;
 
317
  m_total_warn_count= thd->total_warn_count;
381
318
  m_affected_rows= affected_rows_arg;
382
319
  m_last_insert_id= last_insert_id_arg;
383
320
  if (message_arg)
393
330
*/
394
331
 
395
332
void
396
 
Diagnostics_area::set_eof_status(Session *session)
 
333
Diagnostics_area::set_eof_status(THD *thd)
397
334
{
398
335
  /** Only allowed to report eof if has not yet reported an error */
399
336
 
405
342
  if (is_error() || is_disabled())
406
343
    return;
407
344
 
408
 
  m_server_status= session->server_status;
 
345
  m_server_status= thd->server_status;
409
346
  /*
410
347
    If inside a stored procedure, do not return the total
411
348
    number of warnings, since they are not available to the client
412
349
    anyway.
413
350
  */
414
 
  m_total_warn_count= session->total_warn_count;
 
351
  m_total_warn_count= thd->total_warn_count;
415
352
 
416
353
  m_status= DA_EOF;
417
354
}
421
358
*/
422
359
 
423
360
void
424
 
Diagnostics_area::set_error_status(Session *session __attribute__((unused)),
425
 
                                   uint32_t sql_errno_arg,
 
361
Diagnostics_area::set_error_status(THD *thd __attribute__((unused)),
 
362
                                   uint sql_errno_arg,
426
363
                                   const char *message_arg)
427
364
{
428
365
  /*
461
398
}
462
399
 
463
400
 
464
 
Session::Session()
465
 
   :Statement(&main_lex, &main_mem_root,
 
401
THD::THD()
 
402
   :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION,
466
403
              /* statement id */ 0),
467
404
   Open_tables_state(refresh_version), rli_fake(0),
468
405
   lock_id(&main_lock_id),
469
 
   user_time(0),
 
406
   user_time(0), in_sub_stmt(0),
470
407
   binlog_table_maps(0), binlog_flags(0UL),
471
408
   arg_of_last_insert_id_function(false),
472
409
   first_successful_insert_id_in_prev_stmt(0),
480
417
   rand_used(0),
481
418
   time_zone_used(0),
482
419
   in_lock_tables(0),
 
420
   bootstrap(0),
483
421
   derived_tables_processing(false),
484
422
   m_lip(NULL)
485
423
{
491
429
    will be re-initialized in init_for_queries().
492
430
  */
493
431
  init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
 
432
  stmt_arena= this;
494
433
  thread_stack= 0;
495
434
  catalog= (char*)"std"; // the only catalog we have for now
496
435
  main_security_ctx.init();
508
447
  limit_found_rows= 0;
509
448
  row_count_func= -1;
510
449
  statement_id_counter= 0UL;
511
 
  // Must be reset to handle error with Session's created for init of mysqld
 
450
  // Must be reset to handle error with THD's created for init of mysqld
512
451
  lex->current_select= 0;
513
452
  start_time=(time_t) 0;
514
453
  start_utime= 0L;
525
464
  memset(ha_data, 0, sizeof(ha_data));
526
465
  mysys_var=0;
527
466
  binlog_evt_union.do_union= false;
528
 
  dbug_sentry=Session_SENTRY_MAGIC;
 
467
  enable_slow_log= 0;
 
468
  dbug_sentry=THD_SENTRY_MAGIC;
529
469
  net.vio=0;
530
470
  client_capabilities= 0;                       // minimalistic client
531
471
  system_thread= NON_SYSTEM_THREAD;
533
473
  peer_port= 0;                                 // For SHOW PROCESSLIST
534
474
  transaction.m_pending_rows_event= 0;
535
475
  transaction.on= 1;
 
476
#ifdef SIGNAL_WITH_VIO_CLOSE
 
477
  active_vio = 0;
 
478
#endif
536
479
  pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
537
480
 
538
481
  /* Variables with default values */
539
482
  proc_info="login";
540
 
  where= Session::DEFAULT_WHERE;
 
483
  where= THD::DEFAULT_WHERE;
541
484
  server_id = ::server_id;
542
485
  slave_net = 0;
543
486
  command=COM_CONNECT;
562
505
  protocol= &protocol_text;                     // Default protocol
563
506
  protocol_text.init(this);
564
507
 
565
 
  const Query_id& query_id= Query_id::get_query_id();
566
508
  tablespace_op= false;
567
509
  tmp= sql_rnd();
568
 
  randominit(&rand, tmp + (ulong) &rand, tmp + query_id.value());
 
510
  randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::global_query_id);
569
511
  substitute_null_with_insert_id = false;
570
512
  thr_lock_info_init(&lock_info); /* safety: will be reset after start */
571
513
  thr_lock_owner_init(&main_lock_id, &lock_info);
574
516
}
575
517
 
576
518
 
577
 
void Session::push_internal_handler(Internal_error_handler *handler)
 
519
void THD::push_internal_handler(Internal_error_handler *handler)
578
520
{
579
521
  /*
580
522
    TODO: The current implementation is limited to 1 handler at a time only.
581
 
    Session and sp_rcontext need to be modified to use a common handler stack.
 
523
    THD and sp_rcontext need to be modified to use a common handler stack.
582
524
  */
583
525
  assert(m_internal_handler == NULL);
584
526
  m_internal_handler= handler;
585
527
}
586
528
 
587
529
 
588
 
bool Session::handle_error(uint32_t sql_errno, const char *message,
 
530
bool THD::handle_error(uint sql_errno, const char *message,
589
531
                       DRIZZLE_ERROR::enum_warning_level level)
590
532
{
591
533
  if (m_internal_handler)
597
539
}
598
540
 
599
541
 
600
 
void Session::pop_internal_handler()
 
542
void THD::pop_internal_handler()
601
543
{
602
544
  assert(m_internal_handler != NULL);
603
545
  m_internal_handler= NULL;
604
546
}
605
547
 
606
 
#if defined(__cplusplus)
607
 
extern "C" {
608
 
#endif
609
 
 
610
 
void *session_alloc(Session *session, unsigned int size)
611
 
{
612
 
  return session->alloc(size);
613
 
}
614
 
 
615
 
void *session_calloc(Session *session, unsigned int size)
616
 
{
617
 
  return session->calloc(size);
618
 
}
619
 
 
620
 
char *session_strdup(Session *session, const char *str)
621
 
{
622
 
  return session->strdup(str);
623
 
}
624
 
 
625
 
char *session_strmake(Session *session, const char *str, unsigned int size)
626
 
{
627
 
  return session->strmake(str, size);
628
 
}
629
 
 
630
 
void *session_memdup(Session *session, const void* str, unsigned int size)
631
 
{
632
 
  return session->memdup(str, size);
633
 
}
634
 
 
635
 
void session_get_xid(const Session *session, DRIZZLE_XID *xid)
636
 
{
637
 
  *xid = *(DRIZZLE_XID *) &session->transaction.xid_state.xid;
638
 
}
639
 
 
640
 
#if defined(__cplusplus)
641
 
}
642
 
#endif
 
548
extern "C"
 
549
void *thd_alloc(DRIZZLE_THD thd, unsigned int size)
 
550
{
 
551
  return thd->alloc(size);
 
552
}
 
553
 
 
554
extern "C"
 
555
void *thd_calloc(DRIZZLE_THD thd, unsigned int size)
 
556
{
 
557
  return thd->calloc(size);
 
558
}
 
559
 
 
560
extern "C"
 
561
char *thd_strdup(DRIZZLE_THD thd, const char *str)
 
562
{
 
563
  return thd->strdup(str);
 
564
}
 
565
 
 
566
extern "C"
 
567
char *thd_strmake(DRIZZLE_THD thd, const char *str, unsigned int size)
 
568
{
 
569
  return thd->strmake(str, size);
 
570
}
 
571
 
 
572
extern "C"
 
573
LEX_STRING *thd_make_lex_string(THD *thd, LEX_STRING *lex_str,
 
574
                                const char *str, unsigned int size,
 
575
                                int allocate_lex_string)
 
576
{
 
577
  return thd->make_lex_string(lex_str, str, size,
 
578
                              (bool) allocate_lex_string);
 
579
}
 
580
 
 
581
extern "C"
 
582
void *thd_memdup(DRIZZLE_THD thd, const void* str, unsigned int size)
 
583
{
 
584
  return thd->memdup(str, size);
 
585
}
 
586
 
 
587
extern "C"
 
588
void thd_get_xid(const DRIZZLE_THD thd, DRIZZLE_XID *xid)
 
589
{
 
590
  *xid = *(DRIZZLE_XID *) &thd->transaction.xid_state.xid;
 
591
}
643
592
 
644
593
/*
645
594
  Init common variables that has to be reset on start and on change_user
646
595
*/
647
596
 
648
 
void Session::init(void)
 
597
void THD::init(void)
649
598
{
650
599
  pthread_mutex_lock(&LOCK_global_system_variables);
651
 
  plugin_sessionvar_init(this);
652
 
  variables.time_format= date_time_format_copy((Session*) 0,
 
600
  plugin_thdvar_init(this);
 
601
  variables.time_format= date_time_format_copy((THD*) 0,
653
602
                                               variables.time_format);
654
 
  variables.date_format= date_time_format_copy((Session*) 0,
 
603
  variables.date_format= date_time_format_copy((THD*) 0,
655
604
                                               variables.date_format);
656
 
  variables.datetime_format= date_time_format_copy((Session*) 0,
 
605
  variables.datetime_format= date_time_format_copy((THD*) 0,
657
606
                                                   variables.datetime_format);
658
607
  /*
659
608
    variables= global_system_variables above has reset
663
612
  variables.pseudo_thread_id= thread_id;
664
613
  pthread_mutex_unlock(&LOCK_global_system_variables);
665
614
  server_status= SERVER_STATUS_AUTOCOMMIT;
666
 
  options= session_startup_options;
 
615
  options= thd_startup_options;
667
616
 
668
617
  if (variables.max_join_size == HA_POS_ERROR)
669
618
    options |= OPTION_BIG_SELECTS;
686
635
 
687
636
 
688
637
/*
689
 
  Init Session for query processing.
 
638
  Init THD for query processing.
690
639
  This has to be called once before we call mysql_parse.
691
640
  See also comments in sql_class.h.
692
641
*/
693
642
 
694
 
void Session::init_for_queries()
 
643
void THD::init_for_queries()
695
644
{
696
645
  set_time(); 
697
646
  ha_enable_transaction(this,true);
702
651
                      variables.trans_alloc_block_size,
703
652
                      variables.trans_prealloc_size);
704
653
  transaction.xid_state.xid.null();
705
 
  transaction.xid_state.in_session=1;
 
654
  transaction.xid_state.in_thd=1;
706
655
}
707
656
 
708
657
 
709
658
/* Do operations that may take a long time */
710
659
 
711
 
void Session::cleanup(void)
 
660
void THD::cleanup(void)
712
661
{
713
662
  assert(cleanup_done == 0);
714
663
 
732
681
  delete_dynamic(&user_var_events);
733
682
  hash_free(&user_vars);
734
683
  close_temporary_tables(this);
735
 
  free((char*) variables.time_format);
736
 
  free((char*) variables.date_format);
737
 
  free((char*) variables.datetime_format);
 
684
  my_free((char*) variables.time_format, MYF(MY_ALLOW_ZERO_PTR));
 
685
  my_free((char*) variables.date_format, MYF(MY_ALLOW_ZERO_PTR));
 
686
  my_free((char*) variables.datetime_format, MYF(MY_ALLOW_ZERO_PTR));
738
687
  
739
688
  if (global_read_lock)
740
689
    unlock_global_read_lock(this);
743
692
  return;
744
693
}
745
694
 
746
 
Session::~Session()
 
695
THD::~THD()
747
696
{
748
 
  Session_CHECK_SENTRY(this);
749
 
  /* Ensure that no one is using Session */
 
697
  THD_CHECK_SENTRY(this);
 
698
  /* Ensure that no one is using THD */
750
699
  pthread_mutex_lock(&LOCK_delete);
751
700
  pthread_mutex_unlock(&LOCK_delete);
752
701
  add_to_status(&global_status_var, &status_var);
754
703
  /* Close connection */
755
704
  if (net.vio)
756
705
  {
757
 
    net_close(&net);
 
706
    vio_delete(net.vio);
758
707
    net_end(&net);
759
708
  }
760
709
  if (!cleanup_done)
761
710
    cleanup();
762
711
 
763
712
  ha_close_connection(this);
764
 
  plugin_sessionvar_cleanup(this);
 
713
  plugin_thdvar_cleanup(this);
765
714
 
766
715
  main_security_ctx.destroy();
767
 
  if (db)
768
 
  {
769
 
    free(db);
770
 
    db= NULL;
771
 
  }
 
716
  safeFree(db);
772
717
  free_root(&warn_root,MYF(0));
773
718
  free_root(&transaction.mem_root,MYF(0));
774
719
  mysys_var=0;                                  // Safety (shouldn't be needed)
775
720
  pthread_mutex_destroy(&LOCK_delete);
776
 
  dbug_sentry= Session_SENTRY_GONE;
 
721
  dbug_sentry= THD_SENTRY_GONE;
777
722
  if (rli_fake)
778
723
  {
779
724
    delete rli_fake;
801
746
 
802
747
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
803
748
{
804
 
  ulong *end= (ulong*) ((unsigned char*) to_var +
 
749
  ulong *end= (ulong*) ((uchar*) to_var +
805
750
                        offsetof(STATUS_VAR, last_system_status_var) +
806
751
                        sizeof(ulong));
807
752
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var;
826
771
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
827
772
                        STATUS_VAR *dec_var)
828
773
{
829
 
  ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(STATUS_VAR,
 
774
  ulong *end= (ulong*) ((uchar*) to_var + offsetof(STATUS_VAR,
830
775
                                                  last_system_status_var) +
831
776
                        sizeof(ulong));
832
777
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var, *dec= (ulong*) dec_var;
836
781
}
837
782
 
838
783
 
839
 
void Session::awake(Session::killed_state state_to_set)
 
784
void THD::awake(THD::killed_state state_to_set)
840
785
{
841
 
  Session_CHECK_SENTRY(this);
 
786
  THD_CHECK_SENTRY(this);
842
787
  safe_mutex_assert_owner(&LOCK_delete); 
843
788
 
844
789
  killed= state_to_set;
845
 
  if (state_to_set != Session::KILL_QUERY)
 
790
  if (state_to_set != THD::KILL_QUERY)
846
791
  {
847
792
    thr_alarm_kill(thread_id);
848
793
    if (!slave_thread)
849
794
      thread_scheduler.post_kill_notification(this);
 
795
#ifdef SIGNAL_WITH_VIO_CLOSE
 
796
    if (this != current_thd)
 
797
    {
 
798
      /*
 
799
        In addition to a signal, let's close the socket of the thread that
 
800
        is being killed. This is to make sure it does not block if the
 
801
        signal is lost. This needs to be done only on platforms where
 
802
        signals are not a reliable interruption mechanism.
 
803
 
 
804
        If we're killing ourselves, we know that we're not blocked, so this
 
805
        hack is not used.
 
806
      */
 
807
 
 
808
      close_active_vio();
 
809
    }
 
810
#endif    
850
811
  }
851
812
  if (mysys_var)
852
813
  {
869
830
      current_cond and current_mutex are 0), then the victim will not get
870
831
      a signal and it may wait "forever" on the cond (until
871
832
      we issue a second KILL or the status it's waiting for happens).
872
 
      It's true that we have set its session->killed but it may not
 
833
      It's true that we have set its thd->killed but it may not
873
834
      see it immediately and so may have time to reach the cond_wait().
874
835
    */
875
836
    if (mysys_var->current_cond && mysys_var->current_mutex)
888
849
  sql_alloc() and the structure for the net buffer
889
850
*/
890
851
 
891
 
bool Session::store_globals()
 
852
bool THD::store_globals()
892
853
{
893
854
  /*
894
855
    Assert that thread_stack is initialized: it's necessary to be able
896
857
  */
897
858
  assert(thread_stack);
898
859
 
899
 
  if (pthread_setspecific(THR_Session,  this) ||
900
 
      pthread_setspecific(THR_MALLOC, &mem_root))
 
860
  if (my_pthread_setspecific_ptr(THR_THD,  this) ||
 
861
      my_pthread_setspecific_ptr(THR_MALLOC, &mem_root))
901
862
    return 1;
902
863
  mysys_var=my_thread_var;
903
864
  /*
904
865
    Let mysqld define the thread id (not mysys)
905
 
    This allows us to move Session to different threads if needed.
 
866
    This allows us to move THD to different threads if needed.
906
867
  */
907
868
  mysys_var->id= thread_id;
908
869
  real_id= pthread_self();                      // For debugging
909
870
 
910
871
  /*
911
 
    We have to call thr_lock_info_init() again here as Session may have been
 
872
    We have to call thr_lock_info_init() again here as THD may have been
912
873
    created in another thread
913
874
  */
914
875
  thr_lock_info_init(&lock_info);
920
881
  Cleanup after query.
921
882
 
922
883
  SYNOPSIS
923
 
    Session::cleanup_after_query()
 
884
    THD::cleanup_after_query()
924
885
 
925
886
  DESCRIPTION
926
887
    This function is used to reset thread data to its default state.
932
893
    slave.
933
894
*/
934
895
 
935
 
void Session::cleanup_after_query()
 
896
void THD::cleanup_after_query()
936
897
{
937
898
  /*
938
899
    Reset rand_used so that detection of calls to rand() will save random 
939
900
    seeds if needed by the slave.
 
901
 
 
902
    Do not reset rand_used if inside a stored function or trigger because 
 
903
    only the call to these operations is logged. Thus only the calling 
 
904
    statement needs to detect rand() calls made by its substatements. These
 
905
    substatements must not set rand_used to 0 because it would remove the
 
906
    detection of rand() by the calling statement. 
940
907
  */
 
908
  if (!in_sub_stmt) /* stored functions and triggers are a special case */
941
909
  {
942
910
    /* Forget those values, for next binlogger: */
943
911
    stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
956
924
  /* Free Items that were created during this execution */
957
925
  free_items();
958
926
  /* Reset where. */
959
 
  where= Session::DEFAULT_WHERE;
 
927
  where= THD::DEFAULT_WHERE;
960
928
}
961
929
 
962
930
 
970
938
                              instead of using lex_str value
971
939
  @return  NULL on failure, or pointer to the LEX_STRING object
972
940
*/
973
 
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
974
 
                                 const char* str, uint32_t length,
 
941
LEX_STRING *THD::make_lex_string(LEX_STRING *lex_str,
 
942
                                 const char* str, uint length,
975
943
                                 bool allocate_lex_string)
976
944
{
977
945
  if (allocate_lex_string)
1004
972
        In this case to->str will point to 0 and to->length will be 0.
1005
973
*/
1006
974
 
1007
 
bool Session::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1008
 
                         const char *from, uint32_t from_length,
 
975
bool THD::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
 
976
                         const char *from, uint from_length,
1009
977
                         const CHARSET_INFO * const from_cs)
1010
978
{
1011
979
  size_t new_length= to_cs->mbmaxlen * from_length;
1012
 
  uint32_t dummy_errors;
 
980
  uint dummy_errors;
1013
981
  if (!(to->str= (char*) alloc(new_length+1)))
1014
982
  {
1015
983
    to->length= 0;                              // Safety fix
1026
994
  Convert string from source character set to target character set inplace.
1027
995
 
1028
996
  SYNOPSIS
1029
 
    Session::convert_string
 
997
    THD::convert_string
1030
998
 
1031
999
  DESCRIPTION
1032
1000
    Convert string using convert_buffer - buffer for character set 
1037
1005
   !0   out of memory
1038
1006
*/
1039
1007
 
1040
 
bool Session::convert_string(String *s, const CHARSET_INFO * const from_cs,
 
1008
bool THD::convert_string(String *s, const CHARSET_INFO * const from_cs,
1041
1009
                         const CHARSET_INFO * const to_cs)
1042
1010
{
1043
 
  uint32_t dummy_errors;
 
1011
  uint dummy_errors;
1044
1012
  if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
1045
1013
    return true;
1046
1014
  /* If convert_buffer >> s copying is more efficient long term */
1058
1026
  Update some cache variables when character set changes
1059
1027
*/
1060
1028
 
1061
 
void Session::update_charset()
 
1029
void THD::update_charset()
1062
1030
{
1063
1031
  uint32_t not_used;
1064
1032
  charset_is_system_charset= !String::needs_conversion(0,charset(),
1088
1056
 
1089
1057
/* add table to list of changed in transaction tables */
1090
1058
 
1091
 
void Session::add_changed_table(Table *table)
 
1059
void THD::add_changed_table(Table *table)
1092
1060
{
1093
1061
  assert((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
1094
1062
              table->file->has_transactions());
1098
1066
}
1099
1067
 
1100
1068
 
1101
 
void Session::add_changed_table(const char *key, long key_length)
 
1069
void THD::add_changed_table(const char *key, long key_length)
1102
1070
{
1103
1071
  CHANGED_TableList **prev_changed = &transaction.changed_tables;
1104
1072
  CHANGED_TableList *curr = transaction.changed_tables;
1130
1098
}
1131
1099
 
1132
1100
 
1133
 
CHANGED_TableList* Session::changed_table_dup(const char *key, long key_length)
 
1101
CHANGED_TableList* THD::changed_table_dup(const char *key, long key_length)
1134
1102
{
1135
1103
  CHANGED_TableList* new_table = 
1136
1104
    (CHANGED_TableList*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TableList))+
1151
1119
}
1152
1120
 
1153
1121
 
1154
 
int Session::send_explain_fields(select_result *result)
 
1122
int THD::send_explain_fields(select_result *result)
1155
1123
{
1156
1124
  List<Item> field_list;
1157
1125
  Item *item;
1190
1158
                              Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF));
1191
1159
}
1192
1160
 
 
1161
#ifdef SIGNAL_WITH_VIO_CLOSE
 
1162
void THD::close_active_vio()
 
1163
{
 
1164
  safe_mutex_assert_owner(&LOCK_delete); 
 
1165
  if (active_vio)
 
1166
  {
 
1167
    vio_close(active_vio);
 
1168
    active_vio = 0;
 
1169
  }
 
1170
  return;
 
1171
}
 
1172
#endif
 
1173
 
1193
1174
 
1194
1175
struct Item_change_record: public ilink
1195
1176
{
1211
1192
/*
1212
1193
  Register an item tree tree transformation, performed by the query
1213
1194
  optimizer. We need a pointer to runtime_memroot because it may be !=
1214
 
  session->mem_root (this may no longer be a true statement)
 
1195
  thd->mem_root (due to possible set_n_backup_active_arena called for thd).
1215
1196
*/
1216
1197
 
1217
 
void Session::nocheck_register_item_tree_change(Item **place, Item *old_value,
 
1198
void THD::nocheck_register_item_tree_change(Item **place, Item *old_value,
1218
1199
                                            MEM_ROOT *runtime_memroot)
1219
1200
{
1220
1201
  Item_change_record *change;
1227
1208
  if (change_mem == 0)
1228
1209
  {
1229
1210
    /*
1230
 
      OOM, session->fatal_error() is called by the error handler of the
 
1211
      OOM, thd->fatal_error() is called by the error handler of the
1231
1212
      memroot. Just return.
1232
1213
    */
1233
1214
    return;
1239
1220
}
1240
1221
 
1241
1222
 
1242
 
void Session::rollback_item_tree_changes()
 
1223
void THD::rollback_item_tree_changes()
1243
1224
{
1244
1225
  I_List_iterator<Item_change_record> it(change_list);
1245
1226
  Item_change_record *change;
1252
1233
}
1253
1234
 
1254
1235
 
 
1236
/**
 
1237
  Check that the endpoint is still available.
 
1238
*/
 
1239
 
 
1240
bool THD::vio_is_connected()
 
1241
{
 
1242
  uint bytes= 0;
 
1243
 
 
1244
  /* End of input is signaled by poll if the socket is aborted. */
 
1245
  if (vio_poll_read(net.vio, 0))
 
1246
    return true;
 
1247
 
 
1248
  /* Socket is aborted if signaled but no data is available. */
 
1249
  if (vio_peek_read(net.vio, &bytes))
 
1250
    return true;
 
1251
 
 
1252
  return bytes ? true : false;
 
1253
}
 
1254
 
 
1255
 
1255
1256
/*****************************************************************************
1256
1257
** Functions to provide a interface to select results
1257
1258
*****************************************************************************/
1258
1259
 
1259
1260
select_result::select_result()
1260
1261
{
1261
 
  session=current_session;
 
1262
  thd=current_thd;
1262
1263
}
1263
1264
 
1264
 
void select_result::send_error(uint32_t errcode,const char *err)
 
1265
void select_result::send_error(uint errcode,const char *err)
1265
1266
{
1266
1267
  my_message(errcode, err, MYF(0));
1267
1268
}
1295
1296
  cs= NULL;
1296
1297
}
1297
1298
 
1298
 
bool select_send::send_fields(List<Item> &list, uint32_t flags)
 
1299
bool select_send::send_fields(List<Item> &list, uint flags)
1299
1300
{
1300
1301
  bool res;
1301
 
  if (!(res= session->protocol->send_fields(&list, flags)))
 
1302
  if (!(res= thd->protocol->send_fields(&list, flags)))
1302
1303
    is_result_set_started= 1;
1303
1304
  return res;
1304
1305
}
1333
1334
  /*
1334
1335
    We may be passing the control from mysqld to the client: release the
1335
1336
    InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
1336
 
    by session
 
1337
    by thd
1337
1338
  */
1338
 
  ha_release_temporary_latches(session);
 
1339
  ha_release_temporary_latches(thd);
1339
1340
 
1340
1341
  List_iterator_fast<Item> li(items);
1341
 
  Protocol *protocol= session->protocol;
 
1342
  Protocol *protocol= thd->protocol;
1342
1343
  char buff[MAX_FIELD_WIDTH];
1343
1344
  String buffer(buff, sizeof(buff), &my_charset_bin);
1344
1345
 
1353
1354
      break;
1354
1355
    }
1355
1356
  }
1356
 
  session->sent_row_count++;
1357
 
  if (session->is_error())
 
1357
  thd->sent_row_count++;
 
1358
  if (thd->is_error())
1358
1359
  {
1359
1360
    protocol->remove_last_row();
1360
1361
    return(1);
1361
1362
  }
1362
 
  if (session->vio_ok())
 
1363
  if (thd->vio_ok())
1363
1364
    return(protocol->write());
1364
1365
  return(0);
1365
1366
}
1369
1370
  /* 
1370
1371
    We may be passing the control from mysqld to the client: release the
1371
1372
    InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
1372
 
    by session 
 
1373
    by thd 
1373
1374
  */
1374
 
  ha_release_temporary_latches(session);
 
1375
  ha_release_temporary_latches(thd);
1375
1376
 
1376
1377
  /* Unlock tables before sending packet to gain some speed */
1377
 
  if (session->lock)
 
1378
  if (thd->lock)
1378
1379
  {
1379
 
    mysql_unlock_tables(session, session->lock);
1380
 
    session->lock=0;
 
1380
    mysql_unlock_tables(thd, thd->lock);
 
1381
    thd->lock=0;
1381
1382
  }
1382
 
  ::my_eof(session);
 
1383
  ::my_eof(thd);
1383
1384
  is_result_set_started= 0;
1384
1385
  return false;
1385
1386
}
1389
1390
  Handling writing to file
1390
1391
************************************************************************/
1391
1392
 
1392
 
void select_to_file::send_error(uint32_t errcode,const char *err)
 
1393
void select_to_file::send_error(uint errcode,const char *err)
1393
1394
{
1394
1395
  my_message(errcode, err, MYF(0));
1395
1396
  if (file > 0)
1414
1415
      function, SELECT INTO has to have an own SQLCOM.
1415
1416
      TODO: split from SQLCOM_SELECT
1416
1417
    */
1417
 
    ::my_ok(session,row_count);
 
1418
    ::my_ok(thd,row_count);
1418
1419
  }
1419
1420
  file= -1;
1420
1421
  return error;
1451
1452
 
1452
1453
select_export::~select_export()
1453
1454
{
1454
 
  session->sent_row_count=row_count;
 
1455
  thd->sent_row_count=row_count;
1455
1456
}
1456
1457
 
1457
1458
 
1460
1461
 
1461
1462
  SYNOPSIS
1462
1463
    create_file()
1463
 
    session                     Thread handle
 
1464
    thd                 Thread handle
1464
1465
    path                File name
1465
1466
    exchange            Excange class
1466
1467
    cache               IO cache
1471
1472
*/
1472
1473
 
1473
1474
 
1474
 
static File create_file(Session *session, char *path, sql_exchange *exchange,
 
1475
static File create_file(THD *thd, char *path, sql_exchange *exchange,
1475
1476
                        IO_CACHE *cache)
1476
1477
{
1477
1478
  File file;
1478
 
  uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
 
1479
  uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
1479
1480
 
1480
1481
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
1481
1482
  option|= MY_REPLACE_DIR;                      // Force use of db directory
1483
1484
 
1484
1485
  if (!dirname_length(exchange->file_name))
1485
1486
  {
1486
 
    strcpy(path, mysql_real_data_home);
1487
 
    if (session->db)
1488
 
      strncat(path, session->db, FN_REFLEN-strlen(mysql_real_data_home)-1);
 
1487
    strxnmov(path, FN_REFLEN-1, mysql_real_data_home, thd->db ? thd->db : "",
 
1488
             NullS);
1489
1489
    (void) fn_format(path, exchange->file_name, path, "", option);
1490
1490
  }
1491
1491
  else
1531
1531
  if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN)
1532
1532
    strmake(path,exchange->file_name,FN_REFLEN-1);
1533
1533
 
1534
 
  if ((file= create_file(session, path, exchange, &cache)) < 0)
 
1534
  if ((file= create_file(thd, path, exchange, &cache)) < 0)
1535
1535
    return 1;
1536
1536
  /* Check if there is any blobs in data */
1537
1537
  {
1552
1552
  }
1553
1553
  field_term_length=exchange->field_term->length();
1554
1554
  field_term_char= field_term_length ?
1555
 
                   (int) (unsigned char) (*exchange->field_term)[0] : INT_MAX;
 
1555
                   (int) (uchar) (*exchange->field_term)[0] : INT_MAX;
1556
1556
  if (!exchange->line_term->length())
1557
1557
    exchange->line_term=exchange->field_term;   // Use this if it exists
1558
1558
  field_sep_char= (exchange->enclosed->length() ?
1559
 
                  (int) (unsigned char) (*exchange->enclosed)[0] : field_term_char);
 
1559
                  (int) (uchar) (*exchange->enclosed)[0] : field_term_char);
1560
1560
  escape_char=  (exchange->escaped->length() ?
1561
 
                (int) (unsigned char) (*exchange->escaped)[0] : -1);
 
1561
                (int) (uchar) (*exchange->escaped)[0] : -1);
1562
1562
  is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char));
1563
1563
  is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char));
1564
1564
  line_sep_char= (exchange->line_term->length() ?
1565
 
                 (int) (unsigned char) (*exchange->line_term)[0] : INT_MAX);
 
1565
                 (int) (uchar) (*exchange->line_term)[0] : INT_MAX);
1566
1566
  if (!field_term_length)
1567
1567
    exchange->opt_enclosed=0;
1568
1568
  if (!exchange->enclosed->length())
1574
1574
      (exchange->opt_enclosed && non_string_results &&
1575
1575
       field_term_length && strchr(NUMERIC_CHARS, field_term_char)))
1576
1576
  {
1577
 
    push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1577
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1578
1578
                 ER_AMBIGUOUS_FIELD_TERM, ER(ER_AMBIGUOUS_FIELD_TERM));
1579
1579
    is_ambiguous_field_term= true;
1580
1580
  }
1585
1585
}
1586
1586
 
1587
1587
 
1588
 
#define NEED_ESCAPING(x) ((int) (unsigned char) (x) == escape_char    || \
1589
 
                          (enclosed ? (int) (unsigned char) (x) == field_sep_char      \
1590
 
                                    : (int) (unsigned char) (x) == field_term_char) || \
1591
 
                          (int) (unsigned char) (x) == line_sep_char  || \
 
1588
#define NEED_ESCAPING(x) ((int) (uchar) (x) == escape_char    || \
 
1589
                          (enclosed ? (int) (uchar) (x) == field_sep_char      \
 
1590
                                    : (int) (uchar) (x) == field_term_char) || \
 
1591
                          (int) (uchar) (x) == line_sep_char  || \
1592
1592
                          !(x))
1593
1593
 
1594
1594
bool select_export::send_data(List<Item> &items)
1605
1605
  }
1606
1606
  row_count++;
1607
1607
  Item *item;
1608
 
  uint32_t used_length=0,items_left=items.elements;
 
1608
  uint used_length=0,items_left=items.elements;
1609
1609
  List_iterator_fast<Item> li(items);
1610
1610
 
1611
 
  if (my_b_write(&cache,(unsigned char*) exchange->line_start->ptr(),
 
1611
  if (my_b_write(&cache,(uchar*) exchange->line_start->ptr(),
1612
1612
                 exchange->line_start->length()))
1613
1613
    goto err;
1614
1614
  while ((item=li++))
1619
1619
    res=item->str_result(&tmp);
1620
1620
    if (res && enclosed)
1621
1621
    {
1622
 
      if (my_b_write(&cache,(unsigned char*) exchange->enclosed->ptr(),
 
1622
      if (my_b_write(&cache,(uchar*) exchange->enclosed->ptr(),
1623
1623
                     exchange->enclosed->length()))
1624
1624
        goto err;
1625
1625
    }
1631
1631
        {
1632
1632
          null_buff[0]=escape_char;
1633
1633
          null_buff[1]='N';
1634
 
          if (my_b_write(&cache,(unsigned char*) null_buff,2))
 
1634
          if (my_b_write(&cache,(uchar*) null_buff,2))
1635
1635
            goto err;
1636
1636
        }
1637
 
        else if (my_b_write(&cache,(unsigned char*) "NULL",4))
 
1637
        else if (my_b_write(&cache,(uchar*) "NULL",4))
1638
1638
          goto err;
1639
1639
      }
1640
1640
      else
1645
1645
    else
1646
1646
    {
1647
1647
      if (fixed_row_size)
1648
 
        used_length=cmin(res->length(),item->max_length);
 
1648
        used_length=min(res->length(),item->max_length);
1649
1649
      else
1650
1650
        used_length=res->length();
1651
1651
      if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
1653
1653
      {
1654
1654
        char *pos, *start, *end;
1655
1655
        const CHARSET_INFO * const res_charset= res->charset();
1656
 
        const CHARSET_INFO * const character_set_client= session->variables.
 
1656
        const CHARSET_INFO * const character_set_client= thd->variables.
1657
1657
                                                            character_set_client;
1658
1658
        bool check_second_byte= (res_charset == &my_charset_bin) &&
1659
1659
                                 character_set_client->
1710
1710
 
1711
1711
          if ((NEED_ESCAPING(*pos) ||
1712
1712
               (check_second_byte &&
1713
 
                my_mbcharlen(character_set_client, (unsigned char) *pos) == 2 &&
 
1713
                my_mbcharlen(character_set_client, (uchar) *pos) == 2 &&
1714
1714
                pos + 1 < end &&
1715
1715
                NEED_ESCAPING(pos[1]))) &&
1716
1716
              /*
1718
1718
               valid for ENCLOSED BY characters:
1719
1719
              */
1720
1720
              (enclosed || !is_ambiguous_field_term ||
1721
 
               (int) (unsigned char) *pos != field_term_char))
 
1721
               (int) (uchar) *pos != field_term_char))
1722
1722
          {
1723
1723
            char tmp_buff[2];
1724
 
            tmp_buff[0]= ((int) (unsigned char) *pos == field_sep_char &&
 
1724
            tmp_buff[0]= ((int) (uchar) *pos == field_sep_char &&
1725
1725
                          is_ambiguous_field_sep) ?
1726
1726
                          field_sep_char : escape_char;
1727
1727
            tmp_buff[1]= *pos ? *pos : '0';
1728
 
            if (my_b_write(&cache,(unsigned char*) start,(uint) (pos-start)) ||
1729
 
                my_b_write(&cache,(unsigned char*) tmp_buff,2))
 
1728
            if (my_b_write(&cache,(uchar*) start,(uint) (pos-start)) ||
 
1729
                my_b_write(&cache,(uchar*) tmp_buff,2))
1730
1730
              goto err;
1731
1731
            start=pos+1;
1732
1732
          }
1733
1733
        }
1734
 
        if (my_b_write(&cache,(unsigned char*) start,(uint) (pos-start)))
 
1734
        if (my_b_write(&cache,(uchar*) start,(uint) (pos-start)))
1735
1735
          goto err;
1736
1736
      }
1737
 
      else if (my_b_write(&cache,(unsigned char*) res->ptr(),used_length))
 
1737
      else if (my_b_write(&cache,(uchar*) res->ptr(),used_length))
1738
1738
        goto err;
1739
1739
    }
1740
1740
    if (fixed_row_size)
1747
1747
          space_inited=1;
1748
1748
          memset(space, ' ', sizeof(space));
1749
1749
        }
1750
 
        uint32_t length=item->max_length-used_length;
 
1750
        uint length=item->max_length-used_length;
1751
1751
        for (; length > sizeof(space) ; length-=sizeof(space))
1752
1752
        {
1753
 
          if (my_b_write(&cache,(unsigned char*) space,sizeof(space)))
 
1753
          if (my_b_write(&cache,(uchar*) space,sizeof(space)))
1754
1754
            goto err;
1755
1755
        }
1756
 
        if (my_b_write(&cache,(unsigned char*) space,length))
 
1756
        if (my_b_write(&cache,(uchar*) space,length))
1757
1757
          goto err;
1758
1758
      }
1759
1759
    }
1760
1760
    if (res && enclosed)
1761
1761
    {
1762
 
      if (my_b_write(&cache, (unsigned char*) exchange->enclosed->ptr(),
 
1762
      if (my_b_write(&cache, (uchar*) exchange->enclosed->ptr(),
1763
1763
                     exchange->enclosed->length()))
1764
1764
        goto err;
1765
1765
    }
1766
1766
    if (--items_left)
1767
1767
    {
1768
 
      if (my_b_write(&cache, (unsigned char*) exchange->field_term->ptr(),
 
1768
      if (my_b_write(&cache, (uchar*) exchange->field_term->ptr(),
1769
1769
                     field_term_length))
1770
1770
        goto err;
1771
1771
    }
1772
1772
  }
1773
 
  if (my_b_write(&cache,(unsigned char*) exchange->line_term->ptr(),
 
1773
  if (my_b_write(&cache,(uchar*) exchange->line_term->ptr(),
1774
1774
                 exchange->line_term->length()))
1775
1775
    goto err;
1776
1776
  return(0);
1789
1789
                     SELECT_LEX_UNIT *u)
1790
1790
{
1791
1791
  unit= u;
1792
 
  return (int) ((file= create_file(session, path, exchange, &cache)) < 0);
 
1792
  return (int) ((file= create_file(thd, path, exchange, &cache)) < 0);
1793
1793
}
1794
1794
 
1795
1795
 
1816
1816
    res=item->str_result(&tmp);
1817
1817
    if (!res)                                   // If NULL
1818
1818
    {
1819
 
      if (my_b_write(&cache,(unsigned char*) "",1))
 
1819
      if (my_b_write(&cache,(uchar*) "",1))
1820
1820
        goto err;
1821
1821
    }
1822
 
    else if (my_b_write(&cache,(unsigned char*) res->ptr(),res->length()))
 
1822
    else if (my_b_write(&cache,(uchar*) res->ptr(),res->length()))
1823
1823
    {
1824
1824
      my_error(ER_ERROR_ON_WRITE, MYF(0), path, my_errno);
1825
1825
      goto err;
1852
1852
  }
1853
1853
  List_iterator_fast<Item> li(items);
1854
1854
  Item *val_item;
1855
 
  for (uint32_t i= 0; (val_item= li++); i++)
 
1855
  for (uint i= 0; (val_item= li++); i++)
1856
1856
    it->store(i, val_item);
1857
1857
  it->assigned(1);
1858
1858
  return(0);
2028
2028
}
2029
2029
 
2030
2030
 
 
2031
void Query_arena::set_query_arena(Query_arena *set)
 
2032
{
 
2033
  mem_root= set->mem_root;
 
2034
  free_list= set->free_list;
 
2035
  state= set->state;
 
2036
}
 
2037
 
 
2038
 
 
2039
void Query_arena::cleanup_stmt()
 
2040
{
 
2041
  assert("not implemented");
 
2042
}
 
2043
 
2031
2044
/*
2032
2045
  Statement functions
2033
2046
*/
2034
2047
 
2035
 
Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg)
2036
 
  :Query_arena(mem_root_arg),
 
2048
Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
 
2049
                     enum enum_state state_arg, ulong id_arg)
 
2050
  :Query_arena(mem_root_arg, state_arg),
2037
2051
  id(id_arg),
2038
2052
  mark_used_columns(MARK_COLUMNS_READ),
2039
2053
  lex(lex_arg),
2042
2056
  db(NULL),
2043
2057
  db_length(0)
2044
2058
{
2045
 
}
2046
 
 
2047
 
 
2048
 
/*
2049
 
  Don't free mem_root, as mem_root is freed in the end of dispatch_command
2050
 
  (once for any command).
2051
 
*/
2052
 
void Session::end_statement()
 
2059
  name.str= NULL;
 
2060
}
 
2061
 
 
2062
 
 
2063
void Statement::set_statement(Statement *stmt)
 
2064
{
 
2065
  id=             stmt->id;
 
2066
  mark_used_columns=   stmt->mark_used_columns;
 
2067
  lex=            stmt->lex;
 
2068
  query=          stmt->query;
 
2069
  query_length=   stmt->query_length;
 
2070
}
 
2071
 
 
2072
 
 
2073
void
 
2074
Statement::set_n_backup_statement(Statement *stmt, Statement *backup)
 
2075
{
 
2076
  backup->set_statement(this);
 
2077
  set_statement(stmt);
 
2078
  return;
 
2079
}
 
2080
 
 
2081
 
 
2082
void Statement::restore_backup_statement(Statement *stmt, Statement *backup)
 
2083
{
 
2084
  stmt->set_statement(this);
 
2085
  set_statement(backup);
 
2086
  return;
 
2087
}
 
2088
 
 
2089
 
 
2090
void THD::end_statement()
2053
2091
{
2054
2092
  /* Cleanup SQL processing state to reuse this statement in next query. */
2055
2093
  lex_end(lex);
2056
 
}
2057
 
 
2058
 
 
2059
 
bool Session::copy_db_to(char **p_db, size_t *p_db_length)
 
2094
  delete lex->result;
 
2095
  lex->result= 0;
 
2096
  /* Note that free_list is freed in cleanup_after_query() */
 
2097
 
 
2098
  /*
 
2099
    Don't free mem_root, as mem_root is freed in the end of dispatch_command
 
2100
    (once for any command).
 
2101
  */
 
2102
}
 
2103
 
 
2104
 
 
2105
void THD::set_n_backup_active_arena(Query_arena *set, Query_arena *backup)
 
2106
{
 
2107
  assert(backup->is_backup_arena == false);
 
2108
 
 
2109
  backup->set_query_arena(this);
 
2110
  set_query_arena(set);
 
2111
  backup->is_backup_arena= true;
 
2112
  return;
 
2113
}
 
2114
 
 
2115
 
 
2116
void THD::restore_active_arena(Query_arena *set, Query_arena *backup)
 
2117
{
 
2118
  assert(backup->is_backup_arena);
 
2119
  set->set_query_arena(this);
 
2120
  set_query_arena(backup);
 
2121
  backup->is_backup_arena= false;
 
2122
  return;
 
2123
}
 
2124
 
 
2125
 
 
2126
bool THD::copy_db_to(char **p_db, size_t *p_db_length)
2060
2127
{
2061
2128
  if (db == NULL)
2062
2129
  {
2091
2158
    if (mv->local == 0)
2092
2159
    {
2093
2160
      Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item);
2094
 
      suv->fix_fields(session, 0);
 
2161
      suv->fix_fields(thd, 0);
2095
2162
      suv->check(0);
2096
2163
      suv->update();
2097
2164
    }
2098
2165
  }
2099
 
  return(session->is_error());
 
2166
  return(thd->is_error());
2100
2167
}
2101
2168
 
2102
2169
bool select_dumpvar::send_eof()
2103
2170
{
2104
2171
  if (! row_count)
2105
 
    push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2172
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2106
2173
                 ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA));
2107
2174
  /*
2108
2175
    In order to remember the value of affected rows for ROW_COUNT()
2109
2176
    function, SELECT INTO has to have an own SQLCOM.
2110
2177
    TODO: split from SQLCOM_SELECT
2111
2178
  */
2112
 
  ::my_ok(session,row_count);
 
2179
  ::my_ok(thd,row_count);
2113
2180
  return 0;
2114
2181
}
2115
2182
 
2129
2196
}
2130
2197
 
2131
2198
 
2132
 
void session_increment_bytes_sent(ulong length)
 
2199
void thd_increment_bytes_sent(ulong length)
2133
2200
{
2134
 
  Session *session=current_session;
2135
 
  if (likely(session != 0))
2136
 
  { /* current_session==0 when close_connection() calls net_send_error() */
2137
 
    session->status_var.bytes_sent+= length;
 
2201
  THD *thd=current_thd;
 
2202
  if (likely(thd != 0))
 
2203
  { /* current_thd==0 when close_connection() calls net_send_error() */
 
2204
    thd->status_var.bytes_sent+= length;
2138
2205
  }
2139
2206
}
2140
2207
 
2141
2208
 
2142
 
void session_increment_bytes_received(ulong length)
2143
 
{
2144
 
  current_session->status_var.bytes_received+= length;
2145
 
}
2146
 
 
2147
 
 
2148
 
void session_increment_net_big_packet_count(ulong length)
2149
 
{
2150
 
  current_session->status_var.net_big_packet_count+= length;
2151
 
}
2152
 
 
2153
 
void Session::send_kill_message() const
 
2209
void thd_increment_bytes_received(ulong length)
 
2210
{
 
2211
  current_thd->status_var.bytes_received+= length;
 
2212
}
 
2213
 
 
2214
 
 
2215
void thd_increment_net_big_packet_count(ulong length)
 
2216
{
 
2217
  current_thd->status_var.net_big_packet_count+= length;
 
2218
}
 
2219
 
 
2220
void THD::send_kill_message() const
2154
2221
{
2155
2222
  int err= killed_errno();
2156
2223
  if (err)
2157
2224
    my_message(err, ER(err), MYF(0));
2158
2225
}
2159
2226
 
2160
 
void Session::set_status_var_init()
 
2227
void THD::set_status_var_init()
2161
2228
{
2162
2229
  memset(&status_var, 0, sizeof(status_var));
2163
2230
}
2172
2239
void Security_context::destroy()
2173
2240
{
2174
2241
  // If not pointer to constant
2175
 
  if (user)
2176
 
  {
2177
 
    free(user);
2178
 
    user= NULL;
2179
 
  }
2180
 
  if (ip)
2181
 
  {
2182
 
    free(ip);
2183
 
    ip= NULL;
2184
 
  }
 
2242
  safeFree(user);
 
2243
  safeFree(ip);
2185
2244
}
2186
2245
 
2187
2246
 
2199
2258
  access to mysql.proc table to find definitions of stored routines.
2200
2259
****************************************************************************/
2201
2260
 
2202
 
void Session::reset_n_backup_open_tables_state(Open_tables_state *backup)
 
2261
void THD::reset_n_backup_open_tables_state(Open_tables_state *backup)
2203
2262
{
2204
2263
  backup->set_open_tables_state(this);
2205
2264
  reset_open_tables_state();
2208
2267
}
2209
2268
 
2210
2269
 
2211
 
void Session::restore_backup_open_tables_state(Open_tables_state *backup)
 
2270
void THD::restore_backup_open_tables_state(Open_tables_state *backup)
2212
2271
{
2213
2272
  /*
2214
2273
    Before we will throw away current open tables state we want
2223
2282
 
2224
2283
/**
2225
2284
  Check the killed state of a user thread
2226
 
  @param session  user thread
 
2285
  @param thd  user thread
2227
2286
  @retval 0 the user thread is active
2228
2287
  @retval 1 the user thread has been killed
2229
2288
*/
2230
 
extern "C" int session_killed(const Session *session)
 
2289
extern "C" int thd_killed(const DRIZZLE_THD thd)
2231
2290
{
2232
 
  return(session->killed);
 
2291
  return(thd->killed);
2233
2292
}
2234
2293
 
2235
2294
/**
2236
2295
  Return the thread id of a user thread
2237
 
  @param session user thread
 
2296
  @param thd user thread
2238
2297
  @return thread id
2239
2298
*/
2240
 
extern "C" unsigned long session_get_thread_id(const Session *session)
2241
 
{
2242
 
  return((unsigned long)session->thread_id);
2243
 
}
2244
 
 
2245
 
 
2246
 
extern "C"
2247
 
LEX_STRING *session_make_lex_string(Session *session, LEX_STRING *lex_str,
2248
 
                                const char *str, unsigned int size,
2249
 
                                int allocate_lex_string)
2250
 
{
2251
 
  return session->make_lex_string(lex_str, str, size,
2252
 
                              (bool) allocate_lex_string);
2253
 
}
2254
 
 
2255
 
extern "C" const struct charset_info_st *session_charset(Session *session)
2256
 
{
2257
 
  return(session->charset());
2258
 
}
2259
 
 
2260
 
extern "C" char **session_query(Session *session)
2261
 
{
2262
 
  return(&session->query);
2263
 
}
2264
 
 
2265
 
extern "C" int session_slave_thread(const Session *session)
2266
 
{
2267
 
  return(session->slave_thread);
2268
 
}
2269
 
 
2270
 
extern "C" int session_non_transactional_update(const Session *session)
2271
 
{
2272
 
  return(session->transaction.all.modified_non_trans_table);
2273
 
}
2274
 
 
2275
 
extern "C" int session_binlog_format(const Session *session)
2276
 
{
2277
 
  return (int) session->variables.binlog_format;
2278
 
}
2279
 
 
2280
 
extern "C" void session_mark_transaction_to_rollback(Session *session, bool all)
2281
 
{
2282
 
  mark_transaction_to_rollback(session, all);
2283
 
}
 
2299
extern "C" unsigned long thd_get_thread_id(const DRIZZLE_THD thd)
 
2300
{
 
2301
  return((unsigned long)thd->thread_id);
 
2302
}
 
2303
 
 
2304
 
 
2305
#ifdef INNODB_COMPATIBILITY_HOOKS
 
2306
extern "C" const struct charset_info_st *thd_charset(DRIZZLE_THD thd)
 
2307
{
 
2308
  return(thd->charset());
 
2309
}
 
2310
 
 
2311
extern "C" char **thd_query(DRIZZLE_THD thd)
 
2312
{
 
2313
  return(&thd->query);
 
2314
}
 
2315
 
 
2316
extern "C" int thd_slave_thread(const DRIZZLE_THD thd)
 
2317
{
 
2318
  return(thd->slave_thread);
 
2319
}
 
2320
 
 
2321
extern "C" int thd_non_transactional_update(const DRIZZLE_THD thd)
 
2322
{
 
2323
  return(thd->transaction.all.modified_non_trans_table);
 
2324
}
 
2325
 
 
2326
extern "C" int thd_binlog_format(const DRIZZLE_THD thd)
 
2327
{
 
2328
  return (int) thd->variables.binlog_format;
 
2329
}
 
2330
 
 
2331
extern "C" void thd_mark_transaction_to_rollback(DRIZZLE_THD thd, bool all)
 
2332
{
 
2333
  mark_transaction_to_rollback(thd, all);
 
2334
}
 
2335
#endif // INNODB_COMPATIBILITY_HOOKS */
2284
2336
 
2285
2337
 
2286
2338
/**
2287
2339
  Mark transaction to rollback and mark error as fatal to a sub-statement.
2288
2340
 
2289
 
  @param  session   Thread handle
 
2341
  @param  thd   Thread handle
2290
2342
  @param  all   true <=> rollback main transaction.
2291
2343
*/
2292
2344
 
2293
 
void mark_transaction_to_rollback(Session *session, bool all)
 
2345
void mark_transaction_to_rollback(THD *thd, bool all)
2294
2346
{
2295
 
  if (session)
 
2347
  if (thd)
2296
2348
  {
2297
 
    session->is_fatal_sub_stmt_error= true;
2298
 
    session->transaction_rollback_request= all;
 
2349
    thd->is_fatal_sub_stmt_error= true;
 
2350
    thd->transaction_rollback_request= all;
2299
2351
  }
2300
2352
}
2301
2353
/***************************************************************************
2305
2357
pthread_mutex_t LOCK_xid_cache;
2306
2358
HASH xid_cache;
2307
2359
 
2308
 
extern "C" unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
 
2360
extern "C" uchar *xid_get_hash_key(const uchar *, size_t *, bool);
2309
2361
extern "C" void xid_free_hash(void *);
2310
2362
 
2311
 
unsigned char *xid_get_hash_key(const unsigned char *ptr, size_t *length,
 
2363
uchar *xid_get_hash_key(const uchar *ptr, size_t *length,
2312
2364
                        bool not_used __attribute__((unused)))
2313
2365
{
2314
2366
  *length=((XID_STATE*)ptr)->xid.key_length();
2317
2369
 
2318
2370
void xid_free_hash(void *ptr)
2319
2371
{
2320
 
  if (!((XID_STATE*)ptr)->in_session)
2321
 
    free((unsigned char*)ptr);
 
2372
  if (!((XID_STATE*)ptr)->in_thd)
 
2373
    my_free((uchar*)ptr, MYF(0));
2322
2374
}
2323
2375
 
2324
2376
bool xid_cache_init()
2359
2411
  {
2360
2412
    xs->xa_state=xa_state;
2361
2413
    xs->xid.set(xid);
2362
 
    xs->in_session=0;
2363
 
    res=my_hash_insert(&xid_cache, (unsigned char*)xs);
 
2414
    xs->in_thd=0;
 
2415
    res=my_hash_insert(&xid_cache, (uchar*)xs);
2364
2416
  }
2365
2417
  pthread_mutex_unlock(&LOCK_xid_cache);
2366
2418
  return res;
2372
2424
  pthread_mutex_lock(&LOCK_xid_cache);
2373
2425
  assert(hash_search(&xid_cache, xid_state->xid.key(),
2374
2426
                          xid_state->xid.key_length())==0);
2375
 
  bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
 
2427
  bool res=my_hash_insert(&xid_cache, (uchar*)xid_state);
2376
2428
  pthread_mutex_unlock(&LOCK_xid_cache);
2377
2429
  return res;
2378
2430
}
2381
2433
void xid_cache_delete(XID_STATE *xid_state)
2382
2434
{
2383
2435
  pthread_mutex_lock(&LOCK_xid_cache);
2384
 
  hash_delete(&xid_cache, (unsigned char *)xid_state);
 
2436
  hash_delete(&xid_cache, (uchar *)xid_state);
2385
2437
  pthread_mutex_unlock(&LOCK_xid_cache);
2386
2438
}
2387
2439
 
2391
2443
  inserted/updated/deleted.
2392
2444
*/
2393
2445
 
 
2446
#ifndef DRIZZLE_CLIENT
2394
2447
 
2395
2448
/*
2396
2449
  Template member function for ensuring that there is an rows log
2400
2453
    - Events of type 'RowEventT' have the type code 'type_code'.
2401
2454
    
2402
2455
  POST CONDITION:
2403
 
    If a non-NULL pointer is returned, the pending event for thread 'session' will
 
2456
    If a non-NULL pointer is returned, the pending event for thread 'thd' will
2404
2457
    be an event of type 'RowEventT' (which have the type code 'type_code')
2405
2458
    will either empty or have enough space to hold 'needed' bytes.  In
2406
2459
    addition, the columns bitmap will be correct for the row, meaning that
2414
2467
 */
2415
2468
 
2416
2469
template <class RowsEventT> Rows_log_event* 
2417
 
Session::binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
 
2470
THD::binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
2418
2471
                                       size_t needed,
2419
2472
                                       bool is_transactional,
2420
2473
                                       RowsEventT *hint __attribute__((unused)))
2490
2543
  compiling option.
2491
2544
*/
2492
2545
template Rows_log_event*
2493
 
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
 
2546
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2494
2547
                                       Write_rows_log_event*);
2495
2548
 
2496
2549
template Rows_log_event*
2497
 
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
 
2550
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2498
2551
                                       Delete_rows_log_event *);
2499
2552
 
2500
2553
template Rows_log_event* 
2501
 
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
 
2554
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2502
2555
                                       Update_rows_log_event *);
2503
2556
#endif
2504
2557
 
2551
2604
    ~Row_data_memory()
2552
2605
    {
2553
2606
      if (m_memory != 0 && m_release_memory_on_destruction)
2554
 
        free((unsigned char*) m_memory);
 
2607
        my_free((uchar*) m_memory, MYF(MY_WME));
2555
2608
    }
2556
2609
 
2557
2610
    /**
2565
2618
      return m_memory != 0;
2566
2619
    }
2567
2620
 
2568
 
    unsigned char *slot(uint32_t s)
 
2621
    uchar *slot(uint s)
2569
2622
    {
2570
2623
      assert(s < sizeof(m_ptr)/sizeof(*m_ptr));
2571
2624
      assert(m_ptr[s] != 0);
2597
2650
        */
2598
2651
        if (table->write_row_record == 0)
2599
2652
          table->write_row_record=
2600
 
            (unsigned char *) alloc_root(&table->mem_root, 2 * maxlen);
 
2653
            (uchar *) alloc_root(&table->mem_root, 2 * maxlen);
2601
2654
        m_memory= table->write_row_record;
2602
2655
        m_release_memory_on_destruction= false;
2603
2656
      }
2604
2657
      else
2605
2658
      {
2606
 
        m_memory= (unsigned char *) my_malloc(total_length, MYF(MY_WME));
 
2659
        m_memory= (uchar *) my_malloc(total_length, MYF(MY_WME));
2607
2660
        m_release_memory_on_destruction= true;
2608
2661
      }
2609
2662
    }
2610
2663
 
2611
2664
    mutable bool m_alloc_checked;
2612
2665
    bool m_release_memory_on_destruction;
2613
 
    unsigned char *m_memory;
2614
 
    unsigned char *m_ptr[2];
 
2666
    uchar *m_memory;
 
2667
    uchar *m_ptr[2];
2615
2668
  };
2616
2669
}
2617
2670
 
2618
2671
 
2619
 
int Session::binlog_write_row(Table* table, bool is_trans, 
2620
 
                          unsigned char const *record) 
 
2672
int THD::binlog_write_row(Table* table, bool is_trans, 
 
2673
                          uchar const *record) 
2621
2674
2622
2675
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2623
2676
 
2629
2682
  if (!memory.has_memory())
2630
2683
    return HA_ERR_OUT_OF_MEM;
2631
2684
 
2632
 
  unsigned char *row_data= memory.slot(0);
 
2685
  uchar *row_data= memory.slot(0);
2633
2686
 
2634
2687
  size_t const len= pack_row(table, table->write_set, row_data, record);
2635
2688
 
2643
2696
  return ev->add_row_data(row_data, len);
2644
2697
}
2645
2698
 
2646
 
int Session::binlog_update_row(Table* table, bool is_trans,
2647
 
                           const unsigned char *before_record,
2648
 
                           const unsigned char *after_record)
 
2699
int THD::binlog_update_row(Table* table, bool is_trans,
 
2700
                           const uchar *before_record,
 
2701
                           const uchar *after_record)
2649
2702
2650
2703
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2651
2704
 
2656
2709
  if (!row_data.has_memory())
2657
2710
    return HA_ERR_OUT_OF_MEM;
2658
2711
 
2659
 
  unsigned char *before_row= row_data.slot(0);
2660
 
  unsigned char *after_row= row_data.slot(1);
 
2712
  uchar *before_row= row_data.slot(0);
 
2713
  uchar *after_row= row_data.slot(1);
2661
2714
 
2662
2715
  size_t const before_size= pack_row(table, table->read_set, before_row,
2663
2716
                                        before_record);
2677
2730
    ev->add_row_data(after_row, after_size);
2678
2731
}
2679
2732
 
2680
 
int Session::binlog_delete_row(Table* table, bool is_trans, 
2681
 
                           unsigned char const *record)
 
2733
int THD::binlog_delete_row(Table* table, bool is_trans, 
 
2734
                           uchar const *record)
2682
2735
2683
2736
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2684
2737
 
2690
2743
  if (unlikely(!memory.has_memory()))
2691
2744
    return HA_ERR_OUT_OF_MEM;
2692
2745
 
2693
 
  unsigned char *row_data= memory.slot(0);
 
2746
  uchar *row_data= memory.slot(0);
2694
2747
 
2695
2748
  size_t const len= pack_row(table, table->read_set, row_data, record);
2696
2749
 
2705
2758
}
2706
2759
 
2707
2760
 
2708
 
int Session::binlog_flush_pending_rows_event(bool stmt_end)
 
2761
int THD::binlog_flush_pending_rows_event(bool stmt_end)
2709
2762
{
2710
2763
  /*
2711
2764
    We shall flush the pending event even if we are not in row-based
2759
2812
  RETURN VALUE
2760
2813
    Error code, or 0 if no error.
2761
2814
*/
2762
 
int Session::binlog_query(Session::enum_binlog_query_type qtype, char const *query_arg,
 
2815
int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
2763
2816
                      ulong query_len, bool is_trans, bool suppress_use,
2764
 
                      Session::killed_state killed_status_arg)
 
2817
                      THD::killed_state killed_status_arg)
2765
2818
{
2766
2819
  assert(query_arg && mysql_bin_log.is_open());
2767
2820
 
2784
2837
      char warn_buf[DRIZZLE_ERRMSG_SIZE];
2785
2838
      snprintf(warn_buf, DRIZZLE_ERRMSG_SIZE, "%s Statement: %s",
2786
2839
               ER(ER_BINLOG_UNSAFE_STATEMENT), this->query);
2787
 
      sql_print_warning("%s",warn_buf);
 
2840
      sql_print_warning(warn_buf);
2788
2841
      binlog_flags|= BINLOG_FLAG_UNSAFE_STMT_PRINTED;
2789
2842
    }
2790
2843
  }
2791
2844
 
2792
2845
  switch (qtype) {
2793
 
  case Session::ROW_QUERY_TYPE:
 
2846
  case THD::ROW_QUERY_TYPE:
2794
2847
    if (current_stmt_binlog_row_based)
2795
2848
      return(0);
2796
2849
    /* Otherwise, we fall through */
2797
 
  case Session::DRIZZLE_QUERY_TYPE:
 
2850
  case THD::DRIZZLE_QUERY_TYPE:
2798
2851
    /*
2799
2852
      Using this query type is a conveniece hack, since we have been
2800
2853
      moving back and forth between using RBR for replication of
2803
2856
      Make sure to change in check_table_binlog_row_based() according
2804
2857
      to how you treat this.
2805
2858
    */
2806
 
  case Session::STMT_QUERY_TYPE:
 
2859
  case THD::STMT_QUERY_TYPE:
2807
2860
    /*
2808
2861
      The DRIZZLE_LOG::write() function will set the STMT_END_F flag and
2809
2862
      flush the pending rows event if necessary.
2824
2877
    }
2825
2878
    break;
2826
2879
 
2827
 
  case Session::QUERY_TYPE_COUNT:
 
2880
  case THD::QUERY_TYPE_COUNT:
2828
2881
  default:
2829
2882
    assert(0 <= qtype && qtype < QUERY_TYPE_COUNT);
2830
2883
  }
2856
2909
  elements++;
2857
2910
  return(0);
2858
2911
}
 
2912
 
 
2913
#endif /* !defined(DRIZZLE_CLIENT) */