~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

MergedĀ fromĀ trunk.

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
 
3165
3139
  TABLE_SHARE *show_table_share;
3166
3140
  Field **ptr, *field, *timestamp_field;
3167
3141
  int count;
3168
 
  DBUG_ENTER("get_schema_column_record");
3169
3142
 
3170
3143
  if (res)
3171
3144
  {
3181
3154
      thd->clear_error();
3182
3155
      res= 0;
3183
3156
    }
3184
 
    DBUG_RETURN(res);
 
3157
    return(res);
3185
3158
  }
3186
3159
 
3187
3160
  show_table= tables->table;
3208
3181
      uchar *bitmaps;
3209
3182
      uint bitmap_size= show_table_share->column_bitmap_size;
3210
3183
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3211
 
        DBUG_RETURN(0);
 
3184
        return(0);
3212
3185
      bitmap_init(&show_table->def_read_set,
3213
3186
                  (my_bitmap_map*) bitmaps, show_table_share->fields, FALSE);
3214
3187
      bitmap_set_all(&show_table->def_read_set);
3283
3256
                              strlen((const char*) pos), cs);
3284
3257
    }
3285
3258
    if (schema_table_store_record(thd, table))
3286
 
      DBUG_RETURN(1);
 
3259
      return(1);
3287
3260
  }
3288
 
  DBUG_RETURN(0);
 
3261
  return(0);
3289
3262
}
3290
3263
 
3291
3264
 
3398
3371
                                  LEX_STRING *table_name)
3399
3372
{
3400
3373
  CHARSET_INFO *cs= system_charset_info;
3401
 
  DBUG_ENTER("get_schema_stat_record");
3402
3374
  if (res)
3403
3375
  {
3404
3376
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3413
3385
      thd->clear_error();
3414
3386
      res= 0;
3415
3387
    }
3416
 
    DBUG_RETURN(res);
 
3388
    return(res);
3417
3389
  }
3418
3390
  else
3419
3391
  {
3482
3454
          table->field[15]->store(key_info->comment.str, 
3483
3455
                                  key_info->comment.length, cs);
3484
3456
        if (schema_table_store_record(thd, table))
3485
 
          DBUG_RETURN(1);
 
3457
          return(1);
3486
3458
      }
3487
3459
    }
3488
3460
  }
3489
 
  DBUG_RETURN(res);
 
3461
  return(res);
3490
3462
}
3491
3463
 
3492
3464
 
3510
3482
                                         LEX_STRING *db_name,
3511
3483
                                         LEX_STRING *table_name)
3512
3484
{
3513
 
  DBUG_ENTER("get_schema_constraints_record");
3514
3485
  if (res)
3515
3486
  {
3516
3487
    if (thd->is_error())
3517
3488
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3518
3489
                   thd->main_da.sql_errno(), thd->main_da.message());
3519
3490
    thd->clear_error();
3520
 
    DBUG_RETURN(0);
 
3491
    return(0);
3521
3492
  }
3522
3493
  else
3523
3494
  {
3538
3509
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
3539
3510
                              strlen(key_info->name),
3540
3511
                              STRING_WITH_LEN("PRIMARY KEY")))
3541
 
          DBUG_RETURN(1);
 
3512
          return(1);
3542
3513
      }
3543
3514
      else if (key_info->flags & HA_NOSAME)
3544
3515
      {
3545
3516
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
3546
3517
                              strlen(key_info->name),
3547
3518
                              STRING_WITH_LEN("UNIQUE")))
3548
 
          DBUG_RETURN(1);
 
3519
          return(1);
3549
3520
      }
3550
3521
    }
3551
3522
 
3558
3529
                            f_key_info->forein_id->str,
3559
3530
                            strlen(f_key_info->forein_id->str),
3560
3531
                            "FOREIGN KEY", 11))
3561
 
        DBUG_RETURN(1);
 
3532
        return(1);
3562
3533
    }
3563
3534
  }
3564
 
  DBUG_RETURN(res);
 
3535
  return(res);
3565
3536
}
3566
3537
 
3567
3538
 
3586
3557
                                              LEX_STRING *db_name,
3587
3558
                                              LEX_STRING *table_name)
3588
3559
{
3589
 
  DBUG_ENTER("get_schema_key_column_usage_record");
3590
3560
  if (res)
3591
3561
  {
3592
3562
    if (thd->is_error())
3593
3563
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3594
3564
                   thd->main_da.sql_errno(), thd->main_da.message());
3595
3565
    thd->clear_error();
3596
 
    DBUG_RETURN(0);
 
3566
    return(0);
3597
3567
  }
3598
3568
  else
3599
3569
  {
3623
3593
                                 strlen(key_part->field->field_name),
3624
3594
                                 (longlong) f_idx);
3625
3595
          if (schema_table_store_record(thd, table))
3626
 
            DBUG_RETURN(1);
 
3596
            return(1);
3627
3597
        }
3628
3598
      }
3629
3599
    }
3662
3632
                                system_charset_info);
3663
3633
        table->field[11]->set_notnull();
3664
3634
        if (schema_table_store_record(thd, table))
3665
 
          DBUG_RETURN(1);
 
3635
          return(1);
3666
3636
      }
3667
3637
    }
3668
3638
  }
3669
 
  DBUG_RETURN(res);
 
3639
  return(res);
3670
3640
}
3671
3641
 
3672
3642
 
3673
3643
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3674
3644
{
3675
 
  DBUG_ENTER("fill_open_tables");
3676
3645
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3677
3646
  TABLE *table= tables->table;
3678
3647
  CHARSET_INFO *cs= system_charset_info;
3679
3648
  OPEN_TABLE_LIST *open_list;
3680
3649
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3681
3650
            && thd->is_fatal_error)
3682
 
    DBUG_RETURN(1);
 
3651
    return(1);
3683
3652
 
3684
3653
  for (; open_list ; open_list=open_list->next)
3685
3654
  {
3689
3658
    table->field[2]->store((longlong) open_list->in_use, TRUE);
3690
3659
    table->field[3]->store((longlong) open_list->locked, TRUE);
3691
3660
    if (schema_table_store_record(thd, table))
3692
 
      DBUG_RETURN(1);
 
3661
      return(1);
3693
3662
  }
3694
 
  DBUG_RETURN(0);
 
3663
  return(0);
3695
3664
}
3696
3665
 
3697
3666
 
3698
3667
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond)
3699
3668
{
3700
 
  DBUG_ENTER("fill_variables");
3701
3669
  int res= 0;
3702
3670
  LEX *lex= thd->lex;
3703
3671
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3715
3683
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3716
3684
                         option_type, NULL, "", tables->table, upper_case_names);
3717
3685
  rw_unlock(&LOCK_system_variables_hash);
3718
 
  DBUG_RETURN(res);
 
3686
  return(res);
3719
3687
}
3720
3688
 
3721
3689
 
3722
3690
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
3723
3691
{
3724
 
  DBUG_ENTER("fill_status");
3725
3692
  LEX *lex= thd->lex;
3726
3693
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3727
3694
  int res= 0;
3758
3725
                         option_type, tmp1, "", tables->table,
3759
3726
                         upper_case_names);
3760
3727
  pthread_mutex_unlock(&LOCK_status);
3761
 
  DBUG_RETURN(res);
 
3728
  return(res);
3762
3729
}
3763
3730
 
3764
3731
 
3786
3753
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3787
3754
{
3788
3755
  CHARSET_INFO *cs= system_charset_info;
3789
 
  DBUG_ENTER("get_referential_constraints_record");
3790
3756
 
3791
3757
  if (res)
3792
3758
  {
3794
3760
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3795
3761
                   thd->main_da.sql_errno(), thd->main_da.message());
3796
3762
    thd->clear_error();
3797
 
    DBUG_RETURN(0);
 
3763
    return(0);
3798
3764
  }
3799
3765
 
3800
3766
  {
3832
3798
      table->field[8]->store(f_key_info->delete_method->str, 
3833
3799
                             f_key_info->delete_method->length, cs);
3834
3800
      if (schema_table_store_record(thd, table))
3835
 
        DBUG_RETURN(1);
 
3801
        return(1);
3836
3802
    }
3837
3803
  }
3838
 
  DBUG_RETURN(0);
 
3804
  return(0);
3839
3805
}
3840
3806
 
3841
3807
 
3865
3831
  schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3866
3832
  const char* table_name= p_schema_table->table_name;
3867
3833
  ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
3868
 
  DBUG_ENTER("find_schema_table_in_plugin");
3869
3834
 
3870
3835
  if (!my_strcasecmp(system_charset_info,
3871
3836
                     schema_table->table_name,
3872
3837
                     table_name)) {
3873
3838
    p_schema_table->schema_table= schema_table;
3874
 
    DBUG_RETURN(1);
 
3839
    return(1);
3875
3840
  }
3876
3841
 
3877
 
  DBUG_RETURN(0);
 
3842
  return(0);
3878
3843
}
3879
3844
 
3880
3845
 
3895
3860
{
3896
3861
  schema_table_ref schema_table_a;
3897
3862
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3898
 
  DBUG_ENTER("find_schema_table");
3899
3863
 
3900
3864
  for (; schema_table->table_name; schema_table++)
3901
3865
  {
3902
3866
    if (!my_strcasecmp(system_charset_info,
3903
3867
                       schema_table->table_name,
3904
3868
                       table_name))
3905
 
      DBUG_RETURN(schema_table);
 
3869
      return(schema_table);
3906
3870
  }
3907
3871
 
3908
3872
  schema_table_a.table_name= table_name;
3909
3873
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
3910
3874
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3911
 
    DBUG_RETURN(schema_table_a.schema_table);
 
3875
    return(schema_table_a.schema_table);
3912
3876
 
3913
 
  DBUG_RETURN(NULL);
 
3877
  return(NULL);
3914
3878
}
3915
3879
 
3916
3880
 
3944
3908
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3945
3909
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3946
3910
  CHARSET_INFO *cs= system_charset_info;
3947
 
  DBUG_ENTER("create_schema_table");
3948
3911
 
3949
3912
  for (; fields_info->field_name; fields_info++)
3950
3913
  {
3958
3921
                                      fields_info->field_type,
3959
3922
                                      fields_info->value)))
3960
3923
      {
3961
 
        DBUG_RETURN(0);
 
3924
        return(0);
3962
3925
      }
3963
3926
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3964
3927
      break;
3965
 
    case MYSQL_TYPE_DATE:
 
3928
    case MYSQL_TYPE_NEWDATE:
3966
3929
    case MYSQL_TYPE_TIME:
3967
3930
    case MYSQL_TYPE_TIMESTAMP:
3968
3931
    case MYSQL_TYPE_DATETIME:
3969
3932
      if (!(item=new Item_return_date_time(fields_info->field_name,
3970
3933
                                           fields_info->field_type)))
3971
3934
      {
3972
 
        DBUG_RETURN(0);
 
3935
        return(0);
3973
3936
      }
3974
3937
      break;
3975
3938
    case MYSQL_TYPE_FLOAT:
3976
3939
    case MYSQL_TYPE_DOUBLE:
3977
3940
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC, 
3978
3941
                           fields_info->field_length)) == NULL)
3979
 
        DBUG_RETURN(NULL);
 
3942
        return(NULL);
3980
3943
      break;
3981
3944
    case MYSQL_TYPE_NEWDECIMAL:
3982
3945
      if (!(item= new Item_decimal((longlong) fields_info->value, false)))
3983
3946
      {
3984
 
        DBUG_RETURN(0);
 
3947
        return(0);
3985
3948
      }
3986
3949
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3987
3950
      item->decimals= fields_info->field_length%10;
4000
3963
      if (!(item= new Item_blob(fields_info->field_name,
4001
3964
                                fields_info->field_length)))
4002
3965
      {
4003
 
        DBUG_RETURN(0);
 
3966
        return(0);
4004
3967
      }
4005
3968
      break;
4006
3969
    default:
4009
3972
 
4010
3973
      if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
4011
3974
      {
4012
 
        DBUG_RETURN(0);
 
3975
        return(0);
4013
3976
      }
4014
3977
      item->set_name(fields_info->field_name,
4015
3978
                     strlen(fields_info->field_name), cs);
4031
3994
                                (select_lex->options | thd->options |
4032
3995
                                 TMP_TABLE_ALL_COLUMNS),
4033
3996
                                HA_POS_ERROR, table_list->alias)))
4034
 
    DBUG_RETURN(0);
 
3997
    return(0);
4035
3998
  my_bitmap_map* bitmaps=
4036
3999
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
4037
4000
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
4039
4002
  table->read_set= &table->def_read_set;
4040
4003
  bitmap_clear_all(table->read_set);
4041
4004
  table_list->schema_table_param= tmp_table_param;
4042
 
  DBUG_RETURN(table);
 
4005
  return(table);
4043
4006
}
4044
4007
 
4045
4008
 
4218
4181
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4219
4182
{
4220
4183
  TABLE *table;
4221
 
  DBUG_ENTER("mysql_schema_table");
4222
4184
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4223
 
    DBUG_RETURN(1);
 
4185
    return(1);
4224
4186
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4225
4187
  /*
4226
4188
    This test is necessary to make
4253
4215
      {
4254
4216
        if (!transl->item->fixed &&
4255
4217
            transl->item->fix_fields(thd, &transl->item))
4256
 
          DBUG_RETURN(1);
 
4218
          return(1);
4257
4219
      }
4258
 
      DBUG_RETURN(0);
 
4220
      return(0);
4259
4221
    }
4260
4222
    List_iterator_fast<Item> it(sel->item_list);
4261
4223
    if (!(transl=
4263
4225
                              alloc(sel->item_list.elements *
4264
4226
                                    sizeof(Field_translator)))))
4265
4227
    {
4266
 
      DBUG_RETURN(1);
 
4228
      return(1);
4267
4229
    }
4268
4230
    for (org_transl= transl; (item= it++); transl++)
4269
4231
    {
4271
4233
      transl->name= item->name;
4272
4234
      if (!item->fixed && item->fix_fields(thd, &transl->item))
4273
4235
      {
4274
 
        DBUG_RETURN(1);
 
4236
        return(1);
4275
4237
      }
4276
4238
    }
4277
4239
    table_list->field_translation= org_transl;
4278
4240
    table_list->field_translation_end= transl;
4279
4241
  }
4280
4242
 
4281
 
  DBUG_RETURN(0);
 
4243
  return(0);
4282
4244
}
4283
4245
 
4284
4246
 
4301
4263
{
4302
4264
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4303
4265
  LEX_STRING db, table;
4304
 
  DBUG_ENTER("make_schema_select");
4305
 
  DBUG_PRINT("enter", ("mysql_schema_select: %s", schema_table->table_name));
4306
4266
  /*
4307
4267
     We have to make non const db_name & table_name
4308
4268
     because of lower_case_table_names
4315
4275
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4316
4276
                              0, 0, TL_READ))
4317
4277
  {
4318
 
    DBUG_RETURN(1);
 
4278
    return(1);
4319
4279
  }
4320
 
  DBUG_RETURN(0);
 
4280
  return(0);
4321
4281
}
4322
4282
 
4323
4283
 
4341
4301
  THD *thd= join->thd;
4342
4302
  LEX *lex= thd->lex;
4343
4303
  bool result= 0;
4344
 
  DBUG_ENTER("get_schema_tables_result");
4345
4304
 
4346
4305
  thd->no_warnings_for_error= 1;
4347
4306
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4405
4364
    }
4406
4365
  }
4407
4366
  thd->no_warnings_for_error= 0;
4408
 
  DBUG_RETURN(result);
 
4367
  return(result);
4409
4368
}
4410
4369
 
4411
4370
ST_FIELD_INFO schema_fields_info[]=
4851
4810
int initialize_schema_table(st_plugin_int *plugin)
4852
4811
{
4853
4812
  ST_SCHEMA_TABLE *schema_table;
4854
 
  DBUG_ENTER("initialize_schema_table");
4855
4813
 
4856
4814
  if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4857
4815
                                MYF(MY_WME | MY_ZEROFILL))))
4858
 
      DBUG_RETURN(1);
 
4816
      return(1);
4859
4817
  /* Historical Requirement */
4860
4818
  plugin->data= schema_table; // shortcut for the future
4861
4819
  if (plugin->plugin->init)
4879
4837
    schema_table->table_name= plugin->name.str;
4880
4838
  }
4881
4839
 
4882
 
  DBUG_RETURN(0);
 
4840
  return(0);
4883
4841
err:
4884
4842
  my_free(schema_table, MYF(0));
4885
 
  DBUG_RETURN(1);
 
4843
  return(1);
4886
4844
}
4887
4845
 
4888
4846
int finalize_schema_table(st_plugin_int *plugin)
4889
4847
{
4890
4848
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4891
 
  DBUG_ENTER("finalize_schema_table");
4892
4849
 
4893
4850
  if (schema_table && plugin->plugin->deinit)
4894
 
  {
4895
 
    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
4896
 
    if (plugin->plugin->deinit(NULL))
4897
 
    {
4898
 
      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
4899
 
                             plugin->name.str));
4900
 
    }
4901
4851
    my_free(schema_table, MYF(0));
4902
 
  }
4903
 
  DBUG_RETURN(0);
 
4852
 
 
4853
  return(0);
4904
4854
}