diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index 7ec4690d0..b03a865e5 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -60,6 +60,7 @@ const string LDBCommand::ARG_DB_WRITE_BUFFER_SIZE = "db_write_buffer_size"; const string LDBCommand::ARG_WRITE_BUFFER_SIZE = "write_buffer_size"; const string LDBCommand::ARG_FILE_SIZE = "file_size"; const string LDBCommand::ARG_CREATE_IF_MISSING = "create_if_missing"; +const string LDBCommand::ARG_NO_VALUE = "no_value"; const char* LDBCommand::DELIM = " ==> "; @@ -1743,12 +1744,13 @@ Options BatchPutCommand::PrepareOptionsForOpenDB() { ScanCommand::ScanCommand(const vector& params, const map& options, const vector& flags) : LDBCommand(options, flags, true, - BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_TO, + BuildCmdLineOptions({ARG_TTL, ARG_NO_VALUE, ARG_HEX, ARG_KEY_HEX, ARG_TO, ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP, ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})), start_key_specified_(false), end_key_specified_(false), - max_keys_scanned_(-1) { + max_keys_scanned_(-1), + no_value_(false) { map::const_iterator itr = options.find(ARG_FROM); if (itr != options.end()) { @@ -1767,6 +1769,11 @@ ScanCommand::ScanCommand(const vector& params, end_key_specified_ = true; } + vector::const_iterator vitr = std::find(flags.begin(), flags.end(), ARG_NO_VALUE); + if (vitr != flags.end()) { + no_value_ = true; + } + itr = options.find(ARG_MAX_KEYS); if (itr != options.end()) { try { @@ -1794,6 +1801,7 @@ void ScanCommand::Help(string& ret) { ret.append(" [--" + ARG_MAX_KEYS + "=q] "); ret.append(" [--" + ARG_TTL_START + "=:- is inclusive]"); ret.append(" [--" + ARG_TTL_END + "=:- is exclusive]"); + ret.append(" [--" + ARG_NO_VALUE + "]"); ret.append("\n"); } @@ -1850,16 +1858,21 @@ void ScanCommand::DoCommand() { key_slice = formatted_key; } - std::string formatted_value; - if (is_value_hex_) { - formatted_value = "0x" + val_slice.ToString(true /* hex */); - val_slice = formatted_value; + if (no_value_) { + fprintf(stdout, "%.*s\n", + static_cast(key_slice.size()), key_slice.data()); + } else { + Slice val_slice = it->value(); + std::string formatted_value; + if (is_value_hex_) { + formatted_value = "0x" + val_slice.ToString(true /* hex */); + val_slice = formatted_value; + } + fprintf(stdout, "%.*s : %.*s\n", + static_cast(key_slice.size()), key_slice.data(), + static_cast(val_slice.size()), val_slice.data()); } - - fprintf(stdout, "%.*s : %.*s\n", - static_cast(key_slice.size()), key_slice.data(), - static_cast(val_slice.size()), val_slice.data()); - + num_keys_scanned++; if (max_keys_scanned_ >= 0 && num_keys_scanned >= max_keys_scanned_) { break; diff --git a/tools/ldb_cmd.h b/tools/ldb_cmd.h index 0c048e794..2c1c5e4b1 100644 --- a/tools/ldb_cmd.h +++ b/tools/ldb_cmd.h @@ -60,6 +60,7 @@ public: static const string ARG_WRITE_BUFFER_SIZE; static const string ARG_FILE_SIZE; static const string ARG_CREATE_IF_MISSING; + static const string ARG_NO_VALUE; static LDBCommand* InitFromCmdLineArgs( const vector& args, @@ -377,7 +378,7 @@ private: */ bool StringToBool(string val) { std::transform(val.begin(), val.end(), val.begin(), - [](char ch) -> char { return ::tolower(ch); }); + [](char ch) -> char { return (char)::tolower(ch); }); if (val == "true") { return true; @@ -709,6 +710,7 @@ private: bool start_key_specified_; bool end_key_specified_; int max_keys_scanned_; + bool no_value_; }; class DeleteCommand : public LDBCommand {