~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr)
36
36
{
37
37
  register int flag;
38
 
  DBUG_ENTER("wild_case_compare");
39
 
  DBUG_PRINT("enter",("str: '%s'  wildstr: '%s'",str,wildstr));
40
38
  while (*wildstr)
41
39
  {
42
40
    while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
43
41
    {
44
42
      if (*wildstr == wild_prefix && wildstr[1])
45
 
        wildstr++;
46
 
      if (my_toupper(cs, *wildstr++) !=
47
 
          my_toupper(cs, *str++)) DBUG_RETURN(1);
 
43
        wildstr++;
 
44
      if (my_toupper(cs, *wildstr++) != my_toupper(cs, *str++))
 
45
        return(1);
48
46
    }
49
 
    if (! *wildstr ) DBUG_RETURN (*str != 0);
 
47
    if (! *wildstr )
 
48
      return (*str != 0);
50
49
    if (*wildstr++ == wild_one)
51
50
    {
52
 
      if (! *str++) DBUG_RETURN (1);    /* One char; skip */
 
51
      if (! *str++)
 
52
        return (1);     /* One char; skip */
53
53
    }
54
54
    else
55
55
    {                                           /* Found '*' */
56
 
      if (!*wildstr) DBUG_RETURN(0);            /* '*' as last char: OK */
 
56
      if (!*wildstr)
 
57
        return(0);              /* '*' as last char: OK */
57
58
      flag=(*wildstr != wild_many && *wildstr != wild_one);
58
59
      do
59
60
      {
65
66
          cmp=my_toupper(cs, cmp);
66
67
          while (*str && my_toupper(cs, *str) != cmp)
67
68
            str++;
68
 
          if (!*str) DBUG_RETURN (1);
 
69
    if (!*str)
 
70
      return (1);
69
71
        }
70
 
        if (wild_case_compare(cs, str,wildstr) == 0) DBUG_RETURN (0);
 
72
  if (wild_case_compare(cs, str,wildstr) == 0)
 
73
      return (0);
71
74
      } while (*str++);
72
 
      DBUG_RETURN(1);
 
75
      return(1);
73
76
    }
74
77
  }
75
 
  DBUG_RETURN (*str != '\0');
 
78
  return (*str != '\0');
76
79
}
77
80
 
78
81
/***************************************************************************
180
183
 
181
184
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond)
182
185
{
183
 
  DBUG_ENTER("fill_plugins");
184
186
  TABLE *table= tables->table;
185
187
 
186
188
  if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
187
189
                               ~PLUGIN_IS_FREED, table))
188
 
    DBUG_RETURN(1);
 
190
    return(1);
189
191
 
190
 
  DBUG_RETURN(0);
 
192
  return(0);
191
193
}
192
194
 
193
195
 
222
224
  LEX_STRING *file_name= 0;
223
225
  uint file_name_len;
224
226
  TABLE_LIST table_list;
225
 
  DBUG_ENTER("find_files");
226
227
 
227
228
  if (wild && !wild[0])
228
229
    wild=0;
235
236
      my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db);
236
237
    else
237
238
      my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
238
 
    DBUG_RETURN(FIND_FILES_DIR);
 
239
    return(FIND_FILES_DIR);
239
240
  }
240
241
 
241
242
  for (i=0 ; i < (uint) dirp->number_off_files  ; i++)
274
275
            thd->make_lex_string(file_name, uname, file_name_len, TRUE)))
275
276
      {
276
277
        my_dirend(dirp);
277
 
        DBUG_RETURN(FIND_FILES_OOM);
 
278
        return(FIND_FILES_OOM);
278
279
      }
279
280
    }
280
281
    else
301
302
        files->push_back(file_name))
302
303
    {
303
304
      my_dirend(dirp);
304
 
      DBUG_RETURN(FIND_FILES_OOM);
 
305
      return(FIND_FILES_OOM);
305
306
    }
306
307
  }
307
 
  DBUG_PRINT("info",("found: %d files", files->elements));
308
308
  my_dirend(dirp);
309
309
 
310
 
  DBUG_RETURN(FIND_FILES_OK);
 
310
  return(FIND_FILES_OK);
311
311
}
312
312
 
313
313
 
317
317
  Protocol *protocol= thd->protocol;
318
318
  char buff[2048];
319
319
  String buffer(buff, sizeof(buff), system_charset_info);
320
 
  DBUG_ENTER("mysqld_show_create");
321
 
  DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
322
 
                      table_list->table_name));
323
320
 
324
321
  /* Only one table for now, but VIEW can involve several tables */
325
322
  if (open_normal_and_derived_tables(thd, table_list, 0))
326
323
  {
327
324
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
328
 
      DBUG_RETURN(TRUE);
 
325
      return(TRUE);
329
326
 
330
327
    /*
331
328
      Clear all messages with 'error' level status and
339
336
  buffer.length(0);
340
337
 
341
338
  if (store_create_info(thd, table_list, &buffer, NULL))
342
 
    DBUG_RETURN(TRUE);
 
339
    return(TRUE);
343
340
 
344
341
  List<Item> field_list;
345
342
  {
351
348
 
352
349
  if (protocol->send_fields(&field_list,
353
350
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
354
 
    DBUG_RETURN(TRUE);
 
351
    return(TRUE);
355
352
  protocol->prepare_for_resend();
356
353
  {
357
354
    if (table_list->schema_table)
364
361
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
365
362
 
366
363
  if (protocol->write())
367
 
    DBUG_RETURN(TRUE);
 
364
    return(TRUE);
368
365
 
369
366
  my_eof(thd);
370
 
  DBUG_RETURN(FALSE);
 
367
  return(FALSE);
371
368
}
372
369
 
373
370
bool mysqld_show_create_db(THD *thd, char *dbname,
376
373
  char buff[2048];
377
374
  String buffer(buff, sizeof(buff), system_charset_info);
378
375
  Protocol *protocol=thd->protocol;
379
 
  DBUG_ENTER("mysql_show_create_db");
380
376
 
381
377
  if (store_db_create_info(thd, dbname, &buffer, create_info))
382
378
  {
385
381
      can fail is incorrect database name (which is the case now).
386
382
    */
387
383
    my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
388
 
    DBUG_RETURN(TRUE);    
 
384
    return(TRUE);    
389
385
  }
390
386
 
391
387
  List<Item> field_list;
394
390
 
395
391
  if (protocol->send_fields(&field_list,
396
392
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
397
 
    DBUG_RETURN(TRUE);
 
393
    return(TRUE);
398
394
 
399
395
  protocol->prepare_for_resend();
400
396
  protocol->store(dbname, strlen(dbname), system_charset_info);
401
397
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
402
398
 
403
399
  if (protocol->write())
404
 
    DBUG_RETURN(TRUE);
 
400
    return(TRUE);
405
401
  my_eof(thd);
406
 
  DBUG_RETURN(FALSE);
 
402
  return(FALSE);
407
403
}
408
404
 
409
405
 
417
413
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
418
414
{
419
415
  TABLE *table;
420
 
  DBUG_ENTER("mysqld_list_fields");
421
 
  DBUG_PRINT("enter",("table: %s",table_list->table_name));
422
416
 
423
417
  if (open_normal_and_derived_tables(thd, table_list, 0))
424
 
    DBUG_VOID_RETURN;
 
418
    return;
425
419
  table= table_list->table;
426
420
 
427
421
  List<Item> field_list;
438
432
  restore_record(table, s->default_values);              // Get empty record
439
433
  table->use_all_columns();
440
434
  if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
441
 
    DBUG_VOID_RETURN;
 
435
    return;
442
436
  my_eof(thd);
443
 
  DBUG_VOID_RETURN;
 
437
  return;
444
438
}
445
439
 
446
440
 
680
674
  HA_CREATE_INFO create_info;
681
675
  bool show_table_options= FALSE;
682
676
  my_bitmap_map *old_map;
683
 
  DBUG_ENTER("store_create_info");
684
 
  DBUG_PRINT("enter",("table: %s", table->s->table_name.str));
685
677
 
686
678
  restore_record(table, s->default_values); // Get empty record
687
679
 
1034
1026
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
1035
1027
  }
1036
1028
  tmp_restore_column_map(table->read_set, old_map);
1037
 
  DBUG_RETURN(0);
 
1029
  return(0);
1038
1030
}
1039
1031
 
1040
1032
/**
1064
1056
{
1065
1057
  HA_CREATE_INFO create;
1066
1058
  uint create_options = create_info ? create_info->options : 0;
1067
 
  DBUG_ENTER("store_db_create_info");
1068
1059
 
1069
1060
  if (!my_strcasecmp(system_charset_info, dbname,
1070
1061
                     INFORMATION_SCHEMA_NAME.str))
1075
1066
  else
1076
1067
  {
1077
1068
    if (check_db_dir_existence(dbname))
1078
 
      DBUG_RETURN(TRUE);
 
1069
      return(TRUE);
1079
1070
 
1080
1071
    load_db_opt_by_name(thd, dbname, &create);
1081
1072
  }
1103
1094
    buffer->append(STRING_WITH_LEN(" */"));
1104
1095
  }
1105
1096
 
1106
 
  DBUG_RETURN(FALSE);
 
1097
  return(FALSE);
1107
1098
}
1108
1099
 
1109
1100
static void store_key_options(THD *thd, String *packet, TABLE *table,
1170
1161
  ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
1171
1162
                           PROCESS_LIST_WIDTH);
1172
1163
  Protocol *protocol= thd->protocol;
1173
 
  DBUG_ENTER("mysqld_list_processes");
1174
1164
 
1175
1165
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1176
1166
  field_list.push_back(new Item_empty_string("User",16));
1185
1175
  field->maybe_null=1;
1186
1176
  if (protocol->send_fields(&field_list,
1187
1177
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1188
 
    DBUG_VOID_RETURN;
 
1178
    return;
1189
1179
 
1190
1180
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1191
1181
  if (!thd->killed)
1266
1256
      break; /* purecov: inspected */
1267
1257
  }
1268
1258
  my_eof(thd);
1269
 
  DBUG_VOID_RETURN;
 
1259
  return;
1270
1260
}
1271
1261
 
1272
1262
int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
1275
1265
  CHARSET_INFO *cs= system_charset_info;
1276
1266
  char *user;
1277
1267
  time_t now= my_time(0);
1278
 
  DBUG_ENTER("fill_process_list");
1279
1268
 
1280
1269
  user= NullS;
1281
1270
 
1354
1343
      if (schema_table_store_record(thd, table))
1355
1344
      {
1356
1345
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
1357
 
        DBUG_RETURN(1);
 
1346
        return(1);
1358
1347
      }
1359
1348
    }
1360
1349
  }
1361
1350
 
1362
1351
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1363
 
  DBUG_RETURN(0);
 
1352
  return(0);
1364
1353
}
1365
1354
 
1366
1355
/*****************************************************************************
1557
1546
  int len;
1558
1547
  LEX_STRING null_lex_str;
1559
1548
  SHOW_VAR tmp, *var;
1560
 
  DBUG_ENTER("show_status_array");
1561
1549
 
1562
1550
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1563
1551
  null_lex_str.length= 0;
1687
1675
        pthread_mutex_unlock(&LOCK_global_system_variables);
1688
1676
 
1689
1677
        if (schema_table_store_record(thd, table))
1690
 
          DBUG_RETURN(TRUE);
 
1678
          return(TRUE);
1691
1679
      }
1692
1680
    }
1693
1681
  }
1694
1682
 
1695
 
  DBUG_RETURN(FALSE);
 
1683
  return(FALSE);
1696
1684
}
1697
1685
 
1698
1686
 
1700
1688
 
1701
1689
void calc_sum_of_all_status(STATUS_VAR *to)
1702
1690
{
1703
 
  DBUG_ENTER("calc_sum_of_all_status");
1704
1691
 
1705
1692
  /* Ensure that thread id not killed during loop */
1706
1693
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1716
1703
    add_to_status(to, &tmp->status_var);
1717
1704
  
1718
1705
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1719
 
  DBUG_VOID_RETURN;
 
1706
  return;
1720
1707
}
1721
1708
 
1722
1709
 
2157
2144
  List<LEX_STRING> *file_list= data->files;
2158
2145
  const char *wild= data->wild;
2159
2146
  ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
2160
 
  DBUG_ENTER("add_schema_table");
2161
2147
 
2162
2148
  if (schema_table->hidden)
2163
 
      DBUG_RETURN(0);
 
2149
      return(0);
2164
2150
  if (wild)
2165
2151
  {
2166
2152
    if (lower_case_table_names)
2168
2154
      if (wild_case_compare(files_charset_info,
2169
2155
                            schema_table->table_name,
2170
2156
                            wild))
2171
 
        DBUG_RETURN(0);
 
2157
        return(0);
2172
2158
    }
2173
2159
    else if (wild_compare(schema_table->table_name, wild, 0))
2174
 
      DBUG_RETURN(0);
 
2160
      return(0);
2175
2161
  }
2176
2162
 
2177
2163
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2178
2164
                                       strlen(schema_table->table_name),
2179
2165
                                       TRUE)) &&
2180
2166
      !file_list->push_back(file_name))
2181
 
    DBUG_RETURN(0);
2182
 
  DBUG_RETURN(1);
 
2167
    return(0);
 
2168
  return(1);
2183
2169
}
2184
2170
 
2185
2171
 
2188
2174
  LEX_STRING *file_name= 0;
2189
2175
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2190
2176
  st_add_schema_table add_data;
2191
 
  DBUG_ENTER("schema_tables_add");
2192
2177
 
2193
2178
  for (; tmp_schema_table->table_name; tmp_schema_table++)
2194
2179
  {
2211
2196
                              strlen(tmp_schema_table->table_name), TRUE)) &&
2212
2197
        !files->push_back(file_name))
2213
2198
      continue;
2214
 
    DBUG_RETURN(1);
 
2199
    return(1);
2215
2200
  }
2216
2201
 
2217
2202
  add_data.files= files;
2218
2203
  add_data.wild= wild;
2219
2204
  if (plugin_foreach(thd, add_schema_table,
2220
2205
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data))
2221
 
      DBUG_RETURN(1);
 
2206
      return(1);
2222
2207
 
2223
 
  DBUG_RETURN(0);
 
2208
  return(0);
2224
2209
}
2225
2210
 
2226
2211
 
2329
2314
    table_list.first;
2330
2315
  TABLE *table= tables->table;
2331
2316
  int error= 1;
2332
 
  DBUG_ENTER("fill_schema_show");
2333
2317
 
2334
2318
  lex->all_selects_list= tables->schema_select_lex;
2335
2319
  /*
2371
2355
                                           table_name));
2372
2356
   thd->temporary_tables= 0;
2373
2357
   close_tables_for_reopen(thd, &show_table_list);
2374
 
   DBUG_RETURN(error);
 
2358
   return(error);
2375
2359
}
2376
2360
 
2377
2361
 
2574
2558
  Query_tables_list query_tables_list_backup;
2575
2559
  uint table_open_method;
2576
2560
  bool old_value= thd->no_warnings_for_error;
2577
 
  DBUG_ENTER("get_all_tables");
2578
2561
 
2579
2562
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2580
2563
 
2588
2571
  schema_table_idx= get_schema_table_idx(schema_table);
2589
2572
  tables->table_open_method= table_open_method=
2590
2573
    get_table_open_method(tables, schema_table, schema_table_idx);
2591
 
  DBUG_PRINT("open_method", ("%d", tables->table_open_method));
2592
2574
  /* 
2593
2575
    this branch processes SHOW FIELDS, SHOW INDEXES commands.
2594
2576
    see sql_parse.cc, prepare_schema_table() function where
2606
2588
    error= 0;
2607
2589
    goto err;
2608
2590
  }
2609
 
  DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
2610
 
                             STR_OR_NIL(lookup_field_vals.db_value.str),
2611
 
                             STR_OR_NIL(lookup_field_vals.table_value.str)));
2612
2591
 
2613
2592
  if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2614
2593
  {
2785
2764
  lex->all_selects_list= old_all_select_lex;
2786
2765
  lex->sql_command= save_sql_command;
2787
2766
  thd->no_warnings_for_error= old_value;
2788
 
  DBUG_RETURN(error);
 
2767
  return(error);
2789
2768
}
2790
2769
 
2791
2770
 
2813
2792
  bool with_i_schema;
2814
2793
  HA_CREATE_INFO create;
2815
2794
  TABLE *table= tables->table;
2816
 
  DBUG_ENTER("fill_schema_shemata");
2817
2795
 
2818
2796
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2819
 
    DBUG_RETURN(0);
2820
 
  DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
2821
 
                             lookup_field_vals.db_value.str,
2822
 
                             lookup_field_vals.table_value.str));
 
2797
    return(0);
2823
2798
  if (make_db_list(thd, &db_names, &lookup_field_vals,
2824
2799
                   &with_i_schema))
2825
 
    DBUG_RETURN(1);
 
2800
    return(1);
2826
2801
 
2827
2802
  /*
2828
2803
    If we have lookup db value we should check that the database exists
2834
2809
    uint path_len;
2835
2810
    struct stat stat_info;
2836
2811
    if (!lookup_field_vals.db_value.str[0])
2837
 
      DBUG_RETURN(0);
 
2812
      return(0);
2838
2813
    path_len= build_table_filename(path, sizeof(path),
2839
2814
                                   lookup_field_vals.db_value.str, "", "", 0);
2840
2815
    path[path_len-1]= 0;
2841
2816
    if (stat(path,&stat_info))
2842
 
      DBUG_RETURN(0);
 
2817
      return(0);
2843
2818
  }
2844
2819
 
2845
2820
  List_iterator_fast<LEX_STRING> it(db_names);
2849
2824
    {
2850
2825
      if (store_schema_shemata(thd, table, db_name,
2851
2826
                               system_charset_info))
2852
 
        DBUG_RETURN(1);
 
2827
        return(1);
2853
2828
      with_i_schema= 0;
2854
2829
      continue;
2855
2830
    }
2857
2832
      load_db_opt_by_name(thd, db_name->str, &create);
2858
2833
      if (store_schema_shemata(thd, table, db_name,
2859
2834
                               create.default_table_charset))
2860
 
        DBUG_RETURN(1);
 
2835
        return(1);
2861
2836
    }
2862
2837
  }
2863
 
  DBUG_RETURN(0);
 
2838
  return(0);
2864
2839
}
2865
2840
 
2866
2841
 
2872
2847
  const char *tmp_buff;
2873
2848
  MYSQL_TIME time;
2874
2849
  CHARSET_INFO *cs= system_charset_info;
2875
 
  DBUG_ENTER("get_schema_tables_record");
2876
2850
 
2877
2851
  restore_record(table, s->default_values);
2878
2852
  table->field[1]->store(db_name->str, db_name->length, cs);
3047
3021
      }
3048
3022
    }
3049
3023
  }
3050
 
  DBUG_RETURN(schema_table_store_record(thd, table));
 
3024
  return(schema_table_store_record(thd, table));
3051
3025
}
3052
3026
 
3053
3027
 
3173
3147
  TABLE_SHARE *show_table_share;
3174
3148
  Field **ptr, *field, *timestamp_field;
3175
3149
  int count;
3176
 
  DBUG_ENTER("get_schema_column_record");
3177
3150
 
3178
3151
  if (res)
3179
3152
  {
3189
3162
      thd->clear_error();
3190
3163
      res= 0;
3191
3164
    }
3192
 
    DBUG_RETURN(res);
 
3165
    return(res);
3193
3166
  }
3194
3167
 
3195
3168
  show_table= tables->table;
3216
3189
      uchar *bitmaps;
3217
3190
      uint bitmap_size= show_table_share->column_bitmap_size;
3218
3191
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3219
 
        DBUG_RETURN(0);
 
3192
        return(0);
3220
3193
      bitmap_init(&show_table->def_read_set,
3221
3194
                  (my_bitmap_map*) bitmaps, show_table_share->fields, FALSE);
3222
3195
      bitmap_set_all(&show_table->def_read_set);
3291
3264
                              strlen((const char*) pos), cs);
3292
3265
    }
3293
3266
    if (schema_table_store_record(thd, table))
3294
 
      DBUG_RETURN(1);
 
3267
      return(1);
3295
3268
  }
3296
 
  DBUG_RETURN(0);
 
3269
  return(0);
3297
3270
}
3298
3271
 
3299
3272
 
3406
3379
                                  LEX_STRING *table_name)
3407
3380
{
3408
3381
  CHARSET_INFO *cs= system_charset_info;
3409
 
  DBUG_ENTER("get_schema_stat_record");
3410
3382
  if (res)
3411
3383
  {
3412
3384
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3421
3393
      thd->clear_error();
3422
3394
      res= 0;
3423
3395
    }
3424
 
    DBUG_RETURN(res);
 
3396
    return(res);
3425
3397
  }
3426
3398
  else
3427
3399
  {
3490
3462
          table->field[15]->store(key_info->comment.str, 
3491
3463
                                  key_info->comment.length, cs);
3492
3464
        if (schema_table_store_record(thd, table))
3493
 
          DBUG_RETURN(1);
 
3465
          return(1);
3494
3466
      }
3495
3467
    }
3496
3468
  }
3497
 
  DBUG_RETURN(res);
 
3469
  return(res);
3498
3470
}
3499
3471
 
3500
3472
 
3518
3490
                                         LEX_STRING *db_name,
3519
3491
                                         LEX_STRING *table_name)
3520
3492
{
3521
 
  DBUG_ENTER("get_schema_constraints_record");
3522
3493
  if (res)
3523
3494
  {
3524
3495
    if (thd->is_error())
3525
3496
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3526
3497
                   thd->main_da.sql_errno(), thd->main_da.message());
3527
3498
    thd->clear_error();
3528
 
    DBUG_RETURN(0);
 
3499
    return(0);
3529
3500
  }
3530
3501
  else
3531
3502
  {
3546
3517
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
3547
3518
                              strlen(key_info->name),
3548
3519
                              STRING_WITH_LEN("PRIMARY KEY")))
3549
 
          DBUG_RETURN(1);
 
3520
          return(1);
3550
3521
      }
3551
3522
      else if (key_info->flags & HA_NOSAME)
3552
3523
      {
3553
3524
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
3554
3525
                              strlen(key_info->name),
3555
3526
                              STRING_WITH_LEN("UNIQUE")))
3556
 
          DBUG_RETURN(1);
 
3527
          return(1);
3557
3528
      }
3558
3529
    }
3559
3530
 
3566
3537
                            f_key_info->forein_id->str,
3567
3538
                            strlen(f_key_info->forein_id->str),
3568
3539
                            "FOREIGN KEY", 11))
3569
 
        DBUG_RETURN(1);
 
3540
        return(1);
3570
3541
    }
3571
3542
  }
3572
 
  DBUG_RETURN(res);
 
3543
  return(res);
3573
3544
}
3574
3545
 
3575
3546
 
3594
3565
                                              LEX_STRING *db_name,
3595
3566
                                              LEX_STRING *table_name)
3596
3567
{
3597
 
  DBUG_ENTER("get_schema_key_column_usage_record");
3598
3568
  if (res)
3599
3569
  {
3600
3570
    if (thd->is_error())
3601
3571
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3602
3572
                   thd->main_da.sql_errno(), thd->main_da.message());
3603
3573
    thd->clear_error();
3604
 
    DBUG_RETURN(0);
 
3574
    return(0);
3605
3575
  }
3606
3576
  else
3607
3577
  {
3631
3601
                                 strlen(key_part->field->field_name),
3632
3602
                                 (longlong) f_idx);
3633
3603
          if (schema_table_store_record(thd, table))
3634
 
            DBUG_RETURN(1);
 
3604
            return(1);
3635
3605
        }
3636
3606
      }
3637
3607
    }
3670
3640
                                system_charset_info);
3671
3641
        table->field[11]->set_notnull();
3672
3642
        if (schema_table_store_record(thd, table))
3673
 
          DBUG_RETURN(1);
 
3643
          return(1);
3674
3644
      }
3675
3645
    }
3676
3646
  }
3677
 
  DBUG_RETURN(res);
 
3647
  return(res);
3678
3648
}
3679
3649
 
3680
3650
 
3681
3651
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3682
3652
{
3683
 
  DBUG_ENTER("fill_open_tables");
3684
3653
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3685
3654
  TABLE *table= tables->table;
3686
3655
  CHARSET_INFO *cs= system_charset_info;
3687
3656
  OPEN_TABLE_LIST *open_list;
3688
3657
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3689
3658
            && thd->is_fatal_error)
3690
 
    DBUG_RETURN(1);
 
3659
    return(1);
3691
3660
 
3692
3661
  for (; open_list ; open_list=open_list->next)
3693
3662
  {
3697
3666
    table->field[2]->store((longlong) open_list->in_use, TRUE);
3698
3667
    table->field[3]->store((longlong) open_list->locked, TRUE);
3699
3668
    if (schema_table_store_record(thd, table))
3700
 
      DBUG_RETURN(1);
 
3669
      return(1);
3701
3670
  }
3702
 
  DBUG_RETURN(0);
 
3671
  return(0);
3703
3672
}
3704
3673
 
3705
3674
 
3706
3675
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond)
3707
3676
{
3708
 
  DBUG_ENTER("fill_variables");
3709
3677
  int res= 0;
3710
3678
  LEX *lex= thd->lex;
3711
3679
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3723
3691
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3724
3692
                         option_type, NULL, "", tables->table, upper_case_names);
3725
3693
  rw_unlock(&LOCK_system_variables_hash);
3726
 
  DBUG_RETURN(res);
 
3694
  return(res);
3727
3695
}
3728
3696
 
3729
3697
 
3730
3698
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
3731
3699
{
3732
 
  DBUG_ENTER("fill_status");
3733
3700
  LEX *lex= thd->lex;
3734
3701
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3735
3702
  int res= 0;
3766
3733
                         option_type, tmp1, "", tables->table,
3767
3734
                         upper_case_names);
3768
3735
  pthread_mutex_unlock(&LOCK_status);
3769
 
  DBUG_RETURN(res);
 
3736
  return(res);
3770
3737
}
3771
3738
 
3772
3739
 
3794
3761
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3795
3762
{
3796
3763
  CHARSET_INFO *cs= system_charset_info;
3797
 
  DBUG_ENTER("get_referential_constraints_record");
3798
3764
 
3799
3765
  if (res)
3800
3766
  {
3802
3768
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3803
3769
                   thd->main_da.sql_errno(), thd->main_da.message());
3804
3770
    thd->clear_error();
3805
 
    DBUG_RETURN(0);
 
3771
    return(0);
3806
3772
  }
3807
3773
 
3808
3774
  {
3840
3806
      table->field[8]->store(f_key_info->delete_method->str, 
3841
3807
                             f_key_info->delete_method->length, cs);
3842
3808
      if (schema_table_store_record(thd, table))
3843
 
        DBUG_RETURN(1);
 
3809
        return(1);
3844
3810
    }
3845
3811
  }
3846
 
  DBUG_RETURN(0);
 
3812
  return(0);
3847
3813
}
3848
3814
 
3849
3815
 
3873
3839
  schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3874
3840
  const char* table_name= p_schema_table->table_name;
3875
3841
  ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
3876
 
  DBUG_ENTER("find_schema_table_in_plugin");
3877
3842
 
3878
3843
  if (!my_strcasecmp(system_charset_info,
3879
3844
                     schema_table->table_name,
3880
3845
                     table_name)) {
3881
3846
    p_schema_table->schema_table= schema_table;
3882
 
    DBUG_RETURN(1);
 
3847
    return(1);
3883
3848
  }
3884
3849
 
3885
 
  DBUG_RETURN(0);
 
3850
  return(0);
3886
3851
}
3887
3852
 
3888
3853
 
3903
3868
{
3904
3869
  schema_table_ref schema_table_a;
3905
3870
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3906
 
  DBUG_ENTER("find_schema_table");
3907
3871
 
3908
3872
  for (; schema_table->table_name; schema_table++)
3909
3873
  {
3910
3874
    if (!my_strcasecmp(system_charset_info,
3911
3875
                       schema_table->table_name,
3912
3876
                       table_name))
3913
 
      DBUG_RETURN(schema_table);
 
3877
      return(schema_table);
3914
3878
  }
3915
3879
 
3916
3880
  schema_table_a.table_name= table_name;
3917
3881
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
3918
3882
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3919
 
    DBUG_RETURN(schema_table_a.schema_table);
 
3883
    return(schema_table_a.schema_table);
3920
3884
 
3921
 
  DBUG_RETURN(NULL);
 
3885
  return(NULL);
3922
3886
}
3923
3887
 
3924
3888
 
3958
3922
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3959
3923
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3960
3924
  CHARSET_INFO *cs= system_charset_info;
3961
 
  DBUG_ENTER("create_schema_table");
3962
3925
 
3963
3926
  for (; fields_info->field_name; fields_info++)
3964
3927
  {
3973
3936
                                      fields_info->field_type,
3974
3937
                                      fields_info->value)))
3975
3938
      {
3976
 
        DBUG_RETURN(0);
 
3939
        return(0);
3977
3940
      }
3978
3941
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3979
3942
      break;
3984
3947
      if (!(item=new Item_return_date_time(fields_info->field_name,
3985
3948
                                           fields_info->field_type)))
3986
3949
      {
3987
 
        DBUG_RETURN(0);
 
3950
        return(0);
3988
3951
      }
3989
3952
      break;
3990
3953
    case MYSQL_TYPE_FLOAT:
3991
3954
    case MYSQL_TYPE_DOUBLE:
3992
3955
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC, 
3993
3956
                           fields_info->field_length)) == NULL)
3994
 
        DBUG_RETURN(NULL);
 
3957
        return(NULL);
3995
3958
      break;
3996
3959
    case MYSQL_TYPE_DECIMAL:
3997
3960
    case MYSQL_TYPE_NEWDECIMAL:
3998
3961
      if (!(item= new Item_decimal((longlong) fields_info->value, false)))
3999
3962
      {
4000
 
        DBUG_RETURN(0);
 
3963
        return(0);
4001
3964
      }
4002
3965
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
4003
3966
      item->decimals= fields_info->field_length%10;
4016
3979
      if (!(item= new Item_blob(fields_info->field_name,
4017
3980
                                fields_info->field_length)))
4018
3981
      {
4019
 
        DBUG_RETURN(0);
 
3982
        return(0);
4020
3983
      }
4021
3984
      break;
4022
3985
    default:
4025
3988
 
4026
3989
      if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
4027
3990
      {
4028
 
        DBUG_RETURN(0);
 
3991
        return(0);
4029
3992
      }
4030
3993
      item->set_name(fields_info->field_name,
4031
3994
                     strlen(fields_info->field_name), cs);
4047
4010
                                (select_lex->options | thd->options |
4048
4011
                                 TMP_TABLE_ALL_COLUMNS),
4049
4012
                                HA_POS_ERROR, table_list->alias)))
4050
 
    DBUG_RETURN(0);
 
4013
    return(0);
4051
4014
  my_bitmap_map* bitmaps=
4052
4015
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
4053
4016
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
4055
4018
  table->read_set= &table->def_read_set;
4056
4019
  bitmap_clear_all(table->read_set);
4057
4020
  table_list->schema_table_param= tmp_table_param;
4058
 
  DBUG_RETURN(table);
 
4021
  return(table);
4059
4022
}
4060
4023
 
4061
4024
 
4234
4197
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4235
4198
{
4236
4199
  TABLE *table;
4237
 
  DBUG_ENTER("mysql_schema_table");
4238
4200
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4239
 
    DBUG_RETURN(1);
 
4201
    return(1);
4240
4202
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4241
4203
  /*
4242
4204
    This test is necessary to make
4269
4231
      {
4270
4232
        if (!transl->item->fixed &&
4271
4233
            transl->item->fix_fields(thd, &transl->item))
4272
 
          DBUG_RETURN(1);
 
4234
          return(1);
4273
4235
      }
4274
 
      DBUG_RETURN(0);
 
4236
      return(0);
4275
4237
    }
4276
4238
    List_iterator_fast<Item> it(sel->item_list);
4277
4239
    if (!(transl=
4279
4241
                              alloc(sel->item_list.elements *
4280
4242
                                    sizeof(Field_translator)))))
4281
4243
    {
4282
 
      DBUG_RETURN(1);
 
4244
      return(1);
4283
4245
    }
4284
4246
    for (org_transl= transl; (item= it++); transl++)
4285
4247
    {
4287
4249
      transl->name= item->name;
4288
4250
      if (!item->fixed && item->fix_fields(thd, &transl->item))
4289
4251
      {
4290
 
        DBUG_RETURN(1);
 
4252
        return(1);
4291
4253
      }
4292
4254
    }
4293
4255
    table_list->field_translation= org_transl;
4294
4256
    table_list->field_translation_end= transl;
4295
4257
  }
4296
4258
 
4297
 
  DBUG_RETURN(0);
 
4259
  return(0);
4298
4260
}
4299
4261
 
4300
4262
 
4317
4279
{
4318
4280
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4319
4281
  LEX_STRING db, table;
4320
 
  DBUG_ENTER("make_schema_select");
4321
 
  DBUG_PRINT("enter", ("mysql_schema_select: %s", schema_table->table_name));
4322
4282
  /*
4323
4283
     We have to make non const db_name & table_name
4324
4284
     because of lower_case_table_names
4331
4291
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4332
4292
                              0, 0, TL_READ))
4333
4293
  {
4334
 
    DBUG_RETURN(1);
 
4294
    return(1);
4335
4295
  }
4336
 
  DBUG_RETURN(0);
 
4296
  return(0);
4337
4297
}
4338
4298
 
4339
4299
 
4357
4317
  THD *thd= join->thd;
4358
4318
  LEX *lex= thd->lex;
4359
4319
  bool result= 0;
4360
 
  DBUG_ENTER("get_schema_tables_result");
4361
4320
 
4362
4321
  thd->no_warnings_for_error= 1;
4363
4322
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4421
4380
    }
4422
4381
  }
4423
4382
  thd->no_warnings_for_error= 0;
4424
 
  DBUG_RETURN(result);
 
4383
  return(result);
4425
4384
}
4426
4385
 
4427
4386
ST_FIELD_INFO schema_fields_info[]=
4867
4826
int initialize_schema_table(st_plugin_int *plugin)
4868
4827
{
4869
4828
  ST_SCHEMA_TABLE *schema_table;
4870
 
  DBUG_ENTER("initialize_schema_table");
4871
4829
 
4872
4830
  if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4873
4831
                                MYF(MY_WME | MY_ZEROFILL))))
4874
 
      DBUG_RETURN(1);
 
4832
      return(1);
4875
4833
  /* Historical Requirement */
4876
4834
  plugin->data= schema_table; // shortcut for the future
4877
4835
  if (plugin->plugin->init)
4895
4853
    schema_table->table_name= plugin->name.str;
4896
4854
  }
4897
4855
 
4898
 
  DBUG_RETURN(0);
 
4856
  return(0);
4899
4857
err:
4900
4858
  my_free(schema_table, MYF(0));
4901
 
  DBUG_RETURN(1);
 
4859
  return(1);
4902
4860
}
4903
4861
 
4904
4862
int finalize_schema_table(st_plugin_int *plugin)
4905
4863
{
4906
4864
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4907
 
  DBUG_ENTER("finalize_schema_table");
4908
4865
 
4909
4866
  if (schema_table && plugin->plugin->deinit)
4910
 
  {
4911
 
    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
4912
 
    if (plugin->plugin->deinit(NULL))
4913
 
    {
4914
 
      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
4915
 
                             plugin->name.str));
4916
 
    }
4917
4867
    my_free(schema_table, MYF(0));
4918
 
  }
4919
 
  DBUG_RETURN(0);
 
4868
 
 
4869
  return(0);
4920
4870
}