~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_class.cc

  • Committer: Brian Aker
  • Date: 2008-08-12 03:12:57 UTC
  • Revision ID: brian@tangent.org-20080812031257-ln3uk87y1r22byeg
First pass of new sql_db.cc work

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
** User variables
60
60
****************************************************************************/
61
61
 
62
 
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,
63
63
                              bool not_used __attribute__((unused)))
64
64
{
65
65
  *length= entry->name.length;
66
 
  return (unsigned char*) entry->name.str;
 
66
  return (uchar*) entry->name.str;
67
67
}
68
68
 
69
69
extern "C" void free_user_var(user_var_entry *entry)
70
70
{
71
71
  char *pos= (char*) entry+ALIGN_SIZE(sizeof(*entry));
72
72
  if (entry->value && entry->value != pos)
73
 
    free(entry->value);
74
 
  free((char*) entry);
 
73
    my_free(entry->value, MYF(0));
 
74
  my_free((char*) entry,MYF(0));
75
75
}
76
76
 
77
77
bool Key_part_spec::operator==(const Key_part_spec& other) const
137
137
  if (a->generated)
138
138
  {
139
139
    if (b->generated && a->columns.elements > b->columns.elements)
140
 
      std::swap(a, b);                       // Put shorter key in 'a'
 
140
      swap_variables(Key*, a, b);               // Put shorter key in 'a'
141
141
  }
142
142
  else
143
143
  {
144
144
    if (!b->generated)
145
145
      return true;                              // No foreign key
146
 
    std::swap(a, b);                       // Put generated key in 'a'
 
146
    swap_variables(Key*, a, b);                 // Put generated key in 'a'
147
147
  }
148
148
 
149
149
  /* Test if 'a' is a prefix of 'b' */
236
236
                              const char *calling_file __attribute__((unused)),
237
237
                              const unsigned int calling_line __attribute__((unused)))
238
238
{
239
 
  const char *old_info= thd->get_proc_info();
240
 
  thd->set_proc_info(info);
 
239
  const char *old_info= thd->proc_info;
 
240
  thd->proc_info= info;
241
241
  return old_info;
242
242
}
243
243
 
359
359
 
360
360
void
361
361
Diagnostics_area::set_error_status(THD *thd __attribute__((unused)),
362
 
                                   uint32_t sql_errno_arg,
 
362
                                   uint sql_errno_arg,
363
363
                                   const char *message_arg)
364
364
{
365
365
  /*
399
399
 
400
400
 
401
401
THD::THD()
402
 
   :Statement(&main_lex, &main_mem_root,
 
402
   :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION,
403
403
              /* statement id */ 0),
404
404
   Open_tables_state(refresh_version), rli_fake(0),
405
405
   lock_id(&main_lock_id),
429
429
    will be re-initialized in init_for_queries().
430
430
  */
431
431
  init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
 
432
  stmt_arena= this;
432
433
  thread_stack= 0;
433
434
  catalog= (char*)"std"; // the only catalog we have for now
434
435
  main_security_ctx.init();
463
464
  memset(ha_data, 0, sizeof(ha_data));
464
465
  mysys_var=0;
465
466
  binlog_evt_union.do_union= false;
 
467
  enable_slow_log= 0;
466
468
  dbug_sentry=THD_SENTRY_MAGIC;
467
469
  net.vio=0;
468
470
  client_capabilities= 0;                       // minimalistic client
471
473
  peer_port= 0;                                 // For SHOW PROCESSLIST
472
474
  transaction.m_pending_rows_event= 0;
473
475
  transaction.on= 1;
 
476
#ifdef SIGNAL_WITH_VIO_CLOSE
 
477
  active_vio = 0;
 
478
#endif
474
479
  pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
475
480
 
476
481
  /* Variables with default values */
522
527
}
523
528
 
524
529
 
525
 
bool THD::handle_error(uint32_t sql_errno, const char *message,
 
530
bool THD::handle_error(uint sql_errno, const char *message,
526
531
                       DRIZZLE_ERROR::enum_warning_level level)
527
532
{
528
533
  if (m_internal_handler)
541
546
}
542
547
 
543
548
extern "C"
544
 
void *thd_alloc(DRIZZLE_THD thd, unsigned int size)
 
549
void *thd_alloc(MYSQL_THD thd, unsigned int size)
545
550
{
546
551
  return thd->alloc(size);
547
552
}
548
553
 
549
554
extern "C"
550
 
void *thd_calloc(DRIZZLE_THD thd, unsigned int size)
 
555
void *thd_calloc(MYSQL_THD thd, unsigned int size)
551
556
{
552
557
  return thd->calloc(size);
553
558
}
554
559
 
555
560
extern "C"
556
 
char *thd_strdup(DRIZZLE_THD thd, const char *str)
 
561
char *thd_strdup(MYSQL_THD thd, const char *str)
557
562
{
558
563
  return thd->strdup(str);
559
564
}
560
565
 
561
566
extern "C"
562
 
char *thd_strmake(DRIZZLE_THD thd, const char *str, unsigned int size)
 
567
char *thd_strmake(MYSQL_THD thd, const char *str, unsigned int size)
563
568
{
564
569
  return thd->strmake(str, size);
565
570
}
574
579
}
575
580
 
576
581
extern "C"
577
 
void *thd_memdup(DRIZZLE_THD thd, const void* str, unsigned int size)
 
582
void *thd_memdup(MYSQL_THD thd, const void* str, unsigned int size)
578
583
{
579
584
  return thd->memdup(str, size);
580
585
}
581
586
 
582
587
extern "C"
583
 
void thd_get_xid(const DRIZZLE_THD thd, DRIZZLE_XID *xid)
 
588
void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid)
584
589
{
585
 
  *xid = *(DRIZZLE_XID *) &thd->transaction.xid_state.xid;
 
590
  *xid = *(MYSQL_XID *) &thd->transaction.xid_state.xid;
586
591
}
587
592
 
588
593
/*
676
681
  delete_dynamic(&user_var_events);
677
682
  hash_free(&user_vars);
678
683
  close_temporary_tables(this);
679
 
  free((char*) variables.time_format);
680
 
  free((char*) variables.date_format);
681
 
  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));
682
687
  
683
688
  if (global_read_lock)
684
689
    unlock_global_read_lock(this);
698
703
  /* Close connection */
699
704
  if (net.vio)
700
705
  {
701
 
    net_close(&net);
 
706
    vio_delete(net.vio);
702
707
    net_end(&net);
703
708
  }
704
709
  if (!cleanup_done)
708
713
  plugin_thdvar_cleanup(this);
709
714
 
710
715
  main_security_ctx.destroy();
711
 
  if (db)
712
 
  {
713
 
    free(db);
714
 
    db= NULL;
715
 
  }
 
716
  safeFree(db);
716
717
  free_root(&warn_root,MYF(0));
717
718
  free_root(&transaction.mem_root,MYF(0));
718
719
  mysys_var=0;                                  // Safety (shouldn't be needed)
745
746
 
746
747
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
747
748
{
748
 
  ulong *end= (ulong*) ((unsigned char*) to_var +
 
749
  ulong *end= (ulong*) ((uchar*) to_var +
749
750
                        offsetof(STATUS_VAR, last_system_status_var) +
750
751
                        sizeof(ulong));
751
752
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var;
770
771
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
771
772
                        STATUS_VAR *dec_var)
772
773
{
773
 
  ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(STATUS_VAR,
 
774
  ulong *end= (ulong*) ((uchar*) to_var + offsetof(STATUS_VAR,
774
775
                                                  last_system_status_var) +
775
776
                        sizeof(ulong));
776
777
  ulong *to= (ulong*) to_var, *from= (ulong*) from_var, *dec= (ulong*) dec_var;
791
792
    thr_alarm_kill(thread_id);
792
793
    if (!slave_thread)
793
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    
794
811
  }
795
812
  if (mysys_var)
796
813
  {
922
939
  @return  NULL on failure, or pointer to the LEX_STRING object
923
940
*/
924
941
LEX_STRING *THD::make_lex_string(LEX_STRING *lex_str,
925
 
                                 const char* str, uint32_t length,
 
942
                                 const char* str, uint length,
926
943
                                 bool allocate_lex_string)
927
944
{
928
945
  if (allocate_lex_string)
956
973
*/
957
974
 
958
975
bool THD::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
959
 
                         const char *from, uint32_t from_length,
 
976
                         const char *from, uint from_length,
960
977
                         const CHARSET_INFO * const from_cs)
961
978
{
962
979
  size_t new_length= to_cs->mbmaxlen * from_length;
963
 
  uint32_t dummy_errors;
 
980
  uint dummy_errors;
964
981
  if (!(to->str= (char*) alloc(new_length+1)))
965
982
  {
966
983
    to->length= 0;                              // Safety fix
991
1008
bool THD::convert_string(String *s, const CHARSET_INFO * const from_cs,
992
1009
                         const CHARSET_INFO * const to_cs)
993
1010
{
994
 
  uint32_t dummy_errors;
 
1011
  uint dummy_errors;
995
1012
  if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
996
1013
    return true;
997
1014
  /* If convert_buffer >> s copying is more efficient long term */
1026
1043
 
1027
1044
/* routings to adding tables to list of changed in transaction tables */
1028
1045
 
1029
 
inline static void list_include(CHANGED_TableList** prev,
1030
 
                                CHANGED_TableList* curr,
1031
 
                                CHANGED_TableList* new_table)
 
1046
inline static void list_include(CHANGED_TABLE_LIST** prev,
 
1047
                                CHANGED_TABLE_LIST* curr,
 
1048
                                CHANGED_TABLE_LIST* new_table)
1032
1049
{
1033
1050
  if (new_table)
1034
1051
  {
1039
1056
 
1040
1057
/* add table to list of changed in transaction tables */
1041
1058
 
1042
 
void THD::add_changed_table(Table *table)
 
1059
void THD::add_changed_table(TABLE *table)
1043
1060
{
1044
1061
  assert((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
1045
1062
              table->file->has_transactions());
1051
1068
 
1052
1069
void THD::add_changed_table(const char *key, long key_length)
1053
1070
{
1054
 
  CHANGED_TableList **prev_changed = &transaction.changed_tables;
1055
 
  CHANGED_TableList *curr = transaction.changed_tables;
 
1071
  CHANGED_TABLE_LIST **prev_changed = &transaction.changed_tables;
 
1072
  CHANGED_TABLE_LIST *curr = transaction.changed_tables;
1056
1073
 
1057
1074
  for (; curr; prev_changed = &(curr->next), curr = curr->next)
1058
1075
  {
1081
1098
}
1082
1099
 
1083
1100
 
1084
 
CHANGED_TableList* THD::changed_table_dup(const char *key, long key_length)
 
1101
CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length)
1085
1102
{
1086
 
  CHANGED_TableList* new_table = 
1087
 
    (CHANGED_TableList*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TableList))+
 
1103
  CHANGED_TABLE_LIST* new_table = 
 
1104
    (CHANGED_TABLE_LIST*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TABLE_LIST))+
1088
1105
                                      key_length + 1);
1089
1106
  if (!new_table)
1090
1107
  {
1091
1108
    my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
1092
 
             ALIGN_SIZE(sizeof(TableList)) + key_length + 1);
 
1109
             ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1);
1093
1110
    killed= KILL_CONNECTION;
1094
1111
    return 0;
1095
1112
  }
1096
1113
 
1097
 
  new_table->key= ((char*)new_table)+ ALIGN_SIZE(sizeof(CHANGED_TableList));
 
1114
  new_table->key= ((char*)new_table)+ ALIGN_SIZE(sizeof(CHANGED_TABLE_LIST));
1098
1115
  new_table->next = 0;
1099
1116
  new_table->key_length = key_length;
1100
1117
  ::memcpy(new_table->key, key, key_length);
1141
1158
                              Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF));
1142
1159
}
1143
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
 
1144
1174
 
1145
1175
struct Item_change_record: public ilink
1146
1176
{
1162
1192
/*
1163
1193
  Register an item tree tree transformation, performed by the query
1164
1194
  optimizer. We need a pointer to runtime_memroot because it may be !=
1165
 
  thd->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).
1166
1196
*/
1167
1197
 
1168
1198
void THD::nocheck_register_item_tree_change(Item **place, Item *old_value,
1203
1233
}
1204
1234
 
1205
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
 
1206
1256
/*****************************************************************************
1207
1257
** Functions to provide a interface to select results
1208
1258
*****************************************************************************/
1212
1262
  thd=current_thd;
1213
1263
}
1214
1264
 
1215
 
void select_result::send_error(uint32_t errcode,const char *err)
 
1265
void select_result::send_error(uint errcode,const char *err)
1216
1266
{
1217
1267
  my_message(errcode, err, MYF(0));
1218
1268
}
1246
1296
  cs= NULL;
1247
1297
}
1248
1298
 
1249
 
bool select_send::send_fields(List<Item> &list, uint32_t flags)
 
1299
bool select_send::send_fields(List<Item> &list, uint flags)
1250
1300
{
1251
1301
  bool res;
1252
1302
  if (!(res= thd->protocol->send_fields(&list, flags)))
1340
1390
  Handling writing to file
1341
1391
************************************************************************/
1342
1392
 
1343
 
void select_to_file::send_error(uint32_t errcode,const char *err)
 
1393
void select_to_file::send_error(uint errcode,const char *err)
1344
1394
{
1345
1395
  my_message(errcode, err, MYF(0));
1346
1396
  if (file > 0)
1426
1476
                        IO_CACHE *cache)
1427
1477
{
1428
1478
  File file;
1429
 
  uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
 
1479
  uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
1430
1480
 
1431
1481
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
1432
1482
  option|= MY_REPLACE_DIR;                      // Force use of db directory
1435
1485
  if (!dirname_length(exchange->file_name))
1436
1486
  {
1437
1487
    strxnmov(path, FN_REFLEN-1, mysql_real_data_home, thd->db ? thd->db : "",
1438
 
             NULL);
 
1488
             NullS);
1439
1489
    (void) fn_format(path, exchange->file_name, path, "", option);
1440
1490
  }
1441
1491
  else
1502
1552
  }
1503
1553
  field_term_length=exchange->field_term->length();
1504
1554
  field_term_char= field_term_length ?
1505
 
                   (int) (unsigned char) (*exchange->field_term)[0] : INT_MAX;
 
1555
                   (int) (uchar) (*exchange->field_term)[0] : INT_MAX;
1506
1556
  if (!exchange->line_term->length())
1507
1557
    exchange->line_term=exchange->field_term;   // Use this if it exists
1508
1558
  field_sep_char= (exchange->enclosed->length() ?
1509
 
                  (int) (unsigned char) (*exchange->enclosed)[0] : field_term_char);
 
1559
                  (int) (uchar) (*exchange->enclosed)[0] : field_term_char);
1510
1560
  escape_char=  (exchange->escaped->length() ?
1511
 
                (int) (unsigned char) (*exchange->escaped)[0] : -1);
 
1561
                (int) (uchar) (*exchange->escaped)[0] : -1);
1512
1562
  is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char));
1513
1563
  is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char));
1514
1564
  line_sep_char= (exchange->line_term->length() ?
1515
 
                 (int) (unsigned char) (*exchange->line_term)[0] : INT_MAX);
 
1565
                 (int) (uchar) (*exchange->line_term)[0] : INT_MAX);
1516
1566
  if (!field_term_length)
1517
1567
    exchange->opt_enclosed=0;
1518
1568
  if (!exchange->enclosed->length())
1535
1585
}
1536
1586
 
1537
1587
 
1538
 
#define NEED_ESCAPING(x) ((int) (unsigned char) (x) == escape_char    || \
1539
 
                          (enclosed ? (int) (unsigned char) (x) == field_sep_char      \
1540
 
                                    : (int) (unsigned char) (x) == field_term_char) || \
1541
 
                          (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  || \
1542
1592
                          !(x))
1543
1593
 
1544
1594
bool select_export::send_data(List<Item> &items)
1555
1605
  }
1556
1606
  row_count++;
1557
1607
  Item *item;
1558
 
  uint32_t used_length=0,items_left=items.elements;
 
1608
  uint used_length=0,items_left=items.elements;
1559
1609
  List_iterator_fast<Item> li(items);
1560
1610
 
1561
 
  if (my_b_write(&cache,(unsigned char*) exchange->line_start->ptr(),
 
1611
  if (my_b_write(&cache,(uchar*) exchange->line_start->ptr(),
1562
1612
                 exchange->line_start->length()))
1563
1613
    goto err;
1564
1614
  while ((item=li++))
1569
1619
    res=item->str_result(&tmp);
1570
1620
    if (res && enclosed)
1571
1621
    {
1572
 
      if (my_b_write(&cache,(unsigned char*) exchange->enclosed->ptr(),
 
1622
      if (my_b_write(&cache,(uchar*) exchange->enclosed->ptr(),
1573
1623
                     exchange->enclosed->length()))
1574
1624
        goto err;
1575
1625
    }
1581
1631
        {
1582
1632
          null_buff[0]=escape_char;
1583
1633
          null_buff[1]='N';
1584
 
          if (my_b_write(&cache,(unsigned char*) null_buff,2))
 
1634
          if (my_b_write(&cache,(uchar*) null_buff,2))
1585
1635
            goto err;
1586
1636
        }
1587
 
        else if (my_b_write(&cache,(unsigned char*) "NULL",4))
 
1637
        else if (my_b_write(&cache,(uchar*) "NULL",4))
1588
1638
          goto err;
1589
1639
      }
1590
1640
      else
1595
1645
    else
1596
1646
    {
1597
1647
      if (fixed_row_size)
1598
 
        used_length=cmin(res->length(),item->max_length);
 
1648
        used_length=min(res->length(),item->max_length);
1599
1649
      else
1600
1650
        used_length=res->length();
1601
1651
      if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
1641
1691
            If this file is later loaded using this sequence of commands:
1642
1692
            
1643
1693
            mysql> create table t1 (a varchar(128)) character set big5;
1644
 
            mysql> LOAD DATA INFILE 'dump.txt' INTO Table t1;
 
1694
            mysql> LOAD DATA INFILE 'dump.txt' INTO TABLE t1;
1645
1695
            
1646
1696
            then 0x5C will be misinterpreted as the second byte
1647
1697
            of a multi-byte character "0xEE + 0x5C", instead of
1660
1710
 
1661
1711
          if ((NEED_ESCAPING(*pos) ||
1662
1712
               (check_second_byte &&
1663
 
                my_mbcharlen(character_set_client, (unsigned char) *pos) == 2 &&
 
1713
                my_mbcharlen(character_set_client, (uchar) *pos) == 2 &&
1664
1714
                pos + 1 < end &&
1665
1715
                NEED_ESCAPING(pos[1]))) &&
1666
1716
              /*
1668
1718
               valid for ENCLOSED BY characters:
1669
1719
              */
1670
1720
              (enclosed || !is_ambiguous_field_term ||
1671
 
               (int) (unsigned char) *pos != field_term_char))
 
1721
               (int) (uchar) *pos != field_term_char))
1672
1722
          {
1673
1723
            char tmp_buff[2];
1674
 
            tmp_buff[0]= ((int) (unsigned char) *pos == field_sep_char &&
 
1724
            tmp_buff[0]= ((int) (uchar) *pos == field_sep_char &&
1675
1725
                          is_ambiguous_field_sep) ?
1676
1726
                          field_sep_char : escape_char;
1677
1727
            tmp_buff[1]= *pos ? *pos : '0';
1678
 
            if (my_b_write(&cache,(unsigned char*) start,(uint) (pos-start)) ||
1679
 
                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))
1680
1730
              goto err;
1681
1731
            start=pos+1;
1682
1732
          }
1683
1733
        }
1684
 
        if (my_b_write(&cache,(unsigned char*) start,(uint) (pos-start)))
 
1734
        if (my_b_write(&cache,(uchar*) start,(uint) (pos-start)))
1685
1735
          goto err;
1686
1736
      }
1687
 
      else if (my_b_write(&cache,(unsigned char*) res->ptr(),used_length))
 
1737
      else if (my_b_write(&cache,(uchar*) res->ptr(),used_length))
1688
1738
        goto err;
1689
1739
    }
1690
1740
    if (fixed_row_size)
1697
1747
          space_inited=1;
1698
1748
          memset(space, ' ', sizeof(space));
1699
1749
        }
1700
 
        uint32_t length=item->max_length-used_length;
 
1750
        uint length=item->max_length-used_length;
1701
1751
        for (; length > sizeof(space) ; length-=sizeof(space))
1702
1752
        {
1703
 
          if (my_b_write(&cache,(unsigned char*) space,sizeof(space)))
 
1753
          if (my_b_write(&cache,(uchar*) space,sizeof(space)))
1704
1754
            goto err;
1705
1755
        }
1706
 
        if (my_b_write(&cache,(unsigned char*) space,length))
 
1756
        if (my_b_write(&cache,(uchar*) space,length))
1707
1757
          goto err;
1708
1758
      }
1709
1759
    }
1710
1760
    if (res && enclosed)
1711
1761
    {
1712
 
      if (my_b_write(&cache, (unsigned char*) exchange->enclosed->ptr(),
 
1762
      if (my_b_write(&cache, (uchar*) exchange->enclosed->ptr(),
1713
1763
                     exchange->enclosed->length()))
1714
1764
        goto err;
1715
1765
    }
1716
1766
    if (--items_left)
1717
1767
    {
1718
 
      if (my_b_write(&cache, (unsigned char*) exchange->field_term->ptr(),
 
1768
      if (my_b_write(&cache, (uchar*) exchange->field_term->ptr(),
1719
1769
                     field_term_length))
1720
1770
        goto err;
1721
1771
    }
1722
1772
  }
1723
 
  if (my_b_write(&cache,(unsigned char*) exchange->line_term->ptr(),
 
1773
  if (my_b_write(&cache,(uchar*) exchange->line_term->ptr(),
1724
1774
                 exchange->line_term->length()))
1725
1775
    goto err;
1726
1776
  return(0);
1766
1816
    res=item->str_result(&tmp);
1767
1817
    if (!res)                                   // If NULL
1768
1818
    {
1769
 
      if (my_b_write(&cache,(unsigned char*) "",1))
 
1819
      if (my_b_write(&cache,(uchar*) "",1))
1770
1820
        goto err;
1771
1821
    }
1772
 
    else if (my_b_write(&cache,(unsigned char*) res->ptr(),res->length()))
 
1822
    else if (my_b_write(&cache,(uchar*) res->ptr(),res->length()))
1773
1823
    {
1774
1824
      my_error(ER_ERROR_ON_WRITE, MYF(0), path, my_errno);
1775
1825
      goto err;
1802
1852
  }
1803
1853
  List_iterator_fast<Item> li(items);
1804
1854
  Item *val_item;
1805
 
  for (uint32_t i= 0; (val_item= li++); i++)
 
1855
  for (uint i= 0; (val_item= li++); i++)
1806
1856
    it->store(i, val_item);
1807
1857
  it->assigned(1);
1808
1858
  return(0);
1978
2028
}
1979
2029
 
1980
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
 
1981
2044
/*
1982
2045
  Statement functions
1983
2046
*/
1984
2047
 
1985
 
Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg)
1986
 
  :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),
1987
2051
  id(id_arg),
1988
2052
  mark_used_columns(MARK_COLUMNS_READ),
1989
2053
  lex(lex_arg),
1992
2056
  db(NULL),
1993
2057
  db_length(0)
1994
2058
{
1995
 
}
1996
 
 
1997
 
 
1998
 
/*
1999
 
  Don't free mem_root, as mem_root is freed in the end of dispatch_command
2000
 
  (once for any command).
2001
 
*/
 
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
 
2002
2090
void THD::end_statement()
2003
2091
{
2004
2092
  /* Cleanup SQL processing state to reuse this statement in next query. */
2005
2093
  lex_end(lex);
 
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;
2006
2123
}
2007
2124
 
2008
2125
 
2122
2239
void Security_context::destroy()
2123
2240
{
2124
2241
  // If not pointer to constant
2125
 
  if (user)
2126
 
  {
2127
 
    free(user);
2128
 
    user= NULL;
2129
 
  }
2130
 
  if (ip)
2131
 
  {
2132
 
    free(ip);
2133
 
    ip= NULL;
2134
 
  }
 
2242
  safeFree(user);
 
2243
  safeFree(ip);
2135
2244
}
2136
2245
 
2137
2246
 
2177
2286
  @retval 0 the user thread is active
2178
2287
  @retval 1 the user thread has been killed
2179
2288
*/
2180
 
extern "C" int thd_killed(const DRIZZLE_THD thd)
 
2289
extern "C" int thd_killed(const MYSQL_THD thd)
2181
2290
{
2182
2291
  return(thd->killed);
2183
2292
}
2187
2296
  @param thd user thread
2188
2297
  @return thread id
2189
2298
*/
2190
 
extern "C" unsigned long thd_get_thread_id(const DRIZZLE_THD thd)
 
2299
extern "C" unsigned long thd_get_thread_id(const MYSQL_THD thd)
2191
2300
{
2192
2301
  return((unsigned long)thd->thread_id);
2193
2302
}
2194
2303
 
2195
2304
 
2196
2305
#ifdef INNODB_COMPATIBILITY_HOOKS
2197
 
extern "C" const struct charset_info_st *thd_charset(DRIZZLE_THD thd)
 
2306
extern "C" const struct charset_info_st *thd_charset(MYSQL_THD thd)
2198
2307
{
2199
2308
  return(thd->charset());
2200
2309
}
2201
2310
 
2202
 
extern "C" char **thd_query(DRIZZLE_THD thd)
 
2311
extern "C" char **thd_query(MYSQL_THD thd)
2203
2312
{
2204
2313
  return(&thd->query);
2205
2314
}
2206
2315
 
2207
 
extern "C" int thd_slave_thread(const DRIZZLE_THD thd)
 
2316
extern "C" int thd_slave_thread(const MYSQL_THD thd)
2208
2317
{
2209
2318
  return(thd->slave_thread);
2210
2319
}
2211
2320
 
2212
 
extern "C" int thd_non_transactional_update(const DRIZZLE_THD thd)
 
2321
extern "C" int thd_non_transactional_update(const MYSQL_THD thd)
2213
2322
{
2214
2323
  return(thd->transaction.all.modified_non_trans_table);
2215
2324
}
2216
2325
 
2217
 
extern "C" int thd_binlog_format(const DRIZZLE_THD thd)
 
2326
extern "C" int thd_binlog_format(const MYSQL_THD thd)
2218
2327
{
2219
2328
  return (int) thd->variables.binlog_format;
2220
2329
}
2221
2330
 
2222
 
extern "C" void thd_mark_transaction_to_rollback(DRIZZLE_THD thd, bool all)
 
2331
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all)
2223
2332
{
2224
2333
  mark_transaction_to_rollback(thd, all);
2225
2334
}
2248
2357
pthread_mutex_t LOCK_xid_cache;
2249
2358
HASH xid_cache;
2250
2359
 
2251
 
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);
2252
2361
extern "C" void xid_free_hash(void *);
2253
2362
 
2254
 
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,
2255
2364
                        bool not_used __attribute__((unused)))
2256
2365
{
2257
2366
  *length=((XID_STATE*)ptr)->xid.key_length();
2261
2370
void xid_free_hash(void *ptr)
2262
2371
{
2263
2372
  if (!((XID_STATE*)ptr)->in_thd)
2264
 
    free((unsigned char*)ptr);
 
2373
    my_free((uchar*)ptr, MYF(0));
2265
2374
}
2266
2375
 
2267
2376
bool xid_cache_init()
2303
2412
    xs->xa_state=xa_state;
2304
2413
    xs->xid.set(xid);
2305
2414
    xs->in_thd=0;
2306
 
    res=my_hash_insert(&xid_cache, (unsigned char*)xs);
 
2415
    res=my_hash_insert(&xid_cache, (uchar*)xs);
2307
2416
  }
2308
2417
  pthread_mutex_unlock(&LOCK_xid_cache);
2309
2418
  return res;
2315
2424
  pthread_mutex_lock(&LOCK_xid_cache);
2316
2425
  assert(hash_search(&xid_cache, xid_state->xid.key(),
2317
2426
                          xid_state->xid.key_length())==0);
2318
 
  bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
 
2427
  bool res=my_hash_insert(&xid_cache, (uchar*)xid_state);
2319
2428
  pthread_mutex_unlock(&LOCK_xid_cache);
2320
2429
  return res;
2321
2430
}
2324
2433
void xid_cache_delete(XID_STATE *xid_state)
2325
2434
{
2326
2435
  pthread_mutex_lock(&LOCK_xid_cache);
2327
 
  hash_delete(&xid_cache, (unsigned char *)xid_state);
 
2436
  hash_delete(&xid_cache, (uchar *)xid_state);
2328
2437
  pthread_mutex_unlock(&LOCK_xid_cache);
2329
2438
}
2330
2439
 
2334
2443
  inserted/updated/deleted.
2335
2444
*/
2336
2445
 
 
2446
#ifndef MYSQL_CLIENT
2337
2447
 
2338
2448
/*
2339
2449
  Template member function for ensuring that there is an rows log
2357
2467
 */
2358
2468
 
2359
2469
template <class RowsEventT> Rows_log_event* 
2360
 
THD::binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
 
2470
THD::binlog_prepare_pending_rows_event(TABLE* table, uint32_t serv_id,
2361
2471
                                       size_t needed,
2362
2472
                                       bool is_transactional,
2363
2473
                                       RowsEventT *hint __attribute__((unused)))
2364
2474
{
2365
2475
  /* Pre-conditions */
2366
 
  assert(table->s->table_map_id != UINT32_MAX);
 
2476
  assert(table->s->table_map_id != ~0UL);
2367
2477
 
2368
2478
  /* Fetch the type code for the RowsEventT template parameter */
2369
2479
  int const type_code= RowsEventT::TYPE_CODE;
2433
2543
  compiling option.
2434
2544
*/
2435
2545
template Rows_log_event*
2436
 
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
 
2546
THD::binlog_prepare_pending_rows_event(TABLE*, uint32_t, size_t, bool,
2437
2547
                                       Write_rows_log_event*);
2438
2548
 
2439
2549
template Rows_log_event*
2440
 
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
 
2550
THD::binlog_prepare_pending_rows_event(TABLE*, uint32_t, size_t, bool,
2441
2551
                                       Delete_rows_log_event *);
2442
2552
 
2443
2553
template Rows_log_event* 
2444
 
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
 
2554
THD::binlog_prepare_pending_rows_event(TABLE*, uint32_t, size_t, bool,
2445
2555
                                       Update_rows_log_event *);
2446
2556
#endif
2447
2557
 
2473
2583
      @param length
2474
2584
      Length of data that is needed, if the record contain blobs.
2475
2585
     */
2476
 
    Row_data_memory(Table *table, size_t const len1)
 
2586
    Row_data_memory(TABLE *table, size_t const len1)
2477
2587
      : m_memory(0)
2478
2588
    {
2479
2589
      m_alloc_checked= false;
2482
2592
      m_ptr[1]= 0;
2483
2593
    }
2484
2594
 
2485
 
    Row_data_memory(Table *table, size_t const len1, size_t const len2)
 
2595
    Row_data_memory(TABLE *table, size_t const len1, size_t const len2)
2486
2596
      : m_memory(0)
2487
2597
    {
2488
2598
      m_alloc_checked= false;
2494
2604
    ~Row_data_memory()
2495
2605
    {
2496
2606
      if (m_memory != 0 && m_release_memory_on_destruction)
2497
 
        free((unsigned char*) m_memory);
 
2607
        my_free((uchar*) m_memory, MYF(MY_WME));
2498
2608
    }
2499
2609
 
2500
2610
    /**
2508
2618
      return m_memory != 0;
2509
2619
    }
2510
2620
 
2511
 
    unsigned char *slot(uint32_t s)
 
2621
    uchar *slot(uint s)
2512
2622
    {
2513
2623
      assert(s < sizeof(m_ptr)/sizeof(*m_ptr));
2514
2624
      assert(m_ptr[s] != 0);
2517
2627
    }
2518
2628
 
2519
2629
  private:
2520
 
    void allocate_memory(Table *const table, size_t const total_length)
 
2630
    void allocate_memory(TABLE *const table, size_t const total_length)
2521
2631
    {
2522
2632
      if (table->s->blob_fields == 0)
2523
2633
      {
2540
2650
        */
2541
2651
        if (table->write_row_record == 0)
2542
2652
          table->write_row_record=
2543
 
            (unsigned char *) alloc_root(&table->mem_root, 2 * maxlen);
 
2653
            (uchar *) alloc_root(&table->mem_root, 2 * maxlen);
2544
2654
        m_memory= table->write_row_record;
2545
2655
        m_release_memory_on_destruction= false;
2546
2656
      }
2547
2657
      else
2548
2658
      {
2549
 
        m_memory= (unsigned char *) my_malloc(total_length, MYF(MY_WME));
 
2659
        m_memory= (uchar *) my_malloc(total_length, MYF(MY_WME));
2550
2660
        m_release_memory_on_destruction= true;
2551
2661
      }
2552
2662
    }
2553
2663
 
2554
2664
    mutable bool m_alloc_checked;
2555
2665
    bool m_release_memory_on_destruction;
2556
 
    unsigned char *m_memory;
2557
 
    unsigned char *m_ptr[2];
 
2666
    uchar *m_memory;
 
2667
    uchar *m_ptr[2];
2558
2668
  };
2559
2669
}
2560
2670
 
2561
2671
 
2562
 
int THD::binlog_write_row(Table* table, bool is_trans, 
2563
 
                          unsigned char const *record) 
 
2672
int THD::binlog_write_row(TABLE* table, bool is_trans, 
 
2673
                          uchar const *record) 
2564
2674
2565
2675
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2566
2676
 
2568
2678
    Pack records into format for transfer. We are allocating more
2569
2679
    memory than needed, but that doesn't matter.
2570
2680
  */
2571
 
  Row_data_memory memory(table, table->max_row_length(record));
 
2681
  Row_data_memory memory(table, max_row_length(table, record));
2572
2682
  if (!memory.has_memory())
2573
2683
    return HA_ERR_OUT_OF_MEM;
2574
2684
 
2575
 
  unsigned char *row_data= memory.slot(0);
 
2685
  uchar *row_data= memory.slot(0);
2576
2686
 
2577
2687
  size_t const len= pack_row(table, table->write_set, row_data, record);
2578
2688
 
2586
2696
  return ev->add_row_data(row_data, len);
2587
2697
}
2588
2698
 
2589
 
int THD::binlog_update_row(Table* table, bool is_trans,
2590
 
                           const unsigned char *before_record,
2591
 
                           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)
2592
2702
2593
2703
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2594
2704
 
2595
 
  size_t const before_maxlen = table->max_row_length(before_record);
2596
 
  size_t const after_maxlen  = table->max_row_length(after_record);
 
2705
  size_t const before_maxlen = max_row_length(table, before_record);
 
2706
  size_t const after_maxlen  = max_row_length(table, after_record);
2597
2707
 
2598
2708
  Row_data_memory row_data(table, before_maxlen, after_maxlen);
2599
2709
  if (!row_data.has_memory())
2600
2710
    return HA_ERR_OUT_OF_MEM;
2601
2711
 
2602
 
  unsigned char *before_row= row_data.slot(0);
2603
 
  unsigned char *after_row= row_data.slot(1);
 
2712
  uchar *before_row= row_data.slot(0);
 
2713
  uchar *after_row= row_data.slot(1);
2604
2714
 
2605
2715
  size_t const before_size= pack_row(table, table->read_set, before_row,
2606
2716
                                        before_record);
2620
2730
    ev->add_row_data(after_row, after_size);
2621
2731
}
2622
2732
 
2623
 
int THD::binlog_delete_row(Table* table, bool is_trans, 
2624
 
                           unsigned char const *record)
 
2733
int THD::binlog_delete_row(TABLE* table, bool is_trans, 
 
2734
                           uchar const *record)
2625
2735
2626
2736
  assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2627
2737
 
2629
2739
     Pack records into format for transfer. We are allocating more
2630
2740
     memory than needed, but that doesn't matter.
2631
2741
  */
2632
 
  Row_data_memory memory(table, table->max_row_length(record));
 
2742
  Row_data_memory memory(table, max_row_length(table, record));
2633
2743
  if (unlikely(!memory.has_memory()))
2634
2744
    return HA_ERR_OUT_OF_MEM;
2635
2745
 
2636
 
  unsigned char *row_data= memory.slot(0);
 
2746
  uchar *row_data= memory.slot(0);
2637
2747
 
2638
2748
  size_t const len= pack_row(table, table->read_set, row_data, record);
2639
2749
 
2737
2847
    if (current_stmt_binlog_row_based)
2738
2848
      return(0);
2739
2849
    /* Otherwise, we fall through */
2740
 
  case THD::DRIZZLE_QUERY_TYPE:
 
2850
  case THD::MYSQL_QUERY_TYPE:
2741
2851
    /*
2742
2852
      Using this query type is a conveniece hack, since we have been
2743
2853
      moving back and forth between using RBR for replication of
2748
2858
    */
2749
2859
  case THD::STMT_QUERY_TYPE:
2750
2860
    /*
2751
 
      The DRIZZLE_LOG::write() function will set the STMT_END_F flag and
 
2861
      The MYSQL_LOG::write() function will set the STMT_END_F flag and
2752
2862
      flush the pending rows event if necessary.
2753
2863
     */
2754
2864
    {
2799
2909
  elements++;
2800
2910
  return(0);
2801
2911
}
 
2912
 
 
2913
#endif /* !defined(MYSQL_CLIENT) */