| 962 | } |
| 963 | |
| 964 | void |
| 965 | dbcontext::cmd_open(dbcallback_i& cb, const cmd_open_args& arg) |
| 966 | { |
| 967 | unlock_tables_if(); |
| 968 | const table_name_type k = std::make_pair(std::string(arg.dbn), |
| 969 | std::string(arg.tbl)); |
| 970 | const table_map_type::const_iterator iter = table_map.find(k); |
| 971 | uint32_t tblnum = 0; |
| 972 | if (iter != table_map.end()) { |
| 973 | tblnum = iter->second; |
| 974 | DBG_CMP(fprintf(stderr, "HNDSOCK k=%s tblnum=%d\n", k.c_str(), |
| 975 | (int)tblnum)); |
| 976 | } else { |
| 977 | TABLE_LIST tables; |
| 978 | TABLE *table = 0; |
| 979 | bool refresh = true; |
| 980 | const thr_lock_type lock_type = for_write_flag ? TL_WRITE : TL_READ; |
| 981 | LEX_CSTRING db_name= { arg.dbn, strlen(arg.dbn) }; |
| 982 | LEX_CSTRING tbl_name= { arg.tbl, strlen(arg.tbl) }; |
| 983 | tables.init_one_table(&db_name, &tbl_name, 0, lock_type); |
| 984 | MDL_REQUEST_INIT(&tables.mdl_request, MDL_key::TABLE, arg.dbn, arg.tbl, |
| 985 | for_write_flag ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION); |
| 986 | Open_table_context ot_act(thd, 0); |
| 987 | if (!open_table(thd, &tables, &ot_act)) { |
| 988 | table = tables.table; |
| 989 | } |
| 990 | if (table == 0) { |
| 991 | DENA_VERBOSE(20, fprintf(stderr, |
| 992 | "HNDSOCK failed to open %p [%s] [%s] [%d]\n", |
| 993 | thd, arg.dbn, arg.tbl, static_cast<int>(refresh))); |
| 994 | return cb.dbcb_resp_short(1, "open_table"); |
| 995 | } |
| 996 | statistic_increment(open_tables_count, &LOCK_status); |
| 997 | table->reginfo.lock_type = lock_type; |
| 998 | table->use_all_columns(); |
| 999 | tblnum = table_vec.size(); |
| 1000 | tablevec_entry e; |
| 1001 | e.table = table; |
| 1002 | table_vec.push_back(e); |
| 1003 | table_map[k] = tblnum; |
| 1004 | } |
| 1005 | size_t idxnum = static_cast<size_t>(-1); |
| 1006 | if (arg.idx[0] >= '0' && arg.idx[0] <= '9') { |
| 1007 | /* numeric */ |
| 1008 | TABLE *const table = table_vec[tblnum].table; |
| 1009 | idxnum = atoi(arg.idx); |
| 1010 | if (idxnum >= table->s->keys) { |
| 1011 | return cb.dbcb_resp_short(2, "idxnum"); |
| 1012 | } |
| 1013 | } else { |
| 1014 | const char *const idx_name_to_open = |
| 1015 | arg.idx[0] == '\0' ? "PRIMARY" : arg.idx; |
| 1016 | TABLE *const table = table_vec[tblnum].table; |
| 1017 | for (uint i = 0; i < table->s->keys; ++i) { |
| 1018 | KEY& kinfo = table->key_info[i]; |
| 1019 | if (strcmp(kinfo.name.str, idx_name_to_open) == 0) { |
| 1020 | idxnum = i; |
| 1021 | break; |
no test coverage detected