TEST(TestCommand, testShownamespacesCommand) { cout << "testShownamespacesCommand" << endl; FileOutputStream* fos = new FileOutputStream("test.dat", "wb"); CommandWriter* writer = new CommandWriter(fos); ShownamespacesCommand cmd; cmd.setDB("testdb"); writer->writeCommand(&cmd); fos->close(); delete fos; delete writer; FileInputStream* fis = new FileInputStream("test.dat", "rb"); CommandReader* reader = new CommandReader(fis); Command* resCmd = reader->readCommand(); EXPECT_TRUE(resCmd->commandType() == SHOWNAMESPACES); ShownamespacesCommand* sw = (ShownamespacesCommand*)resCmd; EXPECT_TRUE(sw->DB()->compare("testdb") == 0); fis->close(); delete resCmd; delete fis; delete reader; }
std::vector<std::string>* Connection::namespaces(const std::string& db) const { if (_logger->isDebug()) _logger->debug(2, "namespaces command. db: %s", db.c_str()); ShownamespacesCommand cmd; cmd.setDB(db); _commandWriter->writeCommand(&cmd); cmd.readResult(_inputStream); std::vector<std::string>* result = (std::vector<std::string>*)cmd.result(); return result; }
std::vector<char*>* DjondbConnection::namespaces(const char* db) const { if (_logger->isDebug()) _logger->debug(2, "namespaces command. db: %s", db); if (!isOpen()) { throw DjondbException(D_ERROR_CONNECTION, "Not connected to any server"); } ShownamespacesCommand cmd; cmd.setDB(db); _commandWriter->writeCommand(&cmd); cmd.readResult(_inputStream); std::vector<std::string>* temp = (std::vector<std::string>*)cmd.result(); std::vector<char*>* result = new std::vector<char*>(); for (std::vector<std::string>::const_iterator i = temp->begin(); i != temp->end(); i++) { std::string ns = *i; result->push_back(strcpy(ns.c_str(), ns.length())); } delete temp; return result; }