206
int CharSetISMethods::fillTable(Session *session, TableList *tables)
209
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
210
Table *table= tables->table;
211
const CHARSET_INFO * const scs= system_charset_info;
213
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
215
const CHARSET_INFO * const tmp_cs= cs[0];
216
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
217
(tmp_cs->state & MY_CS_AVAILABLE) &&
218
!(tmp_cs->state & MY_CS_HIDDEN) &&
220
wild_case_compare(scs, tmp_cs->csname,wild)))
223
table->restoreRecordAsDefault();
224
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
225
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
226
comment= tmp_cs->comment ? tmp_cs->comment : "";
227
table->field[2]->store(comment, strlen(comment), scs);
228
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
229
if (schema_table_store_record(session, table))
236
int CharSetISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
239
int fields_arr[]= {0, 2, 1, 3, -1};
240
int *field_num= fields_arr;
241
const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
242
const drizzled::plugin::ColumnInfo *column;
243
Name_resolution_context *context= &session->lex->select_lex.context;
245
for (; *field_num >= 0; field_num++)
247
column= columns[*field_num];
248
Item_field *field= new Item_field(context,
249
NULL, NULL, column->getName().c_str());
252
field->set_name(column->getOldName().c_str(),
253
column->getOldName().length(),
254
system_charset_info);
255
if (session->add_item_to_list(field))
262
int CollationISMethods::fillTable(Session *session, TableList *tables)
265
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
266
Table *table= tables->table;
267
const CHARSET_INFO * const scs= system_charset_info;
268
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
271
const CHARSET_INFO *tmp_cs= cs[0];
272
if (! tmp_cs || ! (tmp_cs->state & MY_CS_AVAILABLE) ||
273
(tmp_cs->state & MY_CS_HIDDEN) ||
274
!(tmp_cs->state & MY_CS_PRIMARY))
276
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
278
const CHARSET_INFO *tmp_cl= cl[0];
279
if (! tmp_cl || ! (tmp_cl->state & MY_CS_AVAILABLE) ||
280
!my_charset_same(tmp_cs, tmp_cl))
282
if (! (wild && wild[0] &&
283
wild_case_compare(scs, tmp_cl->name,wild)))
285
const char *tmp_buff;
286
table->restoreRecordAsDefault();
287
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
288
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
289
table->field[2]->store((int64_t) tmp_cl->number, true);
290
tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
291
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
292
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
293
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
294
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
295
if (schema_table_store_record(session, table))
303
int CollCharISMethods::fillTable(Session *session, TableList *tables)
306
Table *table= tables->table;
307
const CHARSET_INFO * const scs= system_charset_info;
308
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
311
const CHARSET_INFO *tmp_cs= cs[0];
312
if (! tmp_cs || ! (tmp_cs->state & MY_CS_AVAILABLE) ||
313
! (tmp_cs->state & MY_CS_PRIMARY))
315
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
317
const CHARSET_INFO *tmp_cl= cl[0];
318
if (! tmp_cl || ! (tmp_cl->state & MY_CS_AVAILABLE) ||
319
! my_charset_same(tmp_cs,tmp_cl))
321
table->restoreRecordAsDefault();
322
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
323
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
324
if (schema_table_store_record(session, table))
331
int ColumnsISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
334
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
335
int *field_num= fields_arr;
336
const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
337
const drizzled::plugin::ColumnInfo *column;
338
Name_resolution_context *context= &session->lex->select_lex.context;
340
for (; *field_num >= 0; field_num++)
342
column= columns[*field_num];
343
if (! session->lex->verbose && (*field_num == 13 ||
349
Item_field *field= new Item_field(context,
350
NULL, NULL, column->getName().c_str());
353
field->set_name(column->getOldName().c_str(),
354
column->getOldName().length(),
355
system_charset_info);
356
if (session->add_item_to_list(field))
365
static void store_key_column_usage(Table *table, LEX_STRING *db_name,
366
LEX_STRING *table_name, const char *key_name,
367
uint32_t key_len, const char *con_type, uint32_t con_len,
207
void store_key_column_usage(Table *table,
209
LEX_STRING *table_name,
210
const char *key_name,
212
const char *con_type,
370
216
const CHARSET_INFO * const cs= system_charset_info;
371
217
table->field[1]->store(db_name->str, db_name->length, cs);
376
222
table->field[7]->store((int64_t) idx, true);
379
int KeyColUsageISMethods::processTable(Session *session,
381
Table *table, bool res,
383
LEX_STRING *table_name) const
387
if (session->is_error())
388
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
389
session->main_da.sql_errno(), session->main_da.message());
390
session->clear_error();
395
List<FOREIGN_KEY_INFO> f_key_list;
396
Table *show_table= tables->table;
397
KEY *key_info=show_table->key_info;
398
uint32_t primary_key= show_table->s->primary_key;
399
show_table->cursor->info(HA_STATUS_VARIABLE |
402
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
404
if (i != primary_key && !(key_info->flags & HA_NOSAME))
409
KEY_PART_INFO *key_part= key_info->key_part;
410
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
415
table->restoreRecordAsDefault();
416
store_key_column_usage(table, db_name, table_name,
418
strlen(key_info->name),
419
key_part->field->field_name,
420
strlen(key_part->field->field_name),
422
if (schema_table_store_record(session, table))
430
show_table->cursor->get_foreign_key_list(session, &f_key_list);
431
FOREIGN_KEY_INFO *f_key_info;
432
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
433
while ((f_key_info= fkey_it++))
437
List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
438
it1(f_key_info->referenced_fields);
440
while ((f_info= it++))
444
table->restoreRecordAsDefault();
445
store_key_column_usage(table, db_name, table_name,
446
f_key_info->forein_id->str,
447
f_key_info->forein_id->length,
448
f_info->str, f_info->length,
450
table->field[8]->store((int64_t) f_idx, true);
451
table->field[8]->set_notnull();
452
table->field[9]->store(f_key_info->referenced_db->str,
453
f_key_info->referenced_db->length,
454
system_charset_info);
455
table->field[9]->set_notnull();
456
table->field[10]->store(f_key_info->referenced_table->str,
457
f_key_info->referenced_table->length,
458
system_charset_info);
459
table->field[10]->set_notnull();
460
table->field[11]->store(r_info->str, r_info->length,
461
system_charset_info);
462
table->field[11]->set_notnull();
463
if (schema_table_store_record(session, table))
473
inline bool open_list_store(Table *table, open_table_list_st& open_list);
474
inline bool open_list_store(Table *table, open_table_list_st& open_list)
476
table->restoreRecordAsDefault();
477
table->field[0]->store(open_list.db.c_str(), open_list.db.length(), system_charset_info);
478
table->field[1]->store(open_list.table.c_str(), open_list.table.length(), system_charset_info);
479
table->field[2]->store((int64_t) open_list.in_use, true);
480
table->field[3]->store((int64_t) open_list.locked, true);
481
if (schema_table_store_record(table->in_use, table))
487
int OpenTablesISMethods::fillTable(Session *session, TableList *tables)
489
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
491
if ((list_open_tables(session->lex->select_lex.db, wild, open_list_store, tables->table) == true) && session->is_fatal_error)
497
class ShowModules : public unary_function<drizzled::plugin::Module *, bool>
502
ShowModules(Session *session_arg, Table *table_arg)
503
: session(session_arg), table(table_arg) {}
505
result_type operator() (argument_type module)
507
const drizzled::plugin::Manifest &manifest= module->getManifest();
508
const CHARSET_INFO * const cs= system_charset_info;
510
table->restoreRecordAsDefault();
512
table->field[0]->store(module->getName().c_str(),
513
module->getName().size(), cs);
515
if (manifest.version)
517
table->field[1]->store(manifest.version, strlen(manifest.version), cs);
518
table->field[1]->set_notnull();
521
table->field[1]->set_null();
525
table->field[2]->store(manifest.author, strlen(manifest.author), cs);
526
table->field[2]->set_notnull();
530
table->field[2]->set_null();
533
if (module->plugin_dl == NULL)
535
table->field[3]->store(STRING_WITH_LEN("YES"),cs);
536
table->field[4]->set_null();
540
table->field[3]->store(STRING_WITH_LEN("NO"),cs);
541
table->field[4]->store(module->plugin_dl->dl.str,
542
module->plugin_dl->dl.length, cs);
547
table->field[5]->store(manifest.descr, strlen(manifest.descr), cs);
548
table->field[5]->set_notnull();
552
table->field[5]->set_null();
555
switch (manifest.license) {
556
case PLUGIN_LICENSE_GPL:
557
table->field[6]->store(drizzled::plugin::LICENSE_GPL_STRING.c_str(),
558
drizzled::plugin::LICENSE_GPL_STRING.size(), cs);
560
case PLUGIN_LICENSE_BSD:
561
table->field[6]->store(drizzled::plugin::LICENSE_BSD_STRING.c_str(),
562
drizzled::plugin::LICENSE_BSD_STRING.size(), cs);
564
case PLUGIN_LICENSE_LGPL:
565
table->field[6]->store(drizzled::plugin::LICENSE_LGPL_STRING.c_str(),
566
drizzled::plugin::LICENSE_LGPL_STRING.size(), cs);
569
table->field[6]->store(drizzled::plugin::LICENSE_PROPRIETARY_STRING.c_str(),
570
drizzled::plugin::LICENSE_PROPRIETARY_STRING.size(),
574
table->field[6]->set_notnull();
576
return schema_table_store_record(session, table);
580
int ModulesISMethods::fillTable(Session *session, TableList *tables)
582
Table *table= tables->table;
584
drizzled::plugin::Registry ®istry= drizzled::plugin::Registry::singleton();
585
vector<drizzled::plugin::Module *> modules= registry.getList(true);
586
vector<drizzled::plugin::Module *>::iterator iter=
587
find_if(modules.begin(), modules.end(), ShowModules(session, table));
588
if (iter != modules.end())
596
: public unary_function<pair<const string, const drizzled::plugin::Plugin *>, bool>
601
ShowPlugins(Session *session_arg, Table *table_arg)
602
: session(session_arg), table(table_arg) {}
604
result_type operator() (argument_type plugin)
606
const CHARSET_INFO * const cs= system_charset_info;
608
table->restoreRecordAsDefault();
610
table->field[0]->store(plugin.first.c_str(),
611
plugin.first.size(), cs);
613
table->field[1]->store(plugin.second->getTypeName().c_str(),
614
plugin.second->getTypeName().size(), cs);
616
if (plugin.second->isActive())
618
table->field[2]->store(STRING_WITH_LEN("YES"),cs);
622
table->field[2]->store(STRING_WITH_LEN("NO"), cs);
625
table->field[3]->store(plugin.second->getModuleName().c_str(),
626
plugin.second->getModuleName().size(), cs);
628
return schema_table_store_record(session, table);
632
int PluginsISMethods::fillTable(Session *session, TableList *tables)
634
Table *table= tables->table;
636
drizzled::plugin::Registry ®istry= drizzled::plugin::Registry::singleton();
637
const map<string, const drizzled::plugin::Plugin *> &plugin_map=
638
registry.getPluginsMap();
639
map<string, const drizzled::plugin::Plugin *>::const_iterator iter=
640
find_if(plugin_map.begin(), plugin_map.end(), ShowPlugins(session, table));
641
if (iter != plugin_map.end())
648
int ProcessListISMethods::fillTable(Session* session, TableList* tables)
650
Table *table= tables->table;
651
const CHARSET_INFO * const cs= system_charset_info;
652
time_t now= time(NULL);
655
if (now == (time_t)-1)
658
pthread_mutex_lock(&LOCK_thread_count);
660
if (! session->killed)
664
for (vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it)
667
Security_context *tmp_sctx= &tmp->security_ctx;
668
struct st_my_thread_var *mysys_var;
671
if (! tmp->client->isConnected())
674
table->restoreRecordAsDefault();
676
table->field[0]->store((int64_t) tmp->thread_id, true);
678
val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
679
table->field[1]->store(val, strlen(val), cs);
681
table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
685
table->field[3]->store(tmp->db, strlen(tmp->db), cs);
686
table->field[3]->set_notnull();
689
if ((mysys_var= tmp->mysys_var))
690
pthread_mutex_lock(&mysys_var->mutex);
692
if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
693
table->field[4]->store(val, strlen(val), cs);
695
table->field[4]->store(command_name[tmp->command].str,
696
command_name[tmp->command].length, cs);
698
table->field[5]->store((uint32_t)(tmp->start_time ?
699
now - tmp->start_time : 0), true);
701
val= (char*) (tmp->client->isWriting() ?
703
tmp->client->isReading() ?
704
(tmp->command == COM_SLEEP ?
705
NULL : "Reading from net") :
706
tmp->get_proc_info() ? tmp->get_proc_info() :
708
tmp->mysys_var->current_cond ?
709
"Waiting on cond" : NULL);
712
table->field[6]->store(val, strlen(val), cs);
713
table->field[6]->set_notnull();
717
pthread_mutex_unlock(&mysys_var->mutex);
719
length= strlen(tmp->process_list_info);
723
table->field[7]->store(tmp->process_list_info, length, cs);
724
table->field[7]->set_notnull();
727
if (schema_table_store_record(session, table))
729
pthread_mutex_unlock(&LOCK_thread_count);
735
pthread_mutex_unlock(&LOCK_thread_count);
740
RefConstraintsISMethods::processTable(Session *session, TableList *tables,
741
Table *table, bool res,
742
LEX_STRING *db_name, LEX_STRING *table_name)
745
const CHARSET_INFO * const cs= system_charset_info;
749
if (session->is_error())
750
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
751
session->main_da.sql_errno(), session->main_da.message());
752
session->clear_error();
757
List<FOREIGN_KEY_INFO> f_key_list;
758
Table *show_table= tables->table;
759
show_table->cursor->info(HA_STATUS_VARIABLE |
763
show_table->cursor->get_foreign_key_list(session, &f_key_list);
764
FOREIGN_KEY_INFO *f_key_info;
765
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
766
while ((f_key_info= it++))
768
table->restoreRecordAsDefault();
769
table->field[1]->store(db_name->str, db_name->length, cs);
770
table->field[9]->store(table_name->str, table_name->length, cs);
771
table->field[2]->store(f_key_info->forein_id->str,
772
f_key_info->forein_id->length, cs);
773
table->field[4]->store(f_key_info->referenced_db->str,
774
f_key_info->referenced_db->length, cs);
775
table->field[10]->store(f_key_info->referenced_table->str,
776
f_key_info->referenced_table->length, cs);
777
if (f_key_info->referenced_key_name)
779
table->field[5]->store(f_key_info->referenced_key_name->str,
780
f_key_info->referenced_key_name->length, cs);
781
table->field[5]->set_notnull();
785
table->field[5]->set_null();
787
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
788
table->field[7]->store(f_key_info->update_method->str,
789
f_key_info->update_method->length, cs);
790
table->field[8]->store(f_key_info->delete_method->str,
791
f_key_info->delete_method->length, cs);
792
if (schema_table_store_record(session, table))
801
static bool store_schema_schemata(Session* session, Table *table, LEX_STRING *db_name,
802
const CHARSET_INFO * const cs)
804
table->restoreRecordAsDefault();
805
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
806
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
807
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
808
return schema_table_store_record(session, table);
811
int SchemataISMethods::fillTable(Session *session, TableList *tables)
814
TODO: fill_schema_shemata() is called when new client is connected.
815
Returning error status in this case leads to client hangup.
818
LOOKUP_FIELD_VALUES lookup_field_vals;
819
vector<LEX_STRING*> db_names;
821
Table *table= tables->table;
822
/* the WHERE condition */
823
COND *cond= table->reginfo.join_tab->select_cond;
825
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
827
if (make_db_list(session, db_names, &lookup_field_vals,
832
If we have lookup db value we should check that the database exists
834
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
837
char path[FN_REFLEN+16];
839
struct stat stat_info;
840
if (!lookup_field_vals.db_value.str[0])
842
path_len= build_table_filename(path, sizeof(path),
843
lookup_field_vals.db_value.str, "", false);
845
if (stat(path,&stat_info))
849
vector<LEX_STRING*>::iterator db_name= db_names.begin();
850
while (db_name != db_names.end())
852
if (with_i_schema) // information schema name is always first in list
854
if (store_schema_schemata(session, table, *db_name, system_charset_info))
861
const CHARSET_INFO *cs= get_default_db_collation((*db_name)->str);
863
if (store_schema_schemata(session, table, *db_name, cs))
872
int SchemataISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
876
LEX *lex= session->lex;
877
Select_Lex *sel= lex->current_select;
878
Name_resolution_context *context= &sel->context;
879
const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
881
if (!sel->item_list.elements)
883
const drizzled::plugin::ColumnInfo *column= columns[1];
884
String buffer(tmp,sizeof(tmp), system_charset_info);
885
Item_field *field= new Item_field(context,
886
NULL, NULL, column->getName().c_str());
887
if (!field || session->add_item_to_list(field))
890
buffer.append(column->getOldName().c_str());
891
if (lex->wild && lex->wild->ptr())
893
buffer.append(STRING_WITH_LEN(" ("));
894
buffer.append(lex->wild->ptr());
897
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
902
int StatsISMethods::processTable(Session *session, TableList *tables,
903
Table *table, bool res,
905
LEX_STRING *table_name) const
907
const CHARSET_INFO * const cs= system_charset_info;
910
if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
913
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
914
rather than in SHOW KEYS
916
if (session->is_error())
918
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
919
session->main_da.sql_errno(), session->main_da.message());
921
session->clear_error();
928
Table *show_table= tables->table;
929
KEY *key_info=show_table->s->key_info;
930
if (show_table->cursor)
932
show_table->cursor->info(HA_STATUS_VARIABLE |
936
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
938
KEY_PART_INFO *key_part= key_info->key_part;
940
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
942
table->restoreRecordAsDefault();
943
table->field[1]->store(db_name->str, db_name->length, cs);
944
table->field[2]->store(table_name->str, table_name->length, cs);
945
table->field[3]->store((int64_t) ((key_info->flags &
946
HA_NOSAME) ? 0 : 1), true);
947
table->field[4]->store(db_name->str, db_name->length, cs);
948
table->field[5]->store(key_info->name, strlen(key_info->name), cs);
949
table->field[6]->store((int64_t) (j+1), true);
950
str=(key_part->field ? key_part->field->field_name :
952
table->field[7]->store(str, strlen(str), cs);
953
if (show_table->cursor)
955
if (show_table->cursor->index_flags(i, j, 0) & HA_READ_ORDER)
957
table->field[8]->store(((key_part->key_part_flag &
960
table->field[8]->set_notnull();
962
KEY *key=show_table->key_info+i;
963
if (key->rec_per_key[j])
965
ha_rows records=(show_table->cursor->stats.records /
966
key->rec_per_key[j]);
967
table->field[9]->store((int64_t) records, true);
968
table->field[9]->set_notnull();
970
str= show_table->cursor->index_type(i);
971
table->field[13]->store(str, strlen(str), cs);
973
if ((key_part->field &&
975
show_table->s->field[key_part->fieldnr-1]->key_length()))
977
table->field[10]->store((int64_t) key_part->length /
978
key_part->field->charset()->mbmaxlen, true);
979
table->field[10]->set_notnull();
981
uint32_t flags= key_part->field ? key_part->field->flags : 0;
982
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
983
table->field[12]->store(pos, strlen(pos), cs);
984
if (!show_table->s->keys_in_use.test(i))
986
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
990
table->field[14]->store("", 0, cs);
992
table->field[14]->set_notnull();
993
assert(test(key_info->flags & HA_USES_COMMENT) ==
994
(key_info->comment.length > 0));
995
if (key_info->flags & HA_USES_COMMENT)
997
table->field[15]->store(key_info->comment.str,
998
key_info->comment.length, cs);
1000
if (schema_table_store_record(session, table))
1010
int StatusISMethods::fillTable(Session *session, TableList *tables)
1012
LEX *lex= session->lex;
1013
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1015
STATUS_VAR *tmp1, tmp;
1016
const string schema_table_name= tables->schema_table->getTableName();
1017
enum enum_var_type option_type;
1018
bool upper_case_names= (schema_table_name.compare("STATUS") != 0);
1020
if (schema_table_name.compare("STATUS") == 0)
1022
option_type= lex->option_type;
1023
if (option_type == OPT_GLOBAL)
1026
tmp1= session->initial_status_var;
1028
else if (schema_table_name.compare("GLOBAL_STATUS") == 0)
1030
option_type= OPT_GLOBAL;
1035
option_type= OPT_SESSION;
1036
tmp1= &session->status_var;
1039
pthread_mutex_lock(&LOCK_status);
1040
if (option_type == OPT_GLOBAL)
1041
calc_sum_of_all_status(&tmp);
1042
res= show_status_array(session, wild,
1043
getFrontOfStatusVars(),
1044
option_type, tmp1, "", tables->table,
1046
pthread_mutex_unlock(&LOCK_status);
1050
static bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
1051
LEX_STRING *table_name, const char *key_name,
1052
uint32_t key_len, const char *con_type, uint32_t con_len)
1054
const CHARSET_INFO * const cs= system_charset_info;
1055
table->restoreRecordAsDefault();
1056
table->field[1]->store(db_name->str, db_name->length, cs);
1057
table->field[2]->store(key_name, key_len, cs);
1058
table->field[3]->store(db_name->str, db_name->length, cs);
1059
table->field[4]->store(table_name->str, table_name->length, cs);
1060
table->field[5]->store(con_type, con_len, cs);
1061
return schema_table_store_record(session, table);
1064
int TabConstraintsISMethods::processTable(Session *session, TableList *tables,
1065
Table *table, bool res,
1066
LEX_STRING *db_name,
1067
LEX_STRING *table_name) const
1071
if (session->is_error())
1073
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1074
session->main_da.sql_errno(), session->main_da.message());
1076
session->clear_error();
1081
List<FOREIGN_KEY_INFO> f_key_list;
1082
Table *show_table= tables->table;
1083
KEY *key_info=show_table->key_info;
1084
uint32_t primary_key= show_table->s->primary_key;
1085
show_table->cursor->info(HA_STATUS_VARIABLE |
1088
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
1090
if (i != primary_key && !(key_info->flags & HA_NOSAME))
1095
if (i == primary_key && is_primary_key(key_info))
1097
if (store_constraints(session, table, db_name, table_name, key_info->name,
1098
strlen(key_info->name),
1099
STRING_WITH_LEN("PRIMARY KEY")))
1104
else if (key_info->flags & HA_NOSAME)
1106
if (store_constraints(session, table, db_name, table_name, key_info->name,
1107
strlen(key_info->name),
1108
STRING_WITH_LEN("UNIQUE")))
1115
show_table->cursor->get_foreign_key_list(session, &f_key_list);
1116
FOREIGN_KEY_INFO *f_key_info;
1117
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
1118
while ((f_key_info=it++))
1120
if (store_constraints(session, table, db_name, table_name,
1121
f_key_info->forein_id->str,
1122
strlen(f_key_info->forein_id->str),
1132
int TablesISMethods::processTable(Session *session, TableList *tables,
1133
Table *table, bool res,
1134
LEX_STRING *db_name,
1135
LEX_STRING *table_name) const
1137
const char *tmp_buff;
1139
const CHARSET_INFO * const cs= system_charset_info;
1141
table->restoreRecordAsDefault();
1142
table->field[1]->store(db_name->str, db_name->length, cs);
1143
table->field[2]->store(table_name->str, table_name->length, cs);
1147
there was errors during opening tables
1149
const char *error= session->is_error() ? session->main_da.message() : "";
1150
if (tables->schema_table)
1152
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
1156
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
1158
table->field[20]->store(error, strlen(error), cs);
1159
session->clear_error();
1163
char option_buff[400],*ptr;
1164
Table *show_table= tables->table;
1165
TableShare *share= show_table->s;
1166
Cursor *cursor= show_table->cursor;
1167
drizzled::plugin::StorageEngine *tmp_db_type= share->db_type();
1169
if (share->tmp_table == SYSTEM_TMP_TABLE)
1171
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
1173
else if (share->tmp_table)
1175
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
1179
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
1182
for (int i= 4; i < 20; i++)
1184
if (i == 7 || (i > 12 && i < 17) || i == 18)
1188
table->field[i]->set_notnull();
1190
const string &engine_name= drizzled::plugin::StorageEngine::resolveName(tmp_db_type);
1191
table->field[4]->store(engine_name.c_str(), engine_name.size(), cs);
1192
table->field[5]->store((int64_t) 0, true);
1196
if (share->db_create_options & HA_OPTION_PACK_KEYS)
1198
ptr= strcpy(ptr," pack_keys=1")+12;
1200
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
1202
ptr= strcpy(ptr," pack_keys=0")+12;
1204
if (share->row_type != ROW_TYPE_DEFAULT)
1206
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint32_t)share->row_type]);
1208
if (share->block_size)
1210
ptr= strcpy(ptr, " block_size=")+12;
1211
ptr= int64_t10_to_str(share->block_size, ptr, 10);
1214
table->field[19]->store(option_buff+1,
1215
(ptr == option_buff ? 0 :
1216
(uint32_t) (ptr-option_buff)-1), cs);
1218
tmp_buff= (share->table_charset ?
1219
share->table_charset->name : "default");
1220
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
1222
if (share->hasComment())
1223
table->field[20]->store(share->getComment(),
1224
share->getCommentLength(), cs);
1228
cursor->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
1230
enum row_type row_type = cursor->get_row_type();
1232
case ROW_TYPE_NOT_USED:
1233
case ROW_TYPE_DEFAULT:
1234
tmp_buff= ((share->db_options_in_use &
1235
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
1236
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
1237
"Dynamic" : "Fixed");
1239
case ROW_TYPE_FIXED:
1242
case ROW_TYPE_DYNAMIC:
1243
tmp_buff= "Dynamic";
1245
case ROW_TYPE_COMPRESSED:
1246
tmp_buff= "Compressed";
1248
case ROW_TYPE_REDUNDANT:
1249
tmp_buff= "Redundant";
1251
case ROW_TYPE_COMPACT:
1252
tmp_buff= "Compact";
1258
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
1259
if (! tables->schema_table)
1261
table->field[7]->store((int64_t) cursor->stats.records, true);
1262
table->field[7]->set_notnull();
1264
table->field[8]->store((int64_t) cursor->stats.mean_rec_length, true);
1265
table->field[9]->store((int64_t) cursor->stats.data_file_length, true);
1266
if (cursor->stats.max_data_file_length)
1268
table->field[10]->store((int64_t) cursor->stats.max_data_file_length,
1271
table->field[11]->store((int64_t) cursor->stats.index_file_length, true);
1272
table->field[12]->store((int64_t) cursor->stats.delete_length, true);
1273
if (show_table->found_next_number_field)
1275
table->field[13]->store((int64_t) cursor->stats.auto_increment_value, true);
1276
table->field[13]->set_notnull();
1278
if (cursor->stats.create_time)
1280
session->variables.time_zone->gmt_sec_to_TIME(&time,
1281
(time_t) cursor->stats.create_time);
1282
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
1283
table->field[14]->set_notnull();
1285
if (cursor->stats.update_time)
1287
session->variables.time_zone->gmt_sec_to_TIME(&time,
1288
(time_t) cursor->stats.update_time);
1289
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
1290
table->field[15]->set_notnull();
1292
if (cursor->stats.check_time)
1294
session->variables.time_zone->gmt_sec_to_TIME(&time,
1295
(time_t) cursor->stats.check_time);
1296
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
1297
table->field[16]->set_notnull();
1299
if (cursor->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
1301
table->field[18]->store((int64_t) cursor->checksum(), true);
1302
table->field[18]->set_notnull();
1306
return (schema_table_store_record(session, table));
1310
int TabNamesISMethods::oldFormat(Session *session, drizzled::plugin::InfoSchemaTable *schema_table)
1314
String buffer(tmp,sizeof(tmp), session->charset());
1315
LEX *lex= session->lex;
1316
Name_resolution_context *context= &lex->select_lex.context;
1317
const drizzled::plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
1319
const drizzled::plugin::ColumnInfo *column= columns[2];
1321
buffer.append(column->getOldName().c_str());
1322
buffer.append(lex->select_lex.db);
1323
if (lex->wild && lex->wild->ptr())
1325
buffer.append(STRING_WITH_LEN(" ("));
1326
buffer.append(lex->wild->ptr());
1329
Item_field *field= new Item_field(context,
1330
NULL, NULL, column->getName().c_str());
1331
if (session->add_item_to_list(field))
1335
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
1336
if (session->lex->verbose)
1338
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
1340
field= new Item_field(context, NULL, NULL, column->getName().c_str());
1341
if (session->add_item_to_list(field))
1345
field->set_name(column->getOldName().c_str(),
1346
column->getOldName().length(),
1347
system_charset_info);
1352
int VariablesISMethods::fillTable(Session *session, TableList *tables)
1355
LEX *lex= session->lex;
1356
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1357
const string schema_table_name= tables->schema_table->getTableName();
1358
enum enum_var_type option_type= OPT_SESSION;
1359
bool upper_case_names= (schema_table_name.compare("VARIABLES") != 0);
1360
bool sorted_vars= (schema_table_name.compare("VARIABLES") == 0);
1362
if (lex->option_type == OPT_GLOBAL ||
1363
schema_table_name.compare("GLOBAL_VARIABLES") == 0)
1365
option_type= OPT_GLOBAL;
1368
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1369
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
1370
option_type, NULL, "", tables->table, upper_case_names);
1371
pthread_rwlock_unlock(&LOCK_system_variables_hash);
226
* Function object used for deleting the memory allocated
227
* for the columns contained with the vector of columns.
233
inline void operator()(const T *ptr) const
239
void clearColumns(vector<const drizzled::plugin::ColumnInfo *> &cols)
241
for_each(cols.begin(), cols.end(), DeleteColumns());