~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_show.cc

Merged in Jay's tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
    db                  database name to set in TABLE_LIST structure
204
204
    path                path to database
205
205
    wild                filter for found files
206
 
    dir                 read databases in path if TRUE, read .frm files in
 
206
    dir                 read databases in path if true, read .frm files in
207
207
                        database otherwise
208
208
 
209
209
  RETURN
272
272
      if (wild && wild_compare(uname, wild, 0))
273
273
        continue;
274
274
      if (!(file_name= 
275
 
            thd->make_lex_string(file_name, uname, file_name_len, TRUE)))
 
275
            thd->make_lex_string(file_name, uname, file_name_len, true)))
276
276
      {
277
277
        my_dirend(dirp);
278
278
        return(FIND_FILES_OOM);
298
298
      }
299
299
    }
300
300
    if (!(file_name= 
301
 
          thd->make_lex_string(file_name, uname, file_name_len, TRUE)) ||
 
301
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
302
302
        files->push_back(file_name))
303
303
    {
304
304
      my_dirend(dirp);
322
322
  if (open_normal_and_derived_tables(thd, table_list, 0))
323
323
  {
324
324
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
325
 
      return(TRUE);
 
325
      return(true);
326
326
 
327
327
    /*
328
328
      Clear all messages with 'error' level status and
336
336
  buffer.length(0);
337
337
 
338
338
  if (store_create_info(thd, table_list, &buffer, NULL))
339
 
    return(TRUE);
 
339
    return(true);
340
340
 
341
341
  List<Item> field_list;
342
342
  {
348
348
 
349
349
  if (protocol->send_fields(&field_list,
350
350
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
351
 
    return(TRUE);
 
351
    return(true);
352
352
  protocol->prepare_for_resend();
353
353
  {
354
354
    if (table_list->schema_table)
361
361
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
362
362
 
363
363
  if (protocol->write())
364
 
    return(TRUE);
 
364
    return(true);
365
365
 
366
366
  my_eof(thd);
367
 
  return(FALSE);
 
367
  return(false);
368
368
}
369
369
 
370
370
bool mysqld_show_create_db(THD *thd, char *dbname,
381
381
      can fail is incorrect database name (which is the case now).
382
382
    */
383
383
    my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
384
 
    return(TRUE);    
 
384
    return(true);    
385
385
  }
386
386
 
387
387
  List<Item> field_list;
390
390
 
391
391
  if (protocol->send_fields(&field_list,
392
392
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
393
 
    return(TRUE);
 
393
    return(true);
394
394
 
395
395
  protocol->prepare_for_resend();
396
396
  protocol->store(dbname, strlen(dbname), system_charset_info);
397
397
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
398
398
 
399
399
  if (protocol->write())
400
 
    return(TRUE);
 
400
    return(true);
401
401
  my_eof(thd);
402
 
  return(FALSE);
 
402
  return(false);
403
403
}
404
404
 
405
405
 
455
455
static const char *require_quotes(const char *name, uint name_length)
456
456
{
457
457
  uint length;
458
 
  bool pure_digit= TRUE;
 
458
  bool pure_digit= true;
459
459
  const char *end= name + name_length;
460
460
 
461
461
  for (; name < end ; name++)
465
465
    if (length == 1 && !system_charset_info->ident_map[chr])
466
466
      return name;
467
467
    if (length == 1 && (chr < '0' || chr > '9'))
468
 
      pure_digit= FALSE;
 
468
      pure_digit= false;
469
469
  }
470
470
  if (pure_digit)
471
471
    return name;
674
674
  handler *file= table->file;
675
675
  TABLE_SHARE *share= table->s;
676
676
  HA_CREATE_INFO create_info;
677
 
  bool show_table_options= FALSE;
 
677
  bool show_table_options= false;
678
678
  my_bitmap_map *old_map;
679
679
 
680
680
  restore_record(table, s->default_values); // Get empty record
861
861
 
862
862
  packet->append(STRING_WITH_LEN("\n)"));
863
863
  {
864
 
    show_table_options= TRUE;
 
864
    show_table_options= true;
865
865
    /*
866
866
      Get possible table space definitions and append them
867
867
      to the CREATE TABLE statement
1009
1009
  @param  create_info   If not NULL, the options member influences the resulting 
1010
1010
                        CRATE statement.
1011
1011
 
1012
 
  @returns TRUE if errors are detected, FALSE otherwise.
 
1012
  @returns true if errors are detected, false otherwise.
1013
1013
*/
1014
1014
 
1015
1015
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
1027
1027
  else
1028
1028
  {
1029
1029
    if (check_db_dir_existence(dbname))
1030
 
      return(TRUE);
 
1030
      return(true);
1031
1031
 
1032
1032
    load_db_opt_by_name(thd, dbname, &create);
1033
1033
  }
1055
1055
    buffer->append(STRING_WITH_LEN(" */"));
1056
1056
  }
1057
1057
 
1058
 
  return(FALSE);
 
1058
  return(false);
1059
1059
}
1060
1060
 
1061
1061
static void store_key_options(THD *thd __attribute__((__unused__)),
1249
1249
 
1250
1250
      restore_record(table, s->default_values);
1251
1251
      /* ID */
1252
 
      table->field[0]->store((int64_t) tmp->thread_id, TRUE);
 
1252
      table->field[0]->store((int64_t) tmp->thread_id, true);
1253
1253
      /* USER */
1254
1254
      val= tmp_sctx->user ? tmp_sctx->user :
1255
1255
            (tmp->system_thread ? "system user" : "unauthenticated user");
1274
1274
                               command_name[tmp->command].length, cs);
1275
1275
      /* MYSQL_TIME */
1276
1276
      table->field[5]->store((uint32)(tmp->start_time ?
1277
 
                                      now - tmp->start_time : 0), TRUE);
 
1277
                                      now - tmp->start_time : 0), true);
1278
1278
      /* STATE */
1279
1279
      val= (char*) (tmp->net.reading_or_writing ?
1280
1280
                    (tmp->net.reading_or_writing == 2 ?
1638
1638
        pthread_mutex_unlock(&LOCK_global_system_variables);
1639
1639
 
1640
1640
        if (schema_table_store_record(thd, table))
1641
 
          return(TRUE);
 
1641
          return(true);
1642
1642
      }
1643
1643
    }
1644
1644
  }
1645
1645
 
1646
 
  return(FALSE);
 
1646
  return(false);
1647
1647
}
1648
1648
 
1649
1649
 
1789
1789
                               strlen(item_field->field_name), 0))
1790
1790
    {
1791
1791
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1792
 
                           tmp_str->length(), FALSE);
 
1792
                           tmp_str->length(), false);
1793
1793
    }
1794
1794
    /* Lookup value is table name */
1795
1795
    else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1798
1798
                                    strlen(item_field->field_name), 0))
1799
1799
    {
1800
1800
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1801
 
                           tmp_str->length(), FALSE);
 
1801
                           tmp_str->length(), false);
1802
1802
    }
1803
1803
  }
1804
1804
  return 0;
2038
2038
  LEX_STRING *i_s_name_copy= 0;
2039
2039
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2040
2040
                                      INFORMATION_SCHEMA_NAME.str,
2041
 
                                      INFORMATION_SCHEMA_NAME.length, TRUE);
 
2041
                                      INFORMATION_SCHEMA_NAME.length, true);
2042
2042
  *with_i_schema= 0;
2043
2043
  if (lookup_field_vals->wild_db_value)
2044
2044
  {
2125
2125
 
2126
2126
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2127
2127
                                       strlen(schema_table->table_name),
2128
 
                                       TRUE)) &&
 
2128
                                       true)) &&
2129
2129
      !file_list->push_back(file_name))
2130
2130
    return(0);
2131
2131
  return(1);
2156
2156
    }
2157
2157
    if ((file_name= 
2158
2158
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
2159
 
                              strlen(tmp_schema_table->table_name), TRUE)) &&
 
2159
                              strlen(tmp_schema_table->table_name), true)) &&
2160
2160
        !files->push_back(file_name))
2161
2161
      continue;
2162
2162
    return(1);
2182
2182
  @param[in]      table_names           List of table names in database
2183
2183
  @param[in]      lex                   pointer to LEX struct
2184
2184
  @param[in]      lookup_field_vals     pointer to LOOKUP_FIELD_VALUE struct
2185
 
  @param[in]      with_i_schema         TRUE means that we add I_S tables to list
 
2185
  @param[in]      with_i_schema         true means that we add I_S tables to list
2186
2186
  @param[in]      db_name               database name
2187
2187
 
2188
2188
  @return         Operation status
2308
2308
    'show columns' & 'show statistics' commands).
2309
2309
  */
2310
2310
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2311
 
                                    strlen(show_table_list->alias), FALSE);
 
2311
                                    strlen(show_table_list->alias), false);
2312
2312
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2313
 
                                 show_table_list->db_length, FALSE);
 
2313
                                 show_table_list->db_length, false);
2314
2314
      
2315
2315
 
2316
2316
   error= test(schema_table->process_table(thd, show_table_list,
2329
2329
  @param[in]      table                    TABLE struct for I_S table
2330
2330
  @param[in]      db_name                  database name
2331
2331
  @param[in]      table_name               table name
2332
 
  @param[in]      with_i_schema            I_S table if TRUE
 
2332
  @param[in]      with_i_schema            I_S table if true
2333
2333
 
2334
2334
  @return         Operation status
2335
2335
    @retval       0           success
2568
2568
 
2569
2569
  if (lookup_field_vals.db_value.length &&
2570
2570
      !lookup_field_vals.wild_db_value)
2571
 
    tables->has_db_lookup_value= TRUE;
 
2571
    tables->has_db_lookup_value= true;
2572
2572
  if (lookup_field_vals.table_value.length &&
2573
2573
      !lookup_field_vals.wild_table_value) 
2574
 
    tables->has_table_lookup_value= TRUE;
 
2574
    tables->has_table_lookup_value= true;
2575
2575
 
2576
2576
  if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2577
2577
    partial_cond= 0;
2654
2654
            sel.parent_lex= lex;
2655
2655
            /* db_name can be changed in make_table_list() func */
2656
2656
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
2657
 
                                      db_name->length, FALSE))
 
2657
                                      db_name->length, false))
2658
2658
              goto err;
2659
2659
            if (make_table_list(thd, &sel, db_name, table_name))
2660
2660
              goto err;
2697
2697
                in this case.
2698
2698
              */
2699
2699
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2700
 
                                   strlen(show_table_list->alias), FALSE);
 
2700
                                   strlen(show_table_list->alias), false);
2701
2701
              res= schema_table->process_table(thd, show_table_list, table,
2702
2702
                                               res, &orig_db_name,
2703
2703
                                               &tmp_lex_string);
2847
2847
    }
2848
2848
    tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2849
2849
    table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2850
 
    table->field[5]->store((int64_t) share->frm_version, TRUE);
 
2850
    table->field[5]->store((int64_t) share->frm_version, true);
2851
2851
 
2852
2852
    ptr=option_buff;
2853
2853
    if (share->min_rows)
2936
2936
      table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2937
2937
      if (!tables->schema_table)
2938
2938
      {
2939
 
        table->field[7]->store((int64_t) file->stats.records, TRUE);
 
2939
        table->field[7]->store((int64_t) file->stats.records, true);
2940
2940
        table->field[7]->set_notnull();
2941
2941
      }
2942
 
      table->field[8]->store((int64_t) file->stats.mean_rec_length, TRUE);
2943
 
      table->field[9]->store((int64_t) file->stats.data_file_length, TRUE);
 
2942
      table->field[8]->store((int64_t) file->stats.mean_rec_length, true);
 
2943
      table->field[9]->store((int64_t) file->stats.data_file_length, true);
2944
2944
      if (file->stats.max_data_file_length)
2945
2945
      {
2946
2946
        table->field[10]->store((int64_t) file->stats.max_data_file_length,
2947
 
                                TRUE);
 
2947
                                true);
2948
2948
      }
2949
 
      table->field[11]->store((int64_t) file->stats.index_file_length, TRUE);
2950
 
      table->field[12]->store((int64_t) file->stats.delete_length, TRUE);
 
2949
      table->field[11]->store((int64_t) file->stats.index_file_length, true);
 
2950
      table->field[12]->store((int64_t) file->stats.delete_length, true);
2951
2951
      if (show_table->found_next_number_field)
2952
2952
      {
2953
2953
        table->field[13]->store((int64_t) file->stats.auto_increment_value,
2954
 
                                TRUE);
 
2954
                                true);
2955
2955
        table->field[13]->set_notnull();
2956
2956
      }
2957
2957
      if (file->stats.create_time)
2977
2977
      }
2978
2978
      if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2979
2979
      {
2980
 
        table->field[18]->store((int64_t) file->checksum(), TRUE);
 
2980
        table->field[18]->store((int64_t) file->checksum(), true);
2981
2981
        table->field[18]->set_notnull();
2982
2982
      }
2983
2983
    }
3028
3028
      (int64_t) octet_max_length / field->charset()->mbminlen :
3029
3029
      (int64_t) octet_max_length / field->charset()->mbmaxlen;
3030
3030
    /* CHARACTER_MAXIMUM_LENGTH column*/
3031
 
    table->field[offset + 1]->store(char_max_len, TRUE);
 
3031
    table->field[offset + 1]->store(char_max_len, true);
3032
3032
    table->field[offset + 1]->set_notnull();
3033
3033
    /* CHARACTER_OCTET_LENGTH column */
3034
 
    table->field[offset + 2]->store((int64_t) octet_max_length, TRUE);
 
3034
    table->field[offset + 2]->store((int64_t) octet_max_length, true);
3035
3035
    table->field[offset + 2]->set_notnull();
3036
3036
  }
3037
3037
 
3065
3065
  /* NUMERIC_PRECISION column */
3066
3066
  if (field_length >= 0)
3067
3067
  {
3068
 
    table->field[offset + 3]->store((int64_t) field_length, TRUE);
 
3068
    table->field[offset + 3]->store((int64_t) field_length, true);
3069
3069
    table->field[offset + 3]->set_notnull();
3070
3070
  }
3071
3071
  /* NUMERIC_SCALE column */
3072
3072
  if (decimals >= 0)
3073
3073
  {
3074
 
    table->field[offset + 4]->store((int64_t) decimals, TRUE);
 
3074
    table->field[offset + 4]->store((int64_t) decimals, true);
3075
3075
    table->field[offset + 4]->set_notnull();
3076
3076
  }
3077
3077
  if (field->has_charset())
3144
3144
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3145
3145
        return(0);
3146
3146
      bitmap_init(&show_table->def_read_set,
3147
 
                  (my_bitmap_map*) bitmaps, show_table_share->fields, FALSE);
 
3147
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3148
3148
      bitmap_set_all(&show_table->def_read_set);
3149
3149
      show_table->read_set= &show_table->def_read_set;
3150
3150
    }
3174
3174
    table->field[2]->store(table_name->str, table_name->length, cs);
3175
3175
    table->field[3]->store(field->field_name, strlen(field->field_name),
3176
3176
                           cs);
3177
 
    table->field[4]->store((int64_t) count, TRUE);
 
3177
    table->field[4]->store((int64_t) count, true);
3178
3178
 
3179
3179
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3180
3180
    {
3243
3243
      table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3244
3244
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3245
3245
      table->field[2]->store(comment, strlen(comment), scs);
3246
 
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, TRUE);
 
3246
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3247
3247
      if (schema_table_store_record(thd, table))
3248
3248
        return 1;
3249
3249
    }
3279
3279
        restore_record(table, s->default_values);
3280
3280
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3281
3281
        table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3282
 
        table->field[2]->store((int64_t) tmp_cl->number, TRUE);
 
3282
        table->field[2]->store((int64_t) tmp_cl->number, true);
3283
3283
        tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3284
3284
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3285
3285
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3286
3286
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3287
 
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, TRUE);
 
3287
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3288
3288
        if (schema_table_store_record(thd, table))
3289
3289
          return 1;
3290
3290
      }
3363
3363
        table->field[1]->store(db_name->str, db_name->length, cs);
3364
3364
        table->field[2]->store(table_name->str, table_name->length, cs);
3365
3365
        table->field[3]->store((int64_t) ((key_info->flags &
3366
 
                                            HA_NOSAME) ? 0 : 1), TRUE);
 
3366
                                            HA_NOSAME) ? 0 : 1), true);
3367
3367
        table->field[4]->store(db_name->str, db_name->length, cs);
3368
3368
        table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3369
 
        table->field[6]->store((int64_t) (j+1), TRUE);
 
3369
        table->field[6]->store((int64_t) (j+1), true);
3370
3370
        str=(key_part->field ? key_part->field->field_name :
3371
3371
             "?unknown field?");
3372
3372
        table->field[7]->store(str, strlen(str), cs);
3384
3384
          {
3385
3385
            ha_rows records=(show_table->file->stats.records /
3386
3386
                             key->rec_per_key[j]);
3387
 
            table->field[9]->store((int64_t) records, TRUE);
 
3387
            table->field[9]->store((int64_t) records, true);
3388
3388
            table->field[9]->set_notnull();
3389
3389
          }
3390
3390
          str= show_table->file->index_type(i);
3395
3395
             show_table->s->field[key_part->fieldnr-1]->key_length()))
3396
3396
        {
3397
3397
          table->field[10]->store((int64_t) key_part->length /
3398
 
                                  key_part->field->charset()->mbmaxlen, TRUE);
 
3398
                                  key_part->field->charset()->mbmaxlen, true);
3399
3399
          table->field[10]->set_notnull();
3400
3400
        }
3401
3401
        uint flags= key_part->field ? key_part->field->flags : 0;
3505
3505
  table->field[4]->store(db_name->str, db_name->length, cs);
3506
3506
  table->field[5]->store(table_name->str, table_name->length, cs);
3507
3507
  table->field[6]->store(con_type, con_len, cs);
3508
 
  table->field[7]->store((int64_t) idx, TRUE);
 
3508
  table->field[7]->store((int64_t) idx, true);
3509
3509
}
3510
3510
 
3511
3511
 
3576
3576
                               f_key_info->forein_id->length,
3577
3577
                               f_info->str, f_info->length,
3578
3578
                               (int64_t) f_idx);
3579
 
        table->field[8]->store((int64_t) f_idx, TRUE);
 
3579
        table->field[8]->store((int64_t) f_idx, true);
3580
3580
        table->field[8]->set_notnull();
3581
3581
        table->field[9]->store(f_key_info->referenced_db->str,
3582
3582
                               f_key_info->referenced_db->length,
3613
3613
    restore_record(table, s->default_values);
3614
3614
    table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3615
3615
    table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3616
 
    table->field[2]->store((int64_t) open_list->in_use, TRUE);
3617
 
    table->field[3]->store((int64_t) open_list->locked, TRUE);
 
3616
    table->field[2]->store((int64_t) open_list->in_use, true);
 
3617
    table->field[3]->store((int64_t) open_list->locked, true);
3618
3618
    if (schema_table_store_record(thd, table))
3619
3619
      return(1);
3620
3620
  }
3954
3954
  my_bitmap_map* bitmaps=
3955
3955
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3956
3956
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3957
 
              FALSE);
 
3957
              false);
3958
3958
  table->read_set= &table->def_read_set;
3959
3959
  bitmap_clear_all(table->read_set);
3960
3960
  table_list->schema_table_param= tmp_table_param;
4246
4246
    executed_place place where I_S table processed
4247
4247
 
4248
4248
  RETURN
4249
 
    FALSE success
4250
 
    TRUE  error
 
4249
    false success
 
4250
    true  error
4251
4251
*/
4252
4252
 
4253
4253
bool get_schema_tables_result(JOIN *join,