| 2104 | } |
| 2105 | |
| 2106 | void HandleNSAddTableField(const std::vector<std::string>& parts, |
| 2107 | ::fedb::client::NsClient* client) { |
| 2108 | if (parts.size() != 4) { |
| 2109 | std::cout << "addtablefield format error. eg: addtablefield tablename " |
| 2110 | "column_name column_type" |
| 2111 | << std::endl; |
| 2112 | return; |
| 2113 | } |
| 2114 | auto iter = ::fedb::codec::DATA_TYPE_MAP.find(parts[3]); |
| 2115 | if (iter == ::fedb::codec::DATA_TYPE_MAP.end()) { |
| 2116 | printf("type %s is invalid\n", parts[3].c_str()); |
| 2117 | return; |
| 2118 | } |
| 2119 | std::vector<::fedb::nameserver::TableInfo> tables; |
| 2120 | std::string msg; |
| 2121 | bool ret = client->ShowTable(parts[1], tables, msg); |
| 2122 | if (!ret) { |
| 2123 | std::cout << "failed to get table info. error msg: " << msg |
| 2124 | << std::endl; |
| 2125 | return; |
| 2126 | } |
| 2127 | if (tables.empty()) { |
| 2128 | printf("add table field failed! table %s doesn`t exist\n", |
| 2129 | parts[1].c_str()); |
| 2130 | return; |
| 2131 | } |
| 2132 | ::fedb::common::ColumnDesc column_desc; |
| 2133 | column_desc.set_name(parts[2]); |
| 2134 | column_desc.set_data_type(iter->second); |
| 2135 | if (!client->AddTableField(parts[1], column_desc, msg)) { |
| 2136 | std::cout << "Fail to add table field. error msg: " << msg << std::endl; |
| 2137 | return; |
| 2138 | } |
| 2139 | std::cout << "add table field ok" << std::endl; |
| 2140 | } |
| 2141 | |
| 2142 | void HandleNSInfo(const std::vector<std::string>& parts, |
| 2143 | ::fedb::client::NsClient* client) { |
no test coverage detected