~ubuntu-branches/ubuntu/gutsy/mysql-dfsg-5.0/gutsy

« back to all changes in this revision

Viewing changes to sql/sql_class.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-04-03 09:43:01 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070403094301-fnjhfr59hu72pvtg
Tags: 5.0.38-0ubuntu1
* Package the Enterprise version again (.37 was a community version), since
  Debian and we have always done so. This brings in a few more bug fixes and
  makes functional derivations less likely.
* debian/README.Maintainer: Add pointer to upstream download URL, since it
  is very hard to find the Enterprise versions.
* Disable 33_scripts__mysql_create_system_tables__no_test.dpatch, since that
  script was removed upstream.
* debian/patches/41_scripts__mysql_install_db.sh__no_test.dpatch: Adapted to
  changed formatting in new upstream version.
* Remove debian/patches/86_PATH_MAX.dpatch, fixed upstream.
* Add debian/patches/90_org_tables_definition.dpatch: Fix local variable
  declaration in libmysqld/sql_parse.cc to fix compilation with
  EMBEDDED_LIBRARY.

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
}
167
167
 
168
168
 
169
 
/*
170
 
  Pass nominal parameters to Statement constructor only to ensure that
171
 
  the destructor works OK in case of error. The main_mem_root will be
172
 
  re-initialized in init().
173
 
*/
174
169
 
175
170
THD::THD()
176
 
  :Statement(CONVENTIONAL_EXECUTION, 0, ALLOC_ROOT_MIN_BLOCK_SIZE, 0),
 
171
   :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION,
 
172
              /* statement id */ 0),
177
173
   Open_tables_state(refresh_version),
178
174
   lock_id(&main_lock_id),
179
175
   user_time(0), in_sub_stmt(0), global_read_lock(0), is_fatal_error(0),
182
178
   clear_next_insert_id(0), in_lock_tables(0), bootstrap(0),
183
179
   derived_tables_processing(FALSE), spcont(NULL)
184
180
{
 
181
  ulong tmp;
 
182
 
 
183
  /*
 
184
    Pass nominal parameters to init_alloc_root only to ensure that
 
185
    the destructor works OK in case of an error. The main_mem_root
 
186
    will be re-initialized in init_for_queries().
 
187
  */
 
188
  init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
185
189
  stmt_arena= this;
186
190
  thread_stack= 0;
187
191
  db= 0;
224
228
#endif
225
229
  client_capabilities= 0;                       // minimalistic client
226
230
  net.last_error[0]=0;                          // If error on boot
 
231
#ifdef HAVE_QUERY_CACHE
227
232
  query_cache_init_query(&net);                 // If error on boot
 
233
#endif
228
234
  ull=0;
229
235
  system_thread= cleanup_done= abort_on_warning= no_warnings_for_error= 0;
230
236
  peer_port= 0;                                 // For SHOW PROCESSLIST
247
253
  init();
248
254
  /* Initialize sub structures */
249
255
  init_sql_alloc(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE);
250
 
#ifdef ENABLED_PROFILING
251
 
  profiling.set_thd(this);
252
 
#endif
253
256
  user_connect=(USER_CONN *)0;
254
257
  hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
255
258
            (hash_get_key) get_var_key,
271
274
  protocol_prep.init(this);
272
275
 
273
276
  tablespace_op=FALSE;
274
 
  ulong tmp=sql_rnd_with_mutex();
275
 
  randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id);
 
277
  tmp= sql_rnd_with_mutex();
 
278
  randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::global_query_id);
276
279
  substitute_null_with_insert_id = FALSE;
277
280
  thr_lock_info_init(&lock_info); /* safety: will be reset after start */
278
281
  thr_lock_owner_init(&main_lock_id, &lock_info);
 
282
 
 
283
  m_internal_handler= NULL;
 
284
}
 
285
 
 
286
 
 
287
void THD::push_internal_handler(Internal_error_handler *handler)
 
288
{
 
289
  /*
 
290
    TODO: The current implementation is limited to 1 handler at a time only.
 
291
    THD and sp_rcontext need to be modified to use a common handler stack.
 
292
  */
 
293
  DBUG_ASSERT(m_internal_handler == NULL);
 
294
  m_internal_handler= handler;
 
295
}
 
296
 
 
297
 
 
298
bool THD::handle_error(uint sql_errno,
 
299
                       MYSQL_ERROR::enum_warning_level level)
 
300
{
 
301
  if (m_internal_handler)
 
302
  {
 
303
    return m_internal_handler->handle_error(sql_errno, level, this);
 
304
  }
 
305
 
 
306
  return FALSE;                                 // 'FALSE', as per coding style
 
307
}
 
308
 
 
309
 
 
310
void THD::pop_internal_handler()
 
311
{
 
312
  DBUG_ASSERT(m_internal_handler != NULL);
 
313
  m_internal_handler= NULL;
279
314
}
280
315
 
281
316
 
320
355
 
321
356
void THD::init_for_queries()
322
357
{
 
358
  set_time(); 
323
359
  ha_enable_transaction(this,TRUE);
324
360
 
325
361
  reset_root_defaults(mem_root, variables.query_alloc_block_size,
443
479
#ifndef DBUG_OFF
444
480
  dbug_sentry= THD_SENTRY_GONE;
445
481
#endif  
 
482
  free_root(&main_mem_root, MYF(0));
446
483
  DBUG_VOID_RETURN;
447
484
}
448
485
 
902
939
  enclosed=   line_start= &my_empty_string;
903
940
  line_term=  &default_line_term;
904
941
  escaped=    &default_escaped;
 
942
  cs= NULL;
905
943
}
906
944
 
907
945
bool select_send::send_fields(List<Item> &list, uint flags)
1084
1122
                        IO_CACHE *cache)
1085
1123
{
1086
1124
  File file;
1087
 
  uint option= MY_UNPACK_FILENAME;
 
1125
  uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
1088
1126
 
1089
1127
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
1090
1128
  option|= MY_REPLACE_DIR;                      // Force use of db directory
1097
1135
  }
1098
1136
  else
1099
1137
    (void) fn_format(path, exchange->file_name, mysql_real_data_home, "", option);
1100
 
    
 
1138
 
 
1139
  if (opt_secure_file_priv &&
 
1140
      strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
 
1141
  {
 
1142
    /* Write only allowed to dir or subdir specified by secure_file_priv */
 
1143
    my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
1144
    return -1;
 
1145
  }
 
1146
 
1101
1147
  if (!access(path, F_OK))
1102
1148
  {
1103
1149
    my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name);
1178
1224
  }
1179
1225
  row_count++;
1180
1226
  Item *item;
1181
 
  char *buff_ptr=buff;
1182
1227
  uint used_length=0,items_left=items.elements;
1183
1228
  List_iterator_fast<Item> li(items);
1184
1229
 
1278
1323
          goto err;
1279
1324
      }
1280
1325
    }
1281
 
    buff_ptr=buff;                              // Place separators here
1282
1326
    if (res && (!exchange->opt_enclosed || result_type == STRING_RESULT))
1283
1327
    {
1284
 
      memcpy(buff_ptr,exchange->enclosed->ptr(),exchange->enclosed->length());
1285
 
      buff_ptr+=exchange->enclosed->length();
 
1328
      if (my_b_write(&cache, (byte*) exchange->enclosed->ptr(),
 
1329
                     exchange->enclosed->length()))
 
1330
        goto err;
1286
1331
    }
1287
1332
    if (--items_left)
1288
1333
    {
1289
 
      memcpy(buff_ptr,exchange->field_term->ptr(),field_term_length);
1290
 
      buff_ptr+=field_term_length;
 
1334
      if (my_b_write(&cache, (byte*) exchange->field_term->ptr(),
 
1335
                     field_term_length))
 
1336
        goto err;
1291
1337
    }
1292
 
    if (my_b_write(&cache,(byte*) buff,(uint) (buff_ptr-buff)))
1293
 
      goto err;
1294
1338
  }
1295
1339
  if (my_b_write(&cache,(byte*) exchange->line_term->ptr(),
1296
1340
                 exchange->line_term->length()))
1438
1482
 
1439
1483
bool select_max_min_finder_subselect::cmp_real()
1440
1484
{
1441
 
  Item *maxmin= ((Item_singlerow_subselect *)item)->el(0);
 
1485
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1442
1486
  double val1= cache->val_real(), val2= maxmin->val_real();
1443
1487
  if (fmax)
1444
1488
    return (cache->null_value && !maxmin->null_value) ||
1451
1495
 
1452
1496
bool select_max_min_finder_subselect::cmp_int()
1453
1497
{
1454
 
  Item *maxmin= ((Item_singlerow_subselect *)item)->el(0);
 
1498
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1455
1499
  longlong val1= cache->val_int(), val2= maxmin->val_int();
1456
1500
  if (fmax)
1457
1501
    return (cache->null_value && !maxmin->null_value) ||
1464
1508
 
1465
1509
bool select_max_min_finder_subselect::cmp_decimal()
1466
1510
{
1467
 
  Item *maxmin= ((Item_singlerow_subselect *)item)->el(0);
 
1511
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1468
1512
  my_decimal cval, *cvalue= cache->val_decimal(&cval);
1469
1513
  my_decimal mval, *mvalue= maxmin->val_decimal(&mval);
1470
1514
  if (fmax)
1479
1523
bool select_max_min_finder_subselect::cmp_str()
1480
1524
{
1481
1525
  String *val1, *val2, buf1, buf2;
1482
 
  Item *maxmin= ((Item_singlerow_subselect *)item)->el(0);
 
1526
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1483
1527
  /*
1484
1528
    as far as both operand is Item_cache buf1 & buf2 will not be used,
1485
1529
    but added for safety
1580
1624
  Statement functions 
1581
1625
*/
1582
1626
 
1583
 
Statement::Statement(enum enum_state state_arg, ulong id_arg,
1584
 
                     ulong alloc_block_size, ulong prealloc_size)
1585
 
  :Query_arena(&main_mem_root, state_arg),
 
1627
Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
 
1628
                     enum enum_state state_arg, ulong id_arg)
 
1629
  :Query_arena(mem_root_arg, state_arg),
1586
1630
  id(id_arg),
1587
1631
  set_query_id(1),
1588
 
  lex(&main_lex),
 
1632
  lex(lex_arg),
1589
1633
  query(0),
1590
1634
  query_length(0),
1591
1635
  cursor(0)
1592
1636
{
1593
1637
  name.str= NULL;
1594
 
  init_sql_alloc(&main_mem_root, alloc_block_size, prealloc_size);
1595
1638
}
1596
1639
 
1597
1640
 
1633
1676
 
1634
1677
void THD::end_statement()
1635
1678
{
1636
 
  /* Cleanup SQL processing state to resuse this statement in next query. */
 
1679
  /* Cleanup SQL processing state to reuse this statement in next query. */
1637
1680
  lex_end(lex);
1638
1681
  delete lex->result;
1639
1682
  lex->result= 0;
1674
1717
 
1675
1718
Statement::~Statement()
1676
1719
{
1677
 
  /*
1678
 
    We must free `main_mem_root', not `mem_root' (pointer), to work
1679
 
    correctly if this statement is used as a backup statement,
1680
 
    for which `mem_root' may point to some other statement.
1681
 
  */
1682
 
  free_root(&main_mem_root, MYF(0));
1683
1720
}
1684
1721
 
1685
1722
C_MODE_START
2051
2088
 
2052
2089
  if (!lex->requires_prelocking() || is_update_query(lex->sql_command))
2053
2090
    options&= ~OPTION_BIN_LOG;
 
2091
 
 
2092
  if ((backup->options & OPTION_BIN_LOG) && is_update_query(lex->sql_command))
 
2093
    mysql_bin_log.start_union_events(this, this->query_id);
 
2094
 
2054
2095
  /* Disable result sets */
2055
2096
  client_capabilities &= ~CLIENT_MULTI_RESULTS;
2056
2097
  in_sub_stmt|= new_state;
2097
2138
  sent_row_count=   backup->sent_row_count;
2098
2139
  client_capabilities= backup->client_capabilities;
2099
2140
 
 
2141
  if ((options & OPTION_BIN_LOG) && is_update_query(lex->sql_command))
 
2142
    mysql_bin_log.stop_union_events(this);
 
2143
 
2100
2144
  /*
2101
2145
    The following is added to the old values as we are interested in the
2102
2146
    total complexity of the query