diff --git a/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h b/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h index d607b7cf36..de2d85cf53 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h +++ b/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h @@ -35,6 +35,7 @@ class ActiveRecordLib_API ActiveRecordBase: public Poco::RefCountedObject public: using Ptr = Poco::AutoPtr; + [[nodiscard]] virtual std::string toString() const = 0; /// Returns a string representation of the object for /// debugging purposes. The default implementation returns the ID. @@ -59,14 +60,17 @@ class ActiveRecordLib_API ActiveRecordBase: public Poco::RefCountedObject void detach(); /// Detaches the object from its Context. + [[nodiscard]] Context::Ptr context() const; /// Returns the Context this object is attached to, /// or a null pointer if the object has not been /// attached to a Context. + [[nodiscard]] virtual bool isValid() const; /// Returns true iff the object is valid ID, otherwise false. + [[nodiscard]] bool isAttached() const; /// Returns true iff the object has been attached to a Context, otherwise false. diff --git a/ActiveRecord/include/Poco/ActiveRecord/Context.h b/ActiveRecord/include/Poco/ActiveRecord/Context.h index 0cca334cf7..ee298bbd35 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/Context.h +++ b/ActiveRecord/include/Poco/ActiveRecord/Context.h @@ -41,9 +41,11 @@ class ActiveRecordLib_API Context: public Poco::RefCountedObject ~Context() = default; /// Destroys the Context. + [[nodiscard]] Poco::Data::Session& session(); /// Returns the database session. + [[nodiscard]] StatementPlaceholderProvider::Ptr statementPlaceholderProvider() const; /// Returns a new StatementPlaceholderProvider. diff --git a/ActiveRecord/include/Poco/ActiveRecord/IDTraits.h b/ActiveRecord/include/Poco/ActiveRecord/IDTraits.h index 3182b9ada4..9792227596 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/IDTraits.h +++ b/ActiveRecord/include/Poco/ActiveRecord/IDTraits.h @@ -39,11 +39,13 @@ class IDTraits public: static constexpr Poco::UInt64 INVALID_ID = std::numeric_limits::max(); + [[nodiscard]] static bool isValid(Poco::UInt64 id) { return id != INVALID_ID; } + [[nodiscard]] static std::string toString(Poco::UInt64 id) { return Poco::NumberFormatter::format(id); @@ -57,11 +59,13 @@ class IDTraits public: static constexpr Poco::Int64 INVALID_ID = std::numeric_limits::max(); + [[nodiscard]] static bool isValid(Poco::Int64 id) { return id != INVALID_ID; } + [[nodiscard]] static std::string toString(Poco::Int64 id) { return Poco::NumberFormatter::format(id); @@ -75,11 +79,13 @@ class IDTraits public: static constexpr Poco::UInt32 INVALID_ID = std::numeric_limits::max(); + [[nodiscard]] static bool isValid(Poco::UInt32 id) { return id != INVALID_ID; } + [[nodiscard]] static std::string toString(Poco::UInt32 id) { return Poco::NumberFormatter::format(id); @@ -93,11 +99,13 @@ class IDTraits public: static const Poco::Int32 INVALID_ID = std::numeric_limits::max(); + [[nodiscard]] static bool isValid(Poco::Int32 id) { return id != INVALID_ID; } + [[nodiscard]] static std::string toString(Poco::Int32 id) { return Poco::NumberFormatter::format(id); @@ -111,11 +119,13 @@ class IDTraits public: static constexpr Poco::UInt16 INVALID_ID = std::numeric_limits::max(); + [[nodiscard]] static bool isValid(Poco::UInt16 id) { return id != INVALID_ID; } + [[nodiscard]] static std::string toString(Poco::UInt16 id) { return Poco::NumberFormatter::format(id); @@ -129,11 +139,13 @@ class IDTraits public: static constexpr Poco::Int16 INVALID_ID = std::numeric_limits::max(); + [[nodiscard]] static bool isValid(Poco::Int16 id) { return id != INVALID_ID; } + [[nodiscard]] static std::string toString(Poco::Int16 id) { return Poco::NumberFormatter::format(id); @@ -147,11 +159,13 @@ class IDTraits public: static ActiveRecordLib_API const std::string INVALID_ID; + [[nodiscard]] static bool isValid(const std::string& id) { return !id.empty(); } + [[nodiscard]] static std::string toString(const std::string& id) { return id; @@ -165,11 +179,13 @@ class IDTraits public: static ActiveRecordLib_API const Poco::UUID INVALID_ID; + [[nodiscard]] static bool isValid(const Poco::UUID& id) { return !id.isNull(); } + [[nodiscard]] static std::string toString(const Poco::UUID& id) { return id.toString(); diff --git a/ActiveRecord/include/Poco/ActiveRecord/Query.h b/ActiveRecord/include/Poco/ActiveRecord/Query.h index bd6f5849c7..daa0831f43 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/Query.h +++ b/ActiveRecord/include/Poco/ActiveRecord/Query.h @@ -116,6 +116,7 @@ class Query return *this; } + [[nodiscard]] std::vector execute() /// Execute the query and return a vector with the /// results. @@ -147,6 +148,7 @@ class Query return result; } + [[nodiscard]] std::size_t totalResults() const /// In case of a paged query, returns the total number of results /// that would be returned without paging. diff --git a/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h b/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h index 9ce2e6d767..131031b803 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h +++ b/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h @@ -30,6 +30,8 @@ class ActiveRecordLib_API StatementPlaceholderProvider using Ptr = std::unique_ptr; virtual void reset() = 0; + + [[nodiscard]] virtual std::string next() = 0; virtual ~StatementPlaceholderProvider(); @@ -40,6 +42,8 @@ class ActiveRecordLib_API DefaultStatementPlaceholderProvider: public StatementP { public: void reset(); + + [[nodiscard]] std::string next(); }; @@ -48,6 +52,8 @@ class ActiveRecordLib_API PostgresStatementPlaceholderProvider: public Statement { public: void reset(); + + [[nodiscard]] std::string next(); private: diff --git a/ApacheConnector/include/ApacheApplication.h b/ApacheConnector/include/ApacheApplication.h index f78b5c3c22..99accb2477 100644 --- a/ApacheConnector/include/ApacheApplication.h +++ b/ApacheConnector/include/ApacheApplication.h @@ -31,9 +31,11 @@ class ApacheApplication: public Poco::Util::Application /// Initializes the application if called for the first /// time; does nothing in later calls. + [[nodiscard]] ApacheRequestHandlerFactory& factory(); /// Returns the ApacheRequestHandlerFactory. + [[nodiscard]] static ApacheApplication& instance(); /// Returns the application instance. diff --git a/ApacheConnector/include/ApacheConnector.h b/ApacheConnector/include/ApacheConnector.h index 1de4130ff4..34abb7bf51 100644 --- a/ApacheConnector/include/ApacheConnector.h +++ b/ApacheConnector/include/ApacheConnector.h @@ -26,6 +26,7 @@ class ApacheRequestRec ApacheRequestRec(request_rec* _pRec); /// Creates the ApacheRequestRec; + [[nodiscard]] bool haveRequestBody(); /// Returns true if the request contains a body. @@ -56,6 +57,7 @@ class ApacheRequestRec /// Copies the request uri and header fields from the Apache request /// to the ApacheServerRequest. + [[nodiscard]] bool secure(); /// Returns true if the request is using a secure /// connection. Returns false if no secure connection diff --git a/ApacheConnector/include/ApacheRequestHandlerFactory.h b/ApacheConnector/include/ApacheRequestHandlerFactory.h index f24e86879a..58bb610d99 100644 --- a/ApacheConnector/include/ApacheRequestHandlerFactory.h +++ b/ApacheConnector/include/ApacheRequestHandlerFactory.h @@ -28,9 +28,11 @@ class ApacheRequestHandlerFactory: public Poco::Net::HTTPRequestHandlerFactory ~ApacheRequestHandlerFactory(); /// Destructor of the ApacheRequestHandlerFactory + [[nodiscard]] Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request); /// Creates a new request handler for the given HTTP request. + [[nodiscard]] bool mustHandle(const std::string& uri); /// Returns 1 if the given uri must be handled by the /// poco_mapper module, 0 otherwise. diff --git a/ApacheConnector/include/ApacheServerRequest.h b/ApacheConnector/include/ApacheServerRequest.h index 6dd9b5c609..c7fd8ef2ae 100644 --- a/ApacheConnector/include/ApacheServerRequest.h +++ b/ApacheConnector/include/ApacheServerRequest.h @@ -35,6 +35,7 @@ class ApacheServerRequest: public Poco::Net::HTTPServerRequest ~ApacheServerRequest(); /// Destroys the ApacheServerRequest. + [[nodiscard]] std::istream& stream(); /// Returns the input stream for reading /// the request body. @@ -42,22 +43,28 @@ class ApacheServerRequest: public Poco::Net::HTTPServerRequest /// The stream is valid until the HTTPServerRequest /// object is destroyed. + [[nodiscard]] bool expectContinue() const; /// Returns true if the client expects a /// 100 Continue response. + [[nodiscard]] const Poco::Net::SocketAddress& clientAddress() const; /// Returns the client's address. + [[nodiscard]] const Poco::Net::SocketAddress& serverAddress() const; /// Returns the server's address. + [[nodiscard]] const Poco::Net::HTTPServerParams& serverParams() const; /// Returns a reference to the server parameters. + [[nodiscard]] Poco::Net::HTTPServerResponse& response() const; /// Returns a reference to the associated response + [[nodiscard]] bool secure() const; /// Returns true if the request is using a secure /// connection. Returns false if no secure connection diff --git a/ApacheConnector/include/ApacheServerResponse.h b/ApacheConnector/include/ApacheServerResponse.h index ea03caec8f..e7c315ecbf 100644 --- a/ApacheConnector/include/ApacheServerResponse.h +++ b/ApacheConnector/include/ApacheServerResponse.h @@ -98,6 +98,7 @@ class ApacheServerResponse: public Poco::Net::HTTPServerResponse /// and sets the "WWW-Authenticate" header field /// according to the given realm. + [[nodiscard]] bool sent() const; /// Returns true if the response (header) has been sent. diff --git a/ApacheConnector/include/ApacheStream.h b/ApacheConnector/include/ApacheStream.h index 22b355e8d3..c6a30be185 100644 --- a/ApacheConnector/include/ApacheStream.h +++ b/ApacheConnector/include/ApacheStream.h @@ -59,6 +59,7 @@ class ApacheIOS: public virtual std::ios /// /// Flushes the buffer, but does not close the socket. + [[nodiscard]] ApacheStreamBuf* rdbuf(); /// Returns a pointer to the internal ApacheStreamBuf. diff --git a/CppParser/include/Poco/CppParser/Attributes.h b/CppParser/include/Poco/CppParser/Attributes.h index 95993d66f4..b54874585c 100644 --- a/CppParser/include/Poco/CppParser/Attributes.h +++ b/CppParser/include/Poco/CppParser/Attributes.h @@ -46,36 +46,43 @@ class CppParser_API Attributes Attributes& operator = (const Attributes& attrs); /// Assignment operator. + [[nodiscard]] bool has(const std::string& name) const; /// Returns true if an attribute with the given name exists. + [[nodiscard]] std::string getString(const std::string& name) const; /// Returns the attribute's value as a string. /// /// Throws a Poco::NotFoundException if the attribute does not exist. + [[nodiscard]] std::string getString(const std::string& name, const std::string& defaultValue) const; /// Returns the attribute's value as a string, if it exists. /// Returns the defaultValue if the attribute does not exist. + [[nodiscard]] int getInt(const std::string& name) const; /// Returns the attribute's value as an integer. /// /// Throws a Poco::NotFoundException if the attribute does not exist. /// Throws a Poco::SyntaxException if the stored value is not an integer. + [[nodiscard]] int getInt(const std::string& name, int defaultValue) const; /// Returns the attribute's value as an integer, if it exists. /// Returns the defaultValue if the attribute does not exist. /// /// Throws a Poco::SyntaxException if the stored value is not an integer. + [[nodiscard]] bool getBool(const std::string& name) const; /// Returns the attribute's value as a boolean. /// The returned value is 'true', iff the stored value is not "false". /// /// Throws a Poco::NotFoundException if the attribute does not exist. + [[nodiscard]] bool getBool(const std::string& name, bool defaultValue) const; /// Returns the attribute's value as a boolean, if it exists. /// The returned value is 'true', iff the stored value is not "false". @@ -87,10 +94,15 @@ class CppParser_API Attributes /// Removes the attribute with the given name. /// Does nothing if the attribute does not exist. + [[nodiscard]] const std::string& operator [] (const std::string& name) const; + + [[nodiscard]] std::string& operator [] (const std::string& name); + [[nodiscard]] Iterator begin() const; + [[nodiscard]] Iterator end() const; void clear(); diff --git a/CppParser/include/Poco/CppParser/AttributesParser.h b/CppParser/include/Poco/CppParser/AttributesParser.h index 65c82fc0d1..0d62ba5c1e 100644 --- a/CppParser/include/Poco/CppParser/AttributesParser.h +++ b/CppParser/include/Poco/CppParser/AttributesParser.h @@ -62,9 +62,14 @@ class CppParser_API AttributesParser const Poco::Token* parseComplexAttribute(const Token* pNext, const std::string& id); const Poco::Token* parseIdentifier(const Poco::Token* pNext, std::string& id); const Poco::Token* next(); + + [[nodiscard]] static bool isIdentifier(const Poco::Token* pToken); + [[nodiscard]] static bool isOperator(const Poco::Token* pToken, int kind); + [[nodiscard]] static bool isLiteral(const Poco::Token* pToken); + [[nodiscard]] static bool isEOF(const Poco::Token* pToken); private: diff --git a/CppParser/include/Poco/CppParser/BuiltIn.h b/CppParser/include/Poco/CppParser/BuiltIn.h index 570c7c4fcf..3fcc42bb2b 100644 --- a/CppParser/include/Poco/CppParser/BuiltIn.h +++ b/CppParser/include/Poco/CppParser/BuiltIn.h @@ -35,7 +35,9 @@ class CppParser_API BuiltIn: public Symbol ~BuiltIn(); /// Destroys the BuiltIn. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string toString() const; }; diff --git a/CppParser/include/Poco/CppParser/CppToken.h b/CppParser/include/Poco/CppParser/CppToken.h index 874aa3b483..cf4ee539ba 100644 --- a/CppParser/include/Poco/CppParser/CppToken.h +++ b/CppParser/include/Poco/CppParser/CppToken.h @@ -97,9 +97,11 @@ class CppParser_API OperatorToken: public CppToken OperatorToken(); ~OperatorToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); + [[nodiscard]] int asInteger() const; private: @@ -202,9 +204,11 @@ class CppParser_API IdentifierToken: public CppToken IdentifierToken(); ~IdentifierToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); + [[nodiscard]] int asInteger() const; private: @@ -221,9 +225,11 @@ class CppParser_API StringLiteralToken: public CppToken public: StringLiteralToken(); ~StringLiteralToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); + [[nodiscard]] std::string asString() const; }; @@ -233,9 +239,11 @@ class CppParser_API CharLiteralToken: public CppToken public: CharLiteralToken(); ~CharLiteralToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); + [[nodiscard]] char asChar() const; }; @@ -245,10 +253,13 @@ class CppParser_API NumberLiteralToken: public CppToken public: NumberLiteralToken(); ~NumberLiteralToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); + [[nodiscard]] int asInteger() const; + [[nodiscard]] double asFloat() const; protected: @@ -267,9 +278,11 @@ class CppParser_API CommentToken: public CppToken public: CommentToken(); ~CommentToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); + [[nodiscard]] std::string asString() const; }; @@ -279,6 +292,7 @@ class CppParser_API PreprocessorToken: public CppToken public: PreprocessorToken(); ~PreprocessorToken(); + [[nodiscard]] Poco::Token::Class tokenClass() const; bool start(char c, std::istream& istr); void finish(std::istream& istr); diff --git a/CppParser/include/Poco/CppParser/Decl.h b/CppParser/include/Poco/CppParser/Decl.h index de687c78a9..eb757a9956 100644 --- a/CppParser/include/Poco/CppParser/Decl.h +++ b/CppParser/include/Poco/CppParser/Decl.h @@ -36,9 +36,11 @@ class CppParser_API Decl: public Symbol ~Decl(); /// Destroys the Decl. + [[nodiscard]] const std::string& declaration() const; /// Returns the declaration. + [[nodiscard]] std::string toString() const; protected: diff --git a/CppParser/include/Poco/CppParser/Enum.h b/CppParser/include/Poco/CppParser/Enum.h index ddfda112a7..0f1f9bc123 100644 --- a/CppParser/include/Poco/CppParser/Enum.h +++ b/CppParser/include/Poco/CppParser/Enum.h @@ -64,19 +64,25 @@ class CppParser_API Enum: public Symbol void addValue(EnumValue* pValue); /// Adds an enum value. The Enum takes ownership of the value. + [[nodiscard]] Iterator begin() const; /// Returns an iterator for iterating over the Enum's EnumValue's. + [[nodiscard]] Iterator end() const; /// Returns an iterator for iterating over the Enum's EnumValue's. + [[nodiscard]] const std::string& baseType() const; /// Returns the base type or an empty string if no base type has been specified. + [[nodiscard]] int flags() const; /// Returns the flags. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string toString() const; protected: diff --git a/CppParser/include/Poco/CppParser/EnumValue.h b/CppParser/include/Poco/CppParser/EnumValue.h index 41b3e8c965..b8754926df 100644 --- a/CppParser/include/Poco/CppParser/EnumValue.h +++ b/CppParser/include/Poco/CppParser/EnumValue.h @@ -39,10 +39,13 @@ class CppParser_API EnumValue: public Symbol virtual ~EnumValue(); /// Destroys the EnumValue. + [[nodiscard]] const std::string& value() const; /// Returns the value, which may be empty. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string toString() const; private: diff --git a/CppParser/include/Poco/CppParser/Function.h b/CppParser/include/Poco/CppParser/Function.h index b756a797ae..91e320c72f 100644 --- a/CppParser/include/Poco/CppParser/Function.h +++ b/CppParser/include/Poco/CppParser/Function.h @@ -60,11 +60,14 @@ class CppParser_API Function: public Decl void addParameter(Parameter* pParam); /// Adds a parameter to the function. + [[nodiscard]] const std::string& getReturnParameter() const; + [[nodiscard]] Iterator begin() const; /// Returns an iterator for iterating over the Function's Parameter's. + [[nodiscard]] Iterator end() const; /// Returns an iterator for iterating over the Function's Parameter's. @@ -92,52 +95,67 @@ class CppParser_API Function: public Decl void makeDelete(); /// Sets the FN_DELETE flag. + [[nodiscard]] int flags() const; /// Returns the function's flags. + [[nodiscard]] bool isConstructor() const; /// Returns true iff the function is a constructor. + [[nodiscard]] bool isDestructor() const; /// Returns true iff the function is a destructor. + [[nodiscard]] bool isMethod() const; /// Returns true iff the function is a method (it's part of /// a Struct and it's neither a constructor nor a destructor). + [[nodiscard]] bool isFunction() const; /// Returns true iff the function is not a member of a class /// (a freestanding function). + [[nodiscard]] bool isConst() const; /// Returns true iff the method is const. + [[nodiscard]] bool isDefault() const; /// Returns true iff the method has a default implementation. + [[nodiscard]] bool isDeleted() const; /// Returns true iff the method has been deleted. + [[nodiscard]] bool isVirtual() const; /// Returns true if the method is virtual. Also examines base /// classes to check for a virtual function with the same /// signature. + [[nodiscard]] bool isStatic() const; /// Returns true iff the method is static. + [[nodiscard]] int countParameters() const; /// Returns the number of parameters. + [[nodiscard]] std::string signature() const; /// Returns the signature of the function. + [[nodiscard]] Function* getOverridden() const; /// If the function is virtual and overrides a function in a /// base class, the base class function is returned. /// Otherwise, null is returned. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string toString() const; private: diff --git a/CppParser/include/Poco/CppParser/NameSpace.h b/CppParser/include/Poco/CppParser/NameSpace.h index 4a41bac73c..5574a80f92 100644 --- a/CppParser/include/Poco/CppParser/NameSpace.h +++ b/CppParser/include/Poco/CppParser/NameSpace.h @@ -55,18 +55,22 @@ class CppParser_API NameSpace: public Symbol void importNameSpace(const std::string& nameSpace); /// Imports a namespace (using namespace ). + [[nodiscard]] Iterator begin() const; /// Returns an iterator for iterating over the NameSpace's Symbol's. + [[nodiscard]] Iterator end() const; /// Returns an iterator for iterating over the NameSpace's Symbol's. + [[nodiscard]] virtual Symbol* lookup(const std::string& name) const; /// Looks up the given name in the symbol table /// and returns the corresponding symbol, or null /// if no symbol can be found. The name can include /// a namespace. + [[nodiscard]] static NameSpace* root(); /// Returns the root namespace. Never delete this one! @@ -91,10 +95,12 @@ class CppParser_API NameSpace: public Symbol void variables(SymbolTable& table) const; /// Fills the symbol table with all variables. + [[nodiscard]] const AliasMap& importedSymbols() const; /// Returns a const reference to a SymbolTable containing all /// imported symbols. + [[nodiscard]] const NameSpaceVec& importedNameSpaces() const; /// Returns a vector containing all imported namespaces. @@ -105,10 +111,13 @@ class CppParser_API NameSpace: public Symbol void setInline(bool isInline); /// Sets the inline flag for this namespace. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string toString() const; private: + [[nodiscard]] Symbol* lookup(const std::string& name, std::set& alreadyVisited) const; /// Looks up the given name in the symbol table /// and returns the corresponding symbol, or null diff --git a/CppParser/include/Poco/CppParser/Parameter.h b/CppParser/include/Poco/CppParser/Parameter.h index 5a1ff416a3..d3febff726 100644 --- a/CppParser/include/Poco/CppParser/Parameter.h +++ b/CppParser/include/Poco/CppParser/Parameter.h @@ -38,26 +38,33 @@ class CppParser_API Parameter: public Decl ~Parameter(); /// Destroys the Parameter. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] bool isReference() const; /// Returns true iff the parameter is a reference. + [[nodiscard]] bool isPointer() const; /// Returns true iff the parameter is a pointer. + [[nodiscard]] bool isConst() const; /// Returns true iff the parameter is const. + [[nodiscard]] bool hasDefaultValue() const; /// Returns true if a defaultvalue was set at this parameter, /// Example: const std::string& data = std::string("default"). + [[nodiscard]] const std::string& declType() const; /// Returns the type of the parameter without const and & if present. /// /// Example: a type const std::string& -> std::string, a type const std::string* returns std::string + [[nodiscard]] const std::string& defaultValue() const; /// If hasDefaultValue() returns true, this method returns the default value, i.e. all data found between /// the opening and closing bracket of the init string. @@ -66,6 +73,7 @@ class CppParser_API Parameter: public Decl /// for = std::string() it will return a zero length string, for = ComplexClass(13,12, "test", 0); /// it will return 13,12, "test", 0. + [[nodiscard]] const std::string& defaultDecl() const; /// If hasDefaultValue() returns true, this method returns the /// default value declaration. diff --git a/CppParser/include/Poco/CppParser/Parser.h b/CppParser/include/Poco/CppParser/Parser.h index 6bf9eb9dfd..658f2f262a 100644 --- a/CppParser/include/Poco/CppParser/Parser.h +++ b/CppParser/include/Poco/CppParser/Parser.h @@ -90,9 +90,13 @@ class CppParser_API Parser void popNameSpace(); NameSpace* currentNameSpace() const; + [[nodiscard]] static bool isIdentifier(const Poco::Token* pToken); + [[nodiscard]] static bool isOperator(const Poco::Token* pToken, int kind); + [[nodiscard]] static bool isKeyword(const Poco::Token* pToken, int kind); + [[nodiscard]] static bool isEOF(const Poco::Token* pToken); static void expectOperator(const Poco::Token* pToken, int kind, const std::string& msg); static void syntaxError(const std::string& msg); diff --git a/CppParser/include/Poco/CppParser/Struct.h b/CppParser/include/Poco/CppParser/Struct.h index 81f62a03ba..527e980724 100644 --- a/CppParser/include/Poco/CppParser/Struct.h +++ b/CppParser/include/Poco/CppParser/Struct.h @@ -67,9 +67,11 @@ class CppParser_API Struct: public NameSpace void addBase(const std::string&, Symbol::Access access, bool isVirtual); /// Adds a base class. + [[nodiscard]] BaseIterator baseBegin() const; /// Returns an iterator for iterating over all base classes. + [[nodiscard]] BaseIterator baseEnd() const; /// Returns an iterator for iterating over all base classes. @@ -79,15 +81,19 @@ class CppParser_API Struct: public NameSpace void addDerived(Struct* pClass); /// Adds a derived class. + [[nodiscard]] DerivedIterator derivedBegin() const; /// Returns an iterator for iterating over all derived classes. + [[nodiscard]] DerivedIterator derivedEnd() const; /// Returns an iterator for iterating over all derived classes. + [[nodiscard]] const std::string& declaration() const; /// Returns the declaration. + [[nodiscard]] int flags() const; /// Returns the struct's flags. @@ -97,15 +103,18 @@ class CppParser_API Struct: public NameSpace void makeFinal(); /// Makes the class final. + [[nodiscard]] bool isInline() const; /// Returns true if the complete class is inlined in a cpp file. + [[nodiscard]] bool isFinal() const; /// Returns true if the class is final. void constructors(Functions& functions) const; /// Returns all constructors, sorted by their parameter count. + [[nodiscard]] Function* destructor() const; /// Returns the destructor, or NULL if no /// destructor is defined. @@ -122,23 +131,30 @@ class CppParser_API Struct: public NameSpace void derived(StructSet& derived) const; /// Returns all derived classes. + [[nodiscard]] Function* findFunction(const std::string& signature) const; /// Finds a function with the given signature. + [[nodiscard]] bool hasVirtualDestructor() const; /// Returns true if the class CppParser_API or one if its base classes /// has a virtual destructor. + [[nodiscard]] bool isClass() const; /// Returns true iff the struct was declared as class. + [[nodiscard]] bool isDerived() const; /// Returns true iff the struct or class is derived from another struct or class. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string toString() const; // Namespace + [[nodiscard]] Symbol* lookup(const std::string& name) const; private: diff --git a/CppParser/include/Poco/CppParser/Symbol.h b/CppParser/include/Poco/CppParser/Symbol.h index 1383bacdae..48e930671d 100644 --- a/CppParser/include/Poco/CppParser/Symbol.h +++ b/CppParser/include/Poco/CppParser/Symbol.h @@ -68,12 +68,15 @@ class CppParser_API Symbol virtual ~Symbol(); /// Destroys the Symbol. + [[nodiscard]] int id() const; /// Returns the symbol's unique ID. + [[nodiscard]] const std::string& name() const; /// Returns the symbol's (local) name. + [[nodiscard]] NameSpace* nameSpace() const; /// Returns the symbol's namespace which /// may be null. @@ -87,6 +90,7 @@ class CppParser_API Symbol void setAttributeList(const std::string& attrs); /// Sets the C++11 attribute list, e.g. "[[noreturn]]". + [[nodiscard]] const std::string& getAttributeList() const; /// Returns the C++11 attribute list, or an empty string /// if the symbol does not have one. @@ -97,30 +101,35 @@ class CppParser_API Symbol void addDocumentation(const std::string& text); /// Adds text to the symbol's documentation. + [[nodiscard]] const std::string& getDocumentation() const; /// Returns the symbol's documentation. void setFile(const std::string& path); /// Sets the file where the symbol is declared. + [[nodiscard]] const std::string& getFile() const; /// Returns the file where the symbol is defined. void setLineNumber(int line); /// Sets the line number of the symbol's declaration. + [[nodiscard]] int getLineNumber() const; /// Returns the line number of the symbol's declaration. void setPackage(const std::string& package); /// Sets the symbol's package. + [[nodiscard]] const std::string& getPackage() const; /// Returns the symbol's package. void setLibrary(const std::string& library); /// Sets the symbol's library. + [[nodiscard]] const std::string& getLibrary() const; /// Returns the symbol's library. @@ -129,12 +138,15 @@ class CppParser_API Symbol /// /// Currently only used for struct/class members. + [[nodiscard]] std::size_t getOrder() const; /// Returns the order of the symbol within its container. + [[nodiscard]] const Attributes& attrs() const; /// Returns the symbol's attributes. + [[nodiscard]] Attributes& attrs(); /// Returns the symbol's attributes. @@ -144,29 +156,38 @@ class CppParser_API Symbol void setAttributes(const Attributes& attrs); /// Sets the symbol's attributes. + [[nodiscard]] std::string fullName() const; /// Returns the symbol's fully qualified name. + [[nodiscard]] static std::string extractName(const std::string& decl); /// Extracts the name from the declaration. + [[nodiscard]] virtual Kind kind() const = 0; /// Returns the symbol's kind. + [[nodiscard]] virtual std::string toString() const = 0; /// Returns a string representation of the symbol. + [[nodiscard]] bool isPublic() const; /// Returns true iff the symbol is public. + [[nodiscard]] bool isProtected() const; /// Returns true iff the symbol is public. + [[nodiscard]] bool isPrivate() const; /// Returns true iff the symbol is public. protected: + [[nodiscard]] static bool isIdent(char c); + [[nodiscard]] static bool hasAttr(const std::string& decl, const std::string& attr); private: diff --git a/CppParser/include/Poco/CppParser/TypeDef.h b/CppParser/include/Poco/CppParser/TypeDef.h index 70c01b3033..2d26d40a9e 100644 --- a/CppParser/include/Poco/CppParser/TypeDef.h +++ b/CppParser/include/Poco/CppParser/TypeDef.h @@ -35,8 +35,10 @@ class CppParser_API TypeDef: public Decl ~TypeDef(); /// Destroys the TypeDef. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string baseType() const; /// Returns the underlying base type. }; @@ -52,8 +54,10 @@ class CppParser_API TypeAlias: public Decl ~TypeAlias(); /// Destroys the TypeAlias. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] std::string baseType() const; /// Returns the underlying base type. }; diff --git a/CppParser/include/Poco/CppParser/Utility.h b/CppParser/include/Poco/CppParser/Utility.h index 0cc3ed30f7..6ca8762ae8 100644 --- a/CppParser/include/Poco/CppParser/Utility.h +++ b/CppParser/include/Poco/CppParser/Utility.h @@ -31,7 +31,7 @@ class CppParser_API Utility /// Various helpers for parsing and analyzing C++ header files. { public: - class CppParser_API FwdDeclBlock + class CppParser_API [[nodiscard]]FwdDeclBlock { public: std::string beginNameSpaceDecl; // contains either $(NS)_BEGIN or the namespace x { decl diff --git a/CppParser/include/Poco/CppParser/Variable.h b/CppParser/include/Poco/CppParser/Variable.h index 1993bd78a3..ec42afff9c 100644 --- a/CppParser/include/Poco/CppParser/Variable.h +++ b/CppParser/include/Poco/CppParser/Variable.h @@ -43,22 +43,28 @@ class CppParser_API Variable: public Decl ~Variable(); /// Destroys the Variable. + [[nodiscard]] int flags() const; /// Returns the variable's flags. + [[nodiscard]] bool isPointer() const; /// Returns true iff the variable holds a pointer. + [[nodiscard]] Symbol::Kind kind() const; + [[nodiscard]] const std::string& declType() const; /// Returns the type of the parameter without const and & if present. /// /// Example: a type const std::string& -> std::string, a type const std::string* returns std::string + [[nodiscard]] bool isConst() const; /// Returns true iff the variable is const. + [[nodiscard]] bool isStatic() const; /// Returns true iff the variable is static. diff --git a/CppUnit/include/CppUnit/CppUnitException.h b/CppUnit/include/CppUnit/CppUnitException.h index 624a6c3d46..70648670ed 100644 --- a/CppUnit/include/CppUnit/CppUnitException.h +++ b/CppUnit/include/CppUnit/CppUnitException.h @@ -37,11 +37,16 @@ class CppUnit_API CppUnitException: public std::exception CppUnitException& operator = (const CppUnitException& other); + [[nodiscard]] const char* what() const noexcept override; + [[nodiscard]] long lineNumber() const; + [[nodiscard]] long data1LineNumber() const; + [[nodiscard]] long data2LineNumber() const; + [[nodiscard]] const std::string& fileName() const; static const std::string CPPUNIT_UNKNOWNFILENAME; diff --git a/CppUnit/include/CppUnit/RepeatedTest.h b/CppUnit/include/CppUnit/RepeatedTest.h index 0bdbc9a674..8cb281cd8e 100644 --- a/CppUnit/include/CppUnit/RepeatedTest.h +++ b/CppUnit/include/CppUnit/RepeatedTest.h @@ -32,7 +32,9 @@ class CppUnit_API RepeatedTest: public TestDecorator { } + [[nodiscard]] int countTestCases(); + [[nodiscard]] std::string toString(); void run(TestResult* result, const Test::Callback& callback = nullptr) override; diff --git a/CppUnit/include/CppUnit/Test.h b/CppUnit/include/CppUnit/Test.h index afd2938daa..df9d42927b 100644 --- a/CppUnit/include/CppUnit/Test.h +++ b/CppUnit/include/CppUnit/Test.h @@ -38,8 +38,11 @@ class CppUnit_API Test virtual ~Test() = 0; virtual void run(TestResult* result, const Callback& callback = nullptr) = 0; + [[nodiscard]] virtual int countTestCases() const = 0; + [[nodiscard]] virtual std::string toString() const = 0; + [[nodiscard]] virtual Test::Type getType() const = 0; void addSetup(const std::vector& setup); diff --git a/CppUnit/include/CppUnit/TestCase.h b/CppUnit/include/CppUnit/TestCase.h index a0e5269f4b..f0a86bd04f 100644 --- a/CppUnit/include/CppUnit/TestCase.h +++ b/CppUnit/include/CppUnit/TestCase.h @@ -123,10 +123,14 @@ class CppUnit_API TestCase: public Test void run(TestResult* result, const Test::Callback& callback = nullptr) override; virtual TestResult* run(); + [[nodiscard]] int countTestCases() const override; + [[nodiscard]] std::string toString() const override; + [[nodiscard]] Test::Type getType() const override; void setType(Test::Type testType); + [[nodiscard]] const std::string& name() const; virtual void setUp(); diff --git a/CppUnit/include/CppUnit/TestDecorator.h b/CppUnit/include/CppUnit/TestDecorator.h index 8348e13063..614eeaf4c2 100644 --- a/CppUnit/include/CppUnit/TestDecorator.h +++ b/CppUnit/include/CppUnit/TestDecorator.h @@ -33,10 +33,12 @@ class CppUnit_API TestDecorator: public Test ~TestDecorator() override; + [[nodiscard]] int countTestCases() const override; void run(TestResult* result, const Test::Callback& callback = nullptr) override; + [[nodiscard]] std::string toString() const override; protected: diff --git a/CppUnit/include/CppUnit/TestFailure.h b/CppUnit/include/CppUnit/TestFailure.h index b2ff60aae0..664e595b4b 100644 --- a/CppUnit/include/CppUnit/TestFailure.h +++ b/CppUnit/include/CppUnit/TestFailure.h @@ -39,8 +39,11 @@ class CppUnit_API TestFailure TestFailure(Test* failedTest, CppUnitException* thrownException); ~TestFailure(); + [[nodiscard]] Test* failedTest(); + [[nodiscard]] CppUnitException* thrownException(); + [[nodiscard]] std::string toString(); protected: diff --git a/CppUnit/include/CppUnit/TestResult.h b/CppUnit/include/CppUnit/TestResult.h index a077334931..bd382d54ca 100644 --- a/CppUnit/include/CppUnit/TestResult.h +++ b/CppUnit/include/CppUnit/TestResult.h @@ -53,8 +53,11 @@ class CppUnit_API TestResult virtual void endTest(Test* test); virtual int runTests(); virtual int testErrors(); + [[nodiscard]] virtual int testFailures(); + [[nodiscard]] virtual bool wasSuccessful(); + [[nodiscard]] virtual bool shouldStop(); virtual void stop(); @@ -93,6 +96,7 @@ class CppUnit_API TestResult } }; + [[nodiscard]] static std::string demangle(const char* name); protected: diff --git a/CppUnit/include/CppUnit/TestRunner.h b/CppUnit/include/CppUnit/TestRunner.h index 602690c392..73a15e60b5 100644 --- a/CppUnit/include/CppUnit/TestRunner.h +++ b/CppUnit/include/CppUnit/TestRunner.h @@ -51,9 +51,11 @@ class CppUnit_API TestRunner protected: void printBanner(); void print(const std::string& name, Test* pTest, int indent, const std::string& parentName = ""); + [[nodiscard]] Test* find(const std::string& name, Test* pTest, const std::string& testName); void findAll(const std::string& name, Test* pTest, const std::string& testName, std::vector& results); int collectAllTestCases(Test* pTest, std::vector& tests); + [[nodiscard]] static bool matchesName(const std::string& searchName, const std::string& testName); private: diff --git a/CppUnit/include/CppUnit/TestSuite.h b/CppUnit/include/CppUnit/TestSuite.h index 8c75aa23f4..9aa1c55750 100644 --- a/CppUnit/include/CppUnit/TestSuite.h +++ b/CppUnit/include/CppUnit/TestSuite.h @@ -42,13 +42,17 @@ class CppUnit_API TestSuite: public Test ~TestSuite() override; void run(TestResult* result, const Test::Callback& callback = nullptr) override; + [[nodiscard]] int countTestCases() const override; void addTest(Test* test); + [[nodiscard]] std::string toString() const override; + [[nodiscard]] Test::Type getType() const override; virtual void deleteContents(); + [[nodiscard]] const std::vector tests() const; private: diff --git a/CppUnit/include/CppUnit/TextTestResult.h b/CppUnit/include/CppUnit/TextTestResult.h index 6be0d4eb52..58905eb42c 100644 --- a/CppUnit/include/CppUnit/TextTestResult.h +++ b/CppUnit/include/CppUnit/TextTestResult.h @@ -33,6 +33,7 @@ class CppUnit_API TextTestResult: public TestResult virtual void printHeader(std::ostream& stream); protected: + [[nodiscard]] std::string shortName(const std::string& testName); void setup(); void ignoring(const std::string ignore); diff --git a/CppUnit/include/CppUnit/estring.h b/CppUnit/include/CppUnit/estring.h index b323db9ed5..447438e987 100644 --- a/CppUnit/include/CppUnit/estring.h +++ b/CppUnit/include/CppUnit/estring.h @@ -16,6 +16,7 @@ namespace CppUnit { // Create a std::string from a const char pointer +[[nodiscard]] inline std::string estring(const char *cstring) { return std::string(cstring); @@ -23,6 +24,7 @@ inline std::string estring(const char *cstring) // Create a std::string from a std::string (for uniformities' sake) +[[nodiscard]] inline std::string estring(std::string& expandedString) { return expandedString; @@ -30,6 +32,7 @@ inline std::string estring(std::string& expandedString) // Create a std::string from an int +[[nodiscard]] inline std::string estring(int number) { char buffer[50]; @@ -39,6 +42,7 @@ inline std::string estring(int number) // Create a string from a long +[[nodiscard]] inline std::string estring(long number) { char buffer[50]; @@ -48,6 +52,7 @@ inline std::string estring(long number) // Create a std::string from a double +[[nodiscard]] inline std::string estring(double number) { char buffer[50]; @@ -57,6 +62,7 @@ inline std::string estring(double number) // Create a std::string from a double +[[nodiscard]] inline std::string estring(const void* ptr) { char buffer[50]; diff --git a/Crypto/include/Poco/Crypto/Cipher.h b/Crypto/include/Poco/Crypto/Cipher.h index b59010ba01..38800b89d5 100644 --- a/Crypto/include/Poco/Crypto/Cipher.h +++ b/Crypto/include/Poco/Crypto/Cipher.h @@ -97,6 +97,7 @@ class Crypto_API Cipher: public Poco::RefCountedObject virtual ~Cipher(); /// Destroys the Cipher. + [[nodiscard]] virtual const std::string& name() const = 0; /// Returns the name of the Cipher. @@ -106,9 +107,11 @@ class Crypto_API Cipher: public Poco::RefCountedObject virtual CryptoTransform::Ptr createDecryptor() = 0; /// Creates a decryptor object to be used with a CryptoStream. + [[nodiscard]] virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE, bool padding = true); /// Directly encrypt a string and encode it using the given encoding. + [[nodiscard]] virtual std::string decryptString(const std::string& str, Encoding encoding = ENC_NONE, bool padding = true); /// Directly decrypt a string that is encoded with the given encoding. diff --git a/Crypto/include/Poco/Crypto/CipherFactory.h b/Crypto/include/Poco/Crypto/CipherFactory.h index a01145525b..587d918209 100644 --- a/Crypto/include/Poco/Crypto/CipherFactory.h +++ b/Crypto/include/Poco/Crypto/CipherFactory.h @@ -41,6 +41,7 @@ class Crypto_API CipherFactory virtual ~CipherFactory(); /// Destroys the CipherFactory. + [[nodiscard]] Cipher* createCipher(const CipherKey& key); /// Creates a Cipher object for the given Cipher name. Valid cipher /// names depend on the OpenSSL version the library is linked with; @@ -56,14 +57,17 @@ class Crypto_API CipherFactory /// * DES: "des", "des3" /// * Blowfish: "bf" + [[nodiscard]] Cipher* createCipher(const RSAKey& key, RSAPaddingMode paddingMode = RSA_PADDING_PKCS1); /// Creates a RSACipher using the given RSA key and padding mode /// for public key encryption/private key decryption. + [[nodiscard]] Cipher* createCipher(const EVPPKey& key); /// Creates an EVPCipher using the given EVP key /// for public key encryption/private key decryption. + [[nodiscard]] static CipherFactory& defaultFactory(); /// Returns the default CipherFactory. diff --git a/Crypto/include/Poco/Crypto/CipherImpl.h b/Crypto/include/Poco/Crypto/CipherImpl.h index 146b921b8f..bc84fbaa11 100644 --- a/Crypto/include/Poco/Crypto/CipherImpl.h +++ b/Crypto/include/Poco/Crypto/CipherImpl.h @@ -38,12 +38,15 @@ class CipherImpl: public Cipher virtual ~CipherImpl(); /// Destroys the CipherImpl. + [[nodiscard]] const std::string& name() const; /// Returns the name of the cipher. + [[nodiscard]] CryptoTransform::Ptr createEncryptor(); /// Creates an encryptor object. + [[nodiscard]] CryptoTransform::Ptr createDecryptor(); /// Creates a decryptor object. diff --git a/Crypto/include/Poco/Crypto/CipherKey.h b/Crypto/include/Poco/Crypto/CipherKey.h index 05025accf8..cdd701bca7 100644 --- a/Crypto/include/Poco/Crypto/CipherKey.h +++ b/Crypto/include/Poco/Crypto/CipherKey.h @@ -104,27 +104,34 @@ class Crypto_API CipherKey CipherKey& operator = (CipherKey&& other) noexcept; /// Move assignment. + [[nodiscard]] const std::string& name() const; /// Returns the name of the Cipher. + [[nodiscard]] int keySize() const; /// Returns the key size of the Cipher. + [[nodiscard]] int blockSize() const; /// Returns the block size of the Cipher. + [[nodiscard]] int ivSize() const; /// Returns the IV size of the Cipher. - + + [[nodiscard]] Mode mode() const; /// Returns the Cipher's mode of operation. + [[nodiscard]] const ByteVec& getKey() const; /// Returns the key for the Cipher. void setKey(const ByteVec& key); /// Sets the key for the Cipher. + [[nodiscard]] const ByteVec& getIV() const; /// Returns the initialization vector (IV) for the Cipher. @@ -135,6 +142,7 @@ class Crypto_API CipherKey /// IV size (see ivSize()), except for GCM mode, which allows /// a custom IV size. + [[nodiscard]] CipherKeyImpl::Ptr impl(); /// Returns the impl object diff --git a/Crypto/include/Poco/Crypto/CipherKeyImpl.h b/Crypto/include/Poco/Crypto/CipherKeyImpl.h index a2e33f0f7c..b1ac521a32 100644 --- a/Crypto/include/Poco/Crypto/CipherKeyImpl.h +++ b/Crypto/include/Poco/Crypto/CipherKeyImpl.h @@ -75,33 +75,41 @@ class Crypto_API CipherKeyImpl: public RefCountedObject virtual ~CipherKeyImpl(); /// Destroys the CipherKeyImpl. + [[nodiscard]] const std::string& name() const; /// Returns the name of the Cipher. + [[nodiscard]] int keySize() const; /// Returns the key size of the Cipher. + [[nodiscard]] int blockSize() const; /// Returns the block size of the Cipher. + [[nodiscard]] int ivSize() const; /// Returns the IV size of the Cipher. + [[nodiscard]] Mode mode() const; /// Returns the Cipher's mode of operation. + [[nodiscard]] const ByteVec& getKey() const; /// Returns the key for the Cipher. void setKey(const ByteVec& key); /// Sets the key for the Cipher. + [[nodiscard]] const ByteVec& getIV() const; /// Returns the initialization vector (IV) for the Cipher. void setIV(const ByteVec& iv); /// Sets the initialization vector (IV) for the Cipher. + [[nodiscard]] const EVP_CIPHER* cipher(); /// Returns the cipher object diff --git a/Crypto/include/Poco/Crypto/CryptoException.h b/Crypto/include/Poco/Crypto/CryptoException.h index 5b2969b89f..dfc736b5a3 100644 --- a/Crypto/include/Poco/Crypto/CryptoException.h +++ b/Crypto/include/Poco/Crypto/CryptoException.h @@ -39,8 +39,11 @@ class Crypto_API OpenSSLException : public CryptoException OpenSSLException(const OpenSSLException& exc); ~OpenSSLException() noexcept; OpenSSLException& operator = (const OpenSSLException& exc); + [[nodiscard]] const char* name() const noexcept; + [[nodiscard]] const char* className() const noexcept; + [[nodiscard]] Poco::Exception* clone() const; void rethrow() const; diff --git a/Crypto/include/Poco/Crypto/CryptoTransform.h b/Crypto/include/Poco/Crypto/CryptoTransform.h index 688e6b166b..a9c2d5d2c0 100644 --- a/Crypto/include/Poco/Crypto/CryptoTransform.h +++ b/Crypto/include/Poco/Crypto/CryptoTransform.h @@ -43,6 +43,7 @@ class Crypto_API CryptoTransform virtual ~CryptoTransform(); /// Destroys the CryptoTransform. + [[nodiscard]] virtual std::size_t blockSize() const = 0; /// Returns the block size for this CryptoTransform. @@ -52,6 +53,7 @@ class Crypto_API CryptoTransform /// no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of /// the block size or an error will occur. + [[nodiscard]] virtual std::string getTag(std::size_t tagSize = 16) = 0; /// Returns the GCM tag after encrypting using GCM mode. /// diff --git a/Crypto/include/Poco/Crypto/DigestEngine.h b/Crypto/include/Poco/Crypto/DigestEngine.h index 657b92dbfd..a28a0ac691 100644 --- a/Crypto/include/Poco/Crypto/DigestEngine.h +++ b/Crypto/include/Poco/Crypto/DigestEngine.h @@ -42,15 +42,19 @@ class Crypto_API DigestEngine: public Poco::DigestEngine ~DigestEngine(); /// Destroys the DigestEngine. + [[nodiscard]] const std::string& algorithm() const; /// Returns the name of the digest algorithm. + [[nodiscard]] int nid() const; /// Returns the NID (OpenSSL object identifier) of the digest algorithm. // DigestEngine + [[nodiscard]] std::size_t digestLength() const; void reset(); + [[nodiscard]] const Poco::DigestEngine::Digest& digest(); protected: diff --git a/Crypto/include/Poco/Crypto/ECDSADigestEngine.h b/Crypto/include/Poco/Crypto/ECDSADigestEngine.h index 57e32923dc..1b819712d8 100644 --- a/Crypto/include/Poco/Crypto/ECDSADigestEngine.h +++ b/Crypto/include/Poco/Crypto/ECDSADigestEngine.h @@ -57,6 +57,7 @@ class Crypto_API ECDSADigestEngine: public Poco::DigestEngine ~ECDSADigestEngine(); /// Destroys the ECDSADigestEngine. + [[nodiscard]] std::size_t digestLength() const; /// Returns the length of the digest in bytes. @@ -78,6 +79,7 @@ class Crypto_API ECDSADigestEngine: public Poco::DigestEngine /// /// Can be called multiple times. + [[nodiscard]] bool verify(const DigestEngine::Digest& signature); /// Verifies the data against the signature. /// @@ -109,12 +111,15 @@ class Crypto_API ECDSASignature ~ECDSASignature(); /// Destroys the ECDSASignature. + [[nodiscard]] ByteVec toDER() const; /// Returns a buffer containing the DER-encoded signature. + [[nodiscard]] ByteVec rawR() const; /// Returns a raw P value. + [[nodiscard]] ByteVec rawS() const; /// Returns a raw Q value. diff --git a/Crypto/include/Poco/Crypto/ECKey.h b/Crypto/include/Poco/Crypto/ECKey.h index 62397f6405..6420dfc93a 100644 --- a/Crypto/include/Poco/Crypto/ECKey.h +++ b/Crypto/include/Poco/Crypto/ECKey.h @@ -88,9 +88,11 @@ class Crypto_API ECKey: public KeyPair ECKey& operator = (ECKey&& other) noexcept; /// Move assignment. + [[nodiscard]] ECKeyImpl::Ptr impl() const; /// Returns the impl object. + [[nodiscard]] static std::string getCurveName(int nid = -1); /// Returns elliptical curve name corresponding to /// the given nid; if nid is not found, returns @@ -100,12 +102,14 @@ class Crypto_API ECKey: public KeyPair /// /// If no curves are found, returns empty string; + [[nodiscard]] static int getCurveNID(std::string& name); /// Returns the NID of the specified curve. /// /// If name is empty, returns the first curve NID /// and updates the name accordingly. + [[nodiscard]] static bool hasCurve(const std::string& name); /// Returns true if the named curve is found, /// false otherwise. diff --git a/Crypto/include/Poco/Crypto/ECKeyImpl.h b/Crypto/include/Poco/Crypto/ECKeyImpl.h index d98bcc2aee..beb8084597 100644 --- a/Crypto/include/Poco/Crypto/ECKeyImpl.h +++ b/Crypto/include/Poco/Crypto/ECKeyImpl.h @@ -70,18 +70,23 @@ class Crypto_API ECKeyImpl: public KeyPairImpl ~ECKeyImpl(); /// Destroys the ECKeyImpl. + [[nodiscard]] EC_KEY* getECKey(); /// Returns the OpenSSL EC key. + [[nodiscard]] const EC_KEY* getECKey() const; /// Returns the OpenSSL EC key. + [[nodiscard]] int size() const; /// Returns the EC key length in bits. + [[nodiscard]] int groupId() const; /// Returns the EC key group integer Id. + [[nodiscard]] std::string groupName() const; /// Returns the EC key group name. @@ -101,6 +106,7 @@ class Crypto_API ECKeyImpl: public KeyPairImpl /// If a null pointer is passed for a stream, the corresponding /// key is not exported. + [[nodiscard]] static std::string getCurveName(int nid = -1); /// Returns elliptical curve name corresponding to /// the given nid; if nid is not found, returns @@ -110,12 +116,14 @@ class Crypto_API ECKeyImpl: public KeyPairImpl /// /// If no curves are found, returns empty string; + [[nodiscard]] static int getCurveNID(std::string& name); /// Returns the NID of the specified curve. /// /// If name is empty, returns the first curve NID /// and updates the name accordingly. + [[nodiscard]] static bool hasCurve(const std::string& name); /// Returns true if the named curve is found, /// false otherwise. diff --git a/Crypto/include/Poco/Crypto/EVPCipherImpl.h b/Crypto/include/Poco/Crypto/EVPCipherImpl.h index 5c8e014147..9187216422 100644 --- a/Crypto/include/Poco/Crypto/EVPCipherImpl.h +++ b/Crypto/include/Poco/Crypto/EVPCipherImpl.h @@ -44,12 +44,15 @@ class EVPCipherImpl: public Cipher virtual ~EVPCipherImpl(); /// Destroys the EVPCipherImpl. + [[nodiscard]] const std::string& name() const; /// Returns the name of the Cipher. + [[nodiscard]] CryptoTransform::Ptr createEncryptor(); /// Creates an encryptor object. + [[nodiscard]] CryptoTransform::Ptr createDecryptor(); /// Creates a decryptor object. diff --git a/Crypto/include/Poco/Crypto/EVPPKey.h b/Crypto/include/Poco/Crypto/EVPPKey.h index 9b52906472..200618ff1f 100644 --- a/Crypto/include/Poco/Crypto/EVPPKey.h +++ b/Crypto/include/Poco/Crypto/EVPPKey.h @@ -120,6 +120,7 @@ class Crypto_API EVPPKey ~EVPPKey(); /// Destroys the EVPPKey. + [[nodiscard]] bool operator == (const EVPPKey& other) const; /// Comparison operator. /// Returns true if public key components and parameters @@ -128,6 +129,7 @@ class Crypto_API EVPPKey /// Works as expected when one key contains only public key, /// while the other one contains private (thus also public) key. + [[nodiscard]] bool operator != (const EVPPKey& other) const; /// Comparison operator. /// Returns true if public key components and parameters @@ -148,18 +150,23 @@ class Crypto_API EVPPKey /// If a null pointer is passed for a stream, the corresponding /// key is not exported. + [[nodiscard]] int type() const; /// Retuns the EVPPKey type NID. + [[nodiscard]] const std::string& name() const; /// Retuns the EVPPKey name. + [[nodiscard]] bool isSupported(int type) const; /// Returns true if OpenSSL type is supported + [[nodiscard]] operator const EVP_PKEY*() const; /// Returns const pointer to the OpenSSL EVP_PKEY structure. + [[nodiscard]] operator EVP_PKEY*(); /// Returns pointer to the OpenSSL EVP_PKEY structure. diff --git a/Crypto/include/Poco/Crypto/Envelope.h b/Crypto/include/Poco/Crypto/Envelope.h index d791c2e1d7..22dc1c4567 100644 --- a/Crypto/include/Poco/Crypto/Envelope.h +++ b/Crypto/include/Poco/Crypto/Envelope.h @@ -61,15 +61,18 @@ class Crypto_API Envelope ~Envelope(); /// Destroys the Envelope. + [[nodiscard]] const ByteVec& iv() const; /// Returns the initialization vector. void addKey(const EVPPKey& key); /// Adds the key to the list of private keys. + [[nodiscard]] const EncKeyVec& keys() const; /// Returns encrypted symmetric keys. + [[nodiscard]] int cipherNID() const; /// Reurns the cipher NID. @@ -79,6 +82,7 @@ class Crypto_API Envelope const ByteVec& seal(const ByteVec& plainData); /// Encrypts the given data and returns the encrypted data. + [[nodiscard]] const ByteVec& getContent() const; /// Returns the encrypted content. @@ -91,6 +95,7 @@ class Crypto_API Envelope std::string openAsString(const EVPPKey& privKey, const ByteVec& encKeys, const ByteVec& iv = ByteVec()); /// Decrypts the stored encrypted data and returns it. + [[nodiscard]] static std::string toString(const ByteVec& data); /// Converts and returns string from ByteVec. @@ -98,7 +103,9 @@ class Crypto_API Envelope Envelope(int cipherNID); Envelope(int cipherNID, const ByteVec& iv); + [[nodiscard]] int ivSize() const; + [[nodiscard]] int blockSize() const; void handleErrors(std::string&& msg); diff --git a/Crypto/include/Poco/Crypto/KeyPair.h b/Crypto/include/Poco/Crypto/KeyPair.h index c4643e9aa4..c67d36c0b2 100644 --- a/Crypto/include/Poco/Crypto/KeyPair.h +++ b/Crypto/include/Poco/Crypto/KeyPair.h @@ -61,6 +61,7 @@ class Crypto_API KeyPair virtual ~KeyPair(); /// Destroys the KeyPair. + [[nodiscard]] virtual int size() const; /// Returns the RSA modulus size. @@ -80,12 +81,15 @@ class Crypto_API KeyPair /// If a null pointer is passed for a stream, the corresponding /// key is not exported. + [[nodiscard]] KeyPairImpl::Ptr impl() const; /// Returns the impl object. + [[nodiscard]] const std::string& name() const; /// Returns key pair name + [[nodiscard]] Type type() const; /// Returns key pair type diff --git a/Crypto/include/Poco/Crypto/KeyPairImpl.h b/Crypto/include/Poco/Crypto/KeyPairImpl.h index 8cd680c1de..43d8ad019b 100644 --- a/Crypto/include/Poco/Crypto/KeyPairImpl.h +++ b/Crypto/include/Poco/Crypto/KeyPairImpl.h @@ -49,6 +49,7 @@ class Crypto_API KeyPairImpl: public Poco::RefCountedObject virtual ~KeyPairImpl(); /// Destroys the KeyPairImpl. + [[nodiscard]] virtual int size() const = 0; /// Returns the key size. @@ -68,9 +69,11 @@ class Crypto_API KeyPairImpl: public Poco::RefCountedObject /// If a null pointer is passed for a stream, the corresponding /// key is not exported. + [[nodiscard]] const std::string& name() const; /// Returns key pair name + [[nodiscard]] Type type() const; /// Returns key pair type diff --git a/Crypto/include/Poco/Crypto/OpenSSLInitializer.h b/Crypto/include/Poco/Crypto/OpenSSLInitializer.h index ed1b72abd5..c8635af626 100644 --- a/Crypto/include/Poco/Crypto/OpenSSLInitializer.h +++ b/Crypto/include/Poco/Crypto/OpenSSLInitializer.h @@ -49,12 +49,14 @@ class Crypto_API OpenSSLInitializer static void uninitialize(); /// Shuts down the OpenSSL machinery. + [[nodiscard]] static bool isFIPSEnabled(); /// Returns true if FIPS mode is enabled, false otherwise. static void enableFIPSMode(bool enabled); /// Enable or disable FIPS mode. If FIPS is not available, this method doesn't do anything. + [[nodiscard]] static bool haveLegacyProvider(); /// Returns true if the OpenSSL legacy provider is available, otherwise false. diff --git a/Crypto/include/Poco/Crypto/PKCS12Container.h b/Crypto/include/Poco/Crypto/PKCS12Container.h index 369219b028..f769a484fb 100644 --- a/Crypto/include/Poco/Crypto/PKCS12Container.h +++ b/Crypto/include/Poco/Crypto/PKCS12Container.h @@ -59,30 +59,38 @@ class Crypto_API PKCS12Container ~PKCS12Container(); /// Destroys the PKCS12Container. + [[nodiscard]] bool hasKey() const; /// Returns true if container contains the key. + [[nodiscard]] EVPPKey getKey() const; /// Return key as openssl EVP_PKEY wrapper object. + [[nodiscard]] bool hasX509Certificate() const; /// Returns true if container has X509 certificate. + [[nodiscard]] const X509Certificate& getX509Certificate() const; /// Returns the X509 certificate. /// Throws NotFoundException if there is no certificate. + [[nodiscard]] const CAList& getCACerts() const; /// Returns the list of CA certificates in this container. + [[nodiscard]] const std::string& getFriendlyName() const; /// Returns the friendly name of the certificate bag. + [[nodiscard]] const CANameList& getFriendlyNamesCA() const; /// Returns a list of CA certificates friendly names. private: void load(PKCS12* pPKCS12, const std::string& password = ""); + [[nodiscard]] std::string extractFriendlyName(X509* pCert); using CertPtr = std::unique_ptr; diff --git a/Crypto/include/Poco/Crypto/RSACipherImpl.h b/Crypto/include/Poco/Crypto/RSACipherImpl.h index 5fc9f10bfb..16a1b53906 100644 --- a/Crypto/include/Poco/Crypto/RSACipherImpl.h +++ b/Crypto/include/Poco/Crypto/RSACipherImpl.h @@ -45,12 +45,15 @@ class RSACipherImpl: public Cipher virtual ~RSACipherImpl(); /// Destroys the RSACipherImpl. + [[nodiscard]] const std::string& name() const; /// Returns the name of the Cipher. + [[nodiscard]] CryptoTransform::Ptr createEncryptor(); /// Creates an encryptor object. + [[nodiscard]] CryptoTransform::Ptr createDecryptor(); /// Creates a decryptor object. diff --git a/Crypto/include/Poco/Crypto/RSADigestEngine.h b/Crypto/include/Poco/Crypto/RSADigestEngine.h index bbddf55abc..375d75451e 100644 --- a/Crypto/include/Poco/Crypto/RSADigestEngine.h +++ b/Crypto/include/Poco/Crypto/RSADigestEngine.h @@ -67,6 +67,7 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine ~RSADigestEngine(); /// Destroys the RSADigestEngine. + [[nodiscard]] std::size_t digestLength() const; /// Returns the length of the digest in bytes. @@ -88,6 +89,7 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine /// /// Can be called multiple times. + [[nodiscard]] bool verify(const DigestEngine::Digest& signature); /// Verifies the data against the signature. /// diff --git a/Crypto/include/Poco/Crypto/RSAKey.h b/Crypto/include/Poco/Crypto/RSAKey.h index fe495b68f6..acdf7ba117 100644 --- a/Crypto/include/Poco/Crypto/RSAKey.h +++ b/Crypto/include/Poco/Crypto/RSAKey.h @@ -105,15 +105,19 @@ class Crypto_API RSAKey: public KeyPair RSAKey& operator = (RSAKey&& other) noexcept; /// Move assignment. + [[nodiscard]] RSAKeyImpl::ByteVec modulus() const; /// Returns the RSA modulus. + [[nodiscard]] RSAKeyImpl::ByteVec encryptionExponent() const; /// Returns the RSA encryption exponent. + [[nodiscard]] RSAKeyImpl::ByteVec decryptionExponent() const; /// Returns the RSA decryption exponent. + [[nodiscard]] RSAKeyImpl::Ptr impl() const; /// Returns the impl object. }; diff --git a/Crypto/include/Poco/Crypto/RSAKeyImpl.h b/Crypto/include/Poco/Crypto/RSAKeyImpl.h index 5c1b5edf83..3518875607 100644 --- a/Crypto/include/Poco/Crypto/RSAKeyImpl.h +++ b/Crypto/include/Poco/Crypto/RSAKeyImpl.h @@ -75,21 +75,27 @@ class Crypto_API RSAKeyImpl: public KeyPairImpl ~RSAKeyImpl(); /// Destroys the RSAKeyImpl. + [[nodiscard]] RSA* getRSA(); /// Returns the OpenSSL RSA object. + [[nodiscard]] const RSA* getRSA() const; /// Returns the OpenSSL RSA object. + [[nodiscard]] int size() const; /// Returns the RSA modulus size. + [[nodiscard]] ByteVec modulus() const; /// Returns the RSA modulus. + [[nodiscard]] ByteVec encryptionExponent() const; /// Returns the RSA encryption exponent. + [[nodiscard]] ByteVec decryptionExponent() const; /// Returns the RSA decryption exponent. @@ -113,6 +119,7 @@ class Crypto_API RSAKeyImpl: public KeyPairImpl RSAKeyImpl(); void freeRSA(); + [[nodiscard]] static ByteVec convertToByteVec(const BIGNUM* bn); RSA* _pRSA; diff --git a/Crypto/include/Poco/Crypto/X509Certificate.h b/Crypto/include/Poco/Crypto/X509Certificate.h index 91ffb6255e..8d53072a73 100644 --- a/Crypto/include/Poco/Crypto/X509Certificate.h +++ b/Crypto/include/Poco/Crypto/X509Certificate.h @@ -89,29 +89,36 @@ class Crypto_API X509Certificate ~X509Certificate(); /// Destroys the X509Certificate. + [[nodiscard]] long version() const; /// Returns the version of the certificate. + [[nodiscard]] const std::string& serialNumber() const; /// Returns the certificate serial number as a /// string in decimal encoding. + [[nodiscard]] const std::string& issuerName() const; /// Returns the certificate issuer's distinguished name. + [[nodiscard]] std::string issuerName(NID nid) const; /// Extracts the information specified by the given /// NID (name identifier) from the certificate issuer's /// distinguished name. + [[nodiscard]] const std::string& subjectName() const; /// Returns the certificate subject's distinguished name. + [[nodiscard]] std::string subjectName(NID nid) const; /// Extracts the information specified by the given /// NID (name identifier) from the certificate subject's /// distinguished name. + [[nodiscard]] std::string commonName() const; /// Returns the common name stored in the certificate /// subject's distinguished name. @@ -120,9 +127,11 @@ class Crypto_API X509Certificate /// Extracts the common name and the alias domain names from the /// certificate. + [[nodiscard]] Poco::DateTime validFrom() const; /// Returns the date and time the certificate is valid from. + [[nodiscard]] Poco::DateTime expiresOn() const; /// Returns the date and time the certificate expires. @@ -139,6 +148,7 @@ class Crypto_API X509Certificate /// Writes the certificate to the file given by path. /// The certificate is written in PEM format. + [[nodiscard]] bool issuedBy(const X509Certificate& issuerCertificate) const; /// Checks whether the certificate has been issued by /// the issuer given by issuerCertificate. This can be @@ -151,6 +161,7 @@ class Crypto_API X509Certificate /// Returns true if verification against the issuer certificate /// was successful, false otherwise. + [[nodiscard]] bool equals(const X509Certificate& otherCertificate) const; /// Checks whether the certificate is equal to /// the other certificate, by comparing the hashes @@ -159,14 +170,17 @@ class Crypto_API X509Certificate /// Returns true if both certificates are identical, /// otherwise false. + [[nodiscard]] const X509* certificate() const; /// Returns the underlying OpenSSL certificate. + [[nodiscard]] X509* dup() const; /// Duplicates and returns the underlying OpenSSL certificate. Note that /// the caller assumes responsibility for the lifecycle of the created /// certificate. + [[nodiscard]] std::string signatureAlgorithm() const; /// Returns the certificate signature algorithm long name. diff --git a/Crypto/src/CipherKeyImpl.cpp b/Crypto/src/CipherKeyImpl.cpp index 86af2afd76..4e264ffc99 100644 --- a/Crypto/src/CipherKeyImpl.cpp +++ b/Crypto/src/CipherKeyImpl.cpp @@ -54,8 +54,8 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name, _key(), _iv() { - // dummy access to Cipherfactory so that the EVP lib is initilaized - CipherFactory::defaultFactory(); + // dummy access to Cipherfactory so that the EVP lib is initialized + (void)CipherFactory::defaultFactory(); _pCipher = EVP_get_cipherbyname(name.c_str()); if (!_pCipher) @@ -82,7 +82,7 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name, _iv(iv) { // dummy access to Cipherfactory so that the EVP lib is initialized - CipherFactory::defaultFactory(); + (void)CipherFactory::defaultFactory(); _pCipher = EVP_get_cipherbyname(name.c_str()); if (!_pCipher) @@ -97,8 +97,8 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name): _key(), _iv() { - // dummy access to Cipherfactory so that the EVP lib is initilaized - CipherFactory::defaultFactory(); + // dummy access to Cipherfactory so that the EVP lib is initialized + (void)CipherFactory::defaultFactory(); _pCipher = EVP_get_cipherbyname(name.c_str()); if (!_pCipher) diff --git a/DNSSD/Avahi/include/Poco/DNSSD/Avahi/AvahiResponderImpl.h b/DNSSD/Avahi/include/Poco/DNSSD/Avahi/AvahiResponderImpl.h index 4871194ddd..4c3ec77cc9 100644 --- a/DNSSD/Avahi/include/Poco/DNSSD/Avahi/AvahiResponderImpl.h +++ b/DNSSD/Avahi/include/Poco/DNSSD/Avahi/AvahiResponderImpl.h @@ -53,6 +53,7 @@ class DNSSD_Avahi_API AvahiResponderImpl: public Poco::DNSSD::DNSSDResponderImpl /// Destroys the AvahiResponderImpl. // DNSSDResponderImpl + [[nodiscard]] DNSSDBrowser& browser(); ServiceHandle registerService(const Service& service, int options); void unregisterService(ServiceHandle& serviceHandle); @@ -66,6 +67,7 @@ class DNSSD_Avahi_API AvahiResponderImpl: public Poco::DNSSD::DNSSDResponderImpl void run(); // Implementation + [[nodiscard]] static const char* describeError(int code); /// Returns a human-readable string describing the error. @@ -97,6 +99,7 @@ class DNSSD_Avahi_API AvahiResponderImpl: public Poco::DNSSD::DNSSDResponderImpl void reregisterServices(); void setupEntryGroup(AvahiEntryGroup* avahiGroup, const Service& service, const RecordVec& records, int options, bool rename); + [[nodiscard]] static AvahiStringList* createTXTRecord(const Service::Properties& properties); private: diff --git a/DNSSD/Bonjour/include/Poco/DNSSD/Bonjour/BonjourResponderImpl.h b/DNSSD/Bonjour/include/Poco/DNSSD/Bonjour/BonjourResponderImpl.h index 058680096d..6ac6a35498 100644 --- a/DNSSD/Bonjour/include/Poco/DNSSD/Bonjour/BonjourResponderImpl.h +++ b/DNSSD/Bonjour/include/Poco/DNSSD/Bonjour/BonjourResponderImpl.h @@ -42,6 +42,7 @@ class DNSSD_Bonjour_API BonjourResponderImpl: public Poco::DNSSD::DNSSDResponder /// Destroys the BonjourResponderImpl. // DNSSDResponderImpl + [[nodiscard]] DNSSDBrowser& browser() override; ServiceHandle registerService(const Service& service, int options) override; void unregisterService(ServiceHandle& serviceHandle) override; @@ -52,12 +53,14 @@ class DNSSD_Bonjour_API BonjourResponderImpl: public Poco::DNSSD::DNSSDResponder void stop() override; // Implementation + [[nodiscard]] static const char* describeError(int code); /// Returns a human-readable string describing the error. void onRegisterServiceReply(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char* name, const char* regtype, const char* domain); protected: + [[nodiscard]] static std::string createTXTRecord(const Service::Properties& properties); private: @@ -73,6 +76,7 @@ class DNSSD_Bonjour_API BonjourResponderImplFactory: public Poco::DNSSD::DNSSDRe /// A factory for BonjourResponderImplFactory objects. { public: + [[nodiscard]] DNSSDResponderImpl* createResponderImpl(Poco::DNSSD::DNSSDResponder& owner) { return new BonjourResponderImpl(owner); diff --git a/DNSSD/include/Poco/DNSSD/DNSSD.h b/DNSSD/include/Poco/DNSSD/DNSSD.h index 7ca0f9376b..94584a2e22 100644 --- a/DNSSD/include/Poco/DNSSD/DNSSD.h +++ b/DNSSD/include/Poco/DNSSD/DNSSD.h @@ -120,42 +120,50 @@ class OpaqueHandle { } + [[nodiscard]] int subtype() const { return _subtype; } template + [[nodiscard]] T cast() const { return reinterpret_cast(_h); } + [[nodiscard]] bool operator == (const OpaqueHandle& other) const { return _h == other._h; } + [[nodiscard]] bool operator != (const OpaqueHandle& other) const { return _h != other._h; } + [[nodiscard]] bool operator <= (const OpaqueHandle& other) const { return _h <= other._h; } + [[nodiscard]] bool operator < (const OpaqueHandle& other) const { return _h < other._h; } + [[nodiscard]] bool operator >= (const OpaqueHandle& other) const { return _h >= other._h; } + [[nodiscard]] bool operator > (const OpaqueHandle& other) const { return _h > other._h; @@ -166,11 +174,13 @@ class OpaqueHandle _h = Invalid; } + [[nodiscard]] bool isValid() const { return _h != Invalid; } + [[nodiscard]] bool isNull() const { return _h == Invalid; diff --git a/DNSSD/include/Poco/DNSSD/DNSSDResponder.h b/DNSSD/include/Poco/DNSSD/DNSSDResponder.h index 81e734cae9..4e2df3ba79 100644 --- a/DNSSD/include/Poco/DNSSD/DNSSDResponder.h +++ b/DNSSD/include/Poco/DNSSD/DNSSDResponder.h @@ -117,6 +117,7 @@ class DNSSD_API DNSSDResponder ~DNSSDResponder(); /// Destroys the DNSSDResponder. + [[nodiscard]] DNSSDBrowser& browser(); /// Returns the DNSServiceBrowser, which is used to /// discover and resolve services and domains. diff --git a/DNSSD/include/Poco/DNSSD/DNSSDResponderImpl.h b/DNSSD/include/Poco/DNSSD/DNSSDResponderImpl.h index c896a56f71..d4ff27cf86 100644 --- a/DNSSD/include/Poco/DNSSD/DNSSDResponderImpl.h +++ b/DNSSD/include/Poco/DNSSD/DNSSDResponderImpl.h @@ -40,6 +40,7 @@ class DNSSD_API DNSSDResponderImpl virtual ~DNSSDResponderImpl(); /// Destroys the DNSSDResponderImpl. + [[nodiscard]] virtual DNSSDBrowser& browser() = 0; /// Returns the DNSSDBrowser, which is used to /// discover and resolve services and domains. @@ -104,6 +105,7 @@ class DNSSD_API DNSSDResponderImplFactory /// implementations and registered with the DNSSDResponder class. { public: + [[nodiscard]] virtual DNSSDResponderImpl* createResponderImpl(DNSSDResponder& owner) = 0; /// Creates a new DNSSDResponderImpl. diff --git a/DNSSD/include/Poco/DNSSD/Domain.h b/DNSSD/include/Poco/DNSSD/Domain.h index 38df15b044..ac4bc1fdaa 100644 --- a/DNSSD/include/Poco/DNSSD/Domain.h +++ b/DNSSD/include/Poco/DNSSD/Domain.h @@ -43,12 +43,15 @@ class DNSSD_API Domain ~Domain(); /// Destroys the Domain. + [[nodiscard]] Poco::Int32 networkInterface() const; /// Returns the index of the network interface the domain was discovered on. + [[nodiscard]] const std::string& name() const; /// Returns the name of the domain. + [[nodiscard]] bool isDefault() const; /// Returns true if the domain is the default domain. diff --git a/DNSSD/include/Poco/DNSSD/Error.h b/DNSSD/include/Poco/DNSSD/Error.h index 75890043e0..7107b3f590 100644 --- a/DNSSD/include/Poco/DNSSD/Error.h +++ b/DNSSD/include/Poco/DNSSD/Error.h @@ -45,12 +45,15 @@ class DNSSD_API Error ~Error(); /// Destroys the ServiceError. + [[nodiscard]] Poco::Int32 networkInterface() const; /// Returns the network interface on which the error occurred. + [[nodiscard]] Poco::Int32 code() const; /// Returns the implementation-specific error code. + [[nodiscard]] const std::string& message() const; /// Returns the human-readable error message. diff --git a/DNSSD/include/Poco/DNSSD/Record.h b/DNSSD/include/Poco/DNSSD/Record.h index 413c36e939..57a5273bd7 100644 --- a/DNSSD/include/Poco/DNSSD/Record.h +++ b/DNSSD/include/Poco/DNSSD/Record.h @@ -138,25 +138,32 @@ class DNSSD_API Record ~Record(); /// Destroys the Service. + [[nodiscard]] Poco::Int32 networkInterface() const; /// The id of the interface on which the remote service is running, or zero /// if no interface has been specified. + [[nodiscard]] const std::string& name() const; /// The full domain name of the record. + [[nodiscard]] Poco::UInt16 type() const; /// The record's type (e.g., RT_PTR). + [[nodiscard]] Poco::UInt16 clazz() const; /// The record's class, which is usually RC_IN. + [[nodiscard]] Poco::UInt16 length() const; /// The length of the record. + [[nodiscard]] const void* data() const; /// The actual data. + [[nodiscard]] Poco::UInt32 ttl() const; /// The time-to-live for the record in seconds. diff --git a/DNSSD/include/Poco/DNSSD/Service.h b/DNSSD/include/Poco/DNSSD/Service.h index cdaf2f740f..e9c272abd1 100644 --- a/DNSSD/include/Poco/DNSSD/Service.h +++ b/DNSSD/include/Poco/DNSSD/Service.h @@ -127,13 +127,16 @@ class DNSSD_API Service ~Service(); /// Destroys the Service. + [[nodiscard]] Poco::Int32 networkInterface() const; /// The id of the interface on which the remote service is running, or zero /// if the service is available on all interfaces. + [[nodiscard]] const std::string& name() const; /// The name of the service. + [[nodiscard]] const std::string& fullName() const; /// Returns the full name of the service. /// @@ -141,6 +144,7 @@ class DNSSD_API Service /// This name is escaped following standard DNS rules. /// The full name will be empty for an unresolved service. + [[nodiscard]] const std::string& type() const; /// The registration type of the service, consisting of service type /// and network protocol (delimited by a dot, as in "_ftp._tcp"), @@ -148,24 +152,29 @@ class DNSSD_API Service /// /// The protocol is always either "_tcp" or "_udp". + [[nodiscard]] const std::string& domain() const; /// The domain the service is registered on. + [[nodiscard]] const std::string& host() const; /// Returns the host name of the host providing the service. /// /// Will be empty for an unresolved service. + [[nodiscard]] Poco::UInt16 port() const; /// Returns the port number on which the service is available. /// /// Will be 0 for an unresolved service. + [[nodiscard]] const Properties& properties() const; /// Returns the contents of the TXT record associated with the service. /// /// Will be empty for an unresolved service. + [[nodiscard]] Properties& properties(); /// Returns the contents of the TXT record associated with the service. /// diff --git a/Data/DataTest/src/SQLExecutor.cpp b/Data/DataTest/src/SQLExecutor.cpp index 2d02ec316a..27002e8973 100644 --- a/Data/DataTest/src/SQLExecutor.cpp +++ b/Data/DataTest/src/SQLExecutor.cpp @@ -376,17 +376,17 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c { sp.setFeature("autoBind"s, true); fail("SessionPool must throw on setFeature after the first session was created.", __LINE__, __FILE__); - } catch(const Poco::InvalidAccessException&) {} + } catch([[maybe_unused]] const Poco::InvalidAccessException& e) {} try { sp.setProperty("storage"s, "deque"s); fail("SessionPool must throw on valid setProperty after the first session was created.", __LINE__, __FILE__); - } catch(const Poco::InvalidAccessException&) {} + } catch([[maybe_unused]] const Poco::InvalidAccessException& e) {} try { sp.setFeature("bulk"s, true); fail("SessionPool must throw on valid setFeature after the first session was created.", __LINE__, __FILE__); - } catch(const Poco::InvalidAccessException&) {} + } catch([[maybe_unused]] const Poco::InvalidAccessException& e) {} std::vector sessions; for (int i = 0; i < maxSessions-minSessions; ++i) @@ -398,23 +398,23 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c { Session s = sp.get(); fail("SessionPool must throw when no sesions available.", __LINE__, __FILE__); - } catch(const Poco::Data::SessionPoolExhaustedException&) {} + } catch([[maybe_unused]] const Poco::Data::SessionPoolExhaustedException& e) {} sp.shutdown(); try { Session s = sp.get(); fail("SessionPool that was shut down must throw on get.", __LINE__, __FILE__); - } catch(const Poco::InvalidAccessException&) {} + } catch([[maybe_unused]] const Poco::InvalidAccessException& e) {} { SessionPool pool(connector, connectString, 1, 4, 2, 10); - try { pool.getFeature("g1"); fail ("getting an unsuported feature must fail", __LINE__, __FILE__); } - catch ( Poco::NotFoundException& ) { } + try { [[maybe_unused]] bool feature = pool.getFeature("g1"); fail ("getting an unsuported feature must fail", __LINE__, __FILE__); } + catch ( [[maybe_unused]] Poco::NotFoundException& e ) { } - try { pool.getProperty("r1"); fail ("getting an unsuported property must fail", __LINE__, __FILE__); } - catch ( Poco::NotFoundException& ) { } + try { [[maybe_unused]] Poco::Any property = pool.getProperty("r1"); fail ("getting an unsuported property must fail", __LINE__, __FILE__); } + catch ( [[maybe_unused]] Poco::NotFoundException& e ) { } assertTrue (pool.capacity() == 4); assertTrue (pool.allocated() == 0); @@ -426,14 +426,14 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c Session ss1(pool.get()); try { pool.setFeature("f1", true); fail ("setting an unsuported feature must fail", __LINE__, __FILE__); } - catch (Poco::InvalidAccessException&) { } - catch (Poco::NotImplementedException&) { } - catch (Poco::Data::NotSupportedException&) { } + catch ([[maybe_unused]] Poco::InvalidAccessException& e) { } + catch ([[maybe_unused]] Poco::NotImplementedException& e) { } + catch ([[maybe_unused]] Poco::Data::NotSupportedException& e) { } try { pool.setProperty("p1", 1); fail ("setting an unsuported property must fail", __LINE__, __FILE__); } - catch (Poco::InvalidAccessException&) { } - catch (Poco::NotImplementedException&) { } - catch (Poco::Data::NotSupportedException&) { } + catch ([[maybe_unused]] Poco::InvalidAccessException& e) { } + catch ([[maybe_unused]] Poco::NotImplementedException& e) { } + catch ([[maybe_unused]] Poco::Data::NotSupportedException& e) { } assertTrue (pool.capacity() == 4); assertTrue (pool.allocated() == 1); @@ -475,7 +475,7 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c Session s6(pool.get()); fail("pool exhausted - must throw", __LINE__, __FILE__); } - catch (Poco::Data::SessionPoolExhaustedException&) { } + catch ([[maybe_unused]] const Poco::Data::SessionPoolExhaustedException& e) {} s5.close(); assertTrue (pool.capacity() == 4); @@ -491,7 +491,7 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c s5 << "DROP TABLE IF EXISTS Test", now; fail("session unusable - must throw", __LINE__, __FILE__); } - catch (Poco::Data::SessionUnavailableException&) { } + catch ([[maybe_unused]] Poco::Data::SessionUnavailableException& e) { } s4.close(); assertTrue (pool.capacity() == 4); @@ -539,7 +539,7 @@ void SQLExecutor::sessionPool(const std::string& connector, const std::string& c Session s7(pool.get()); fail("pool shut down - must throw", __LINE__, __FILE__); } - catch (InvalidAccessException&) { } + catch ([[maybe_unused]] Poco::InvalidAccessException& e) { } assertTrue (pool.capacity() == 4); assertTrue (pool.allocated() == 0); @@ -2853,14 +2853,14 @@ void SQLExecutor::internalExtraction() int i = rset.value(0,0); assertTrue (1 == i); } - catch(BadCastException&) + catch([[maybe_unused]] BadCastException& e) { try { Poco::Int64 l = rset.value(0,0); assertTrue (1 == l); } - catch(BadCastException&) // Oracle really has no integers + catch([[maybe_unused]] BadCastException& e) // Oracle really has no integers { double l = rset.value(0,0); assertTrue (0.9 < l && l < 1.1); @@ -2875,14 +2875,14 @@ void SQLExecutor::internalExtraction() int a = rset.value(0,2); assertTrue (3 == a); } - catch(BadCastException&) + catch([[maybe_unused]] BadCastException& e) { try { Poco::Int64 l = rset.value(0,2); assertTrue (3 == l); } - catch(BadCastException&) // Oracle really has no integers + catch([[maybe_unused]] BadCastException& e) // Oracle really has no integers { double l = rset.value(0,2); assertTrue (2.9 < l && l < 3.1); @@ -2894,7 +2894,7 @@ void SQLExecutor::internalExtraction() double d = rset.value(1,1); assertTrue (2.5 == d); } - catch (BadCastException&) + catch ([[maybe_unused]] BadCastException& e) { float f = rset.value(1,1); assertTrue (2.5 == f); @@ -2904,7 +2904,7 @@ void SQLExecutor::internalExtraction() { s = rset.value(2, 2); } - catch (BadCastException&) + catch ([[maybe_unused]] BadCastException& e) { UTF16String us = rset.value(2, 2); Poco::UnicodeConverter::convert(us, s); @@ -2922,7 +2922,7 @@ void SQLExecutor::internalExtraction() for (int j = 1; it != end; ++it, ++j) assertTrue (*it == j); } - catch(BadCastException&) + catch([[maybe_unused]] BadCastException& e) { try { @@ -2932,7 +2932,7 @@ void SQLExecutor::internalExtraction() for (Poco::Int64 l = 1; it != end; ++it, ++l) assertTrue (*it == l); } - catch(BadCastException&) // Oracle really has no integers + catch([[maybe_unused]] BadCastException& e) // Oracle really has no integers { const Column>& col = rset.column >(0); Column>::Iterator it = col.begin(); @@ -2951,7 +2951,7 @@ void SQLExecutor::internalExtraction() int ii = rset.value(0,0); assertEqual (4, ii); } - catch(BadCastException&) + catch([[maybe_unused]] BadCastException& e) { try { @@ -2959,7 +2959,7 @@ void SQLExecutor::internalExtraction() double d = rset.value(0,0); assertEqual (4, int(d)); } - catch(BadCastException&) + catch([[maybe_unused]] BadCastException& e) { //this is for PostgreSQL Poco::Int64 big = rset.value(0,0); @@ -2970,17 +2970,17 @@ void SQLExecutor::internalExtraction() s = rset.value("cnt", 0).convert(); assertTrue ("4" == s); - try { rset.column >(100); fail ("must fail"); } - catch (RangeException&) { } + try { [[maybe_unused]] auto col = rset.column >(100); fail ("must fail"); } + catch ([[maybe_unused]] RangeException& e) { } - try { rset.value(0,0); fail ("must fail"); } - catch (BadCastException&) { } + try { [[maybe_unused]] auto val = rset.value(0,0); fail ("must fail"); } + catch ([[maybe_unused]] BadCastException& e) { } stmt = (session() << "DELETE FROM Vectors", now); rset = stmt; - try { rset.column >(0); fail ("must fail"); } - catch (RangeException&) { } + try { [[maybe_unused]] auto col = rset.column >(0); fail ("must fail"); } + catch ([[maybe_unused]] RangeException& e) { } } catch(DataException& ce) { @@ -3026,7 +3026,7 @@ void SQLExecutor::filter(const std::string& query, const std::string& intFldName { da = rset.value(0, 1); fail ("must fail"); - } catch (InvalidAccessException&) + } catch ([[maybe_unused]] InvalidAccessException& e) { da = rset.value(0, 1, false); assertTrue (2 == da); diff --git a/Data/MySQL/include/Poco/Data/MySQL/Binder.h b/Data/MySQL/include/Poco/Data/MySQL/Binder.h index 339d45e8d8..ec98573e14 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/Binder.h +++ b/Data/MySQL/include/Poco/Data/MySQL/Binder.h @@ -227,9 +227,11 @@ class MySQL_API Binder: public Poco::Data::AbstractBinder void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; + [[nodiscard]] std::size_t size() const; /// Return count of binded parameters + [[nodiscard]] MYSQL_BIND* getBindArray() const; /// Return array diff --git a/Data/MySQL/include/Poco/Data/MySQL/Connector.h b/Data/MySQL/include/Poco/Data/MySQL/Connector.h index 02479852e9..35a7ba0f4b 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/Connector.h +++ b/Data/MySQL/include/Poco/Data/MySQL/Connector.h @@ -37,9 +37,11 @@ class MySQL_API Connector: public Poco::Data::Connector ~Connector() override; /// Destroys the Connector. + [[nodiscard]] const std::string& name() const override; /// Returns the name associated with this connector. + [[nodiscard]] Poco::AutoPtr createSession(const std::string& connectionString, std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT) override; /// Creates a MySQL SessionImpl object and initializes it with the given connectionString. diff --git a/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h b/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h index 93f0a1669a..23332bc145 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h +++ b/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h @@ -51,12 +51,15 @@ class MySQL_API MySQLException: public Poco::Data::DataException MySQLException& operator=(const MySQLException& exc); /// Assignment operator. + [[nodiscard]] const char* name() const noexcept; /// Returns exception name. + [[nodiscard]] const char* className() const noexcept; /// Returns the name of the exception class. + [[nodiscard]] Poco::Exception* clone() const; /// Creates an exact copy of the exception. /// diff --git a/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h b/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h index 91d028da9b..9bc1174e21 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h +++ b/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h @@ -43,26 +43,33 @@ class MySQL_API MySQLStatementImpl: public Poco::Data::StatementImpl /// Destroys the MySQLStatementImpl. protected: + [[nodiscard]] std::size_t columnsReturned() const override; /// Returns number of columns returned by query. + [[nodiscard]] int affectedRowCount() const override; /// Returns the number of affected rows. /// Used to find out the number of rows affected by insert, delete or update. + [[nodiscard]] const MetaColumn& metaColumn(std::size_t pos) const override; /// Returns column meta data. + [[nodiscard]] bool hasNext() override; /// Returns true if a call to next() will return data. + [[nodiscard]] std::size_t next() override; /// Retrieves the next row from the resultset. /// Will throw, if the resultset is empty. + [[nodiscard]] bool canBind() const override; /// Returns true if a valid statement is set and we can bind. + [[nodiscard]] bool canCompile() const override; /// Returns true if another compile is possible. @@ -72,9 +79,11 @@ class MySQL_API MySQLStatementImpl: public Poco::Data::StatementImpl void bindImpl() override; /// Binds parameters + [[nodiscard]] Poco::Data::AbstractExtractor::Ptr extractor() override; /// Returns the concrete extractor used by the statement. + [[nodiscard]] Poco::Data::AbstractBinder::Ptr binder() override; /// Returns the concrete binder used by the statement. diff --git a/Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h b/Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h index dd16585416..a2baeb710e 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h +++ b/Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h @@ -47,21 +47,27 @@ class ResultMetadata void init(MYSQL_STMT* stmt); /// Initializes the metadata. + [[nodiscard]] std::size_t columnsReturned() const; /// Returns the number of columns in resultset. + [[nodiscard]] const MetaColumn& metaColumn(std::size_t pos) const; /// Returns the reference to the specified metacolumn. + [[nodiscard]] MYSQL_BIND* row(); /// Returns pointer to native row. + [[nodiscard]] std::size_t length(std::size_t pos) const; /// Returns the length. + [[nodiscard]] const unsigned char* rawData(std::size_t pos) const; /// Returns raw data. + [[nodiscard]] bool isNull(std::size_t pos) const; /// Returns true if value at pos is null. diff --git a/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h b/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h index 7659f420af..4b887ee09f 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h +++ b/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h @@ -75,9 +75,11 @@ class SessionHandle void reset(); /// Reset connection with dababase and clears session state, but without disconnecting + [[nodiscard]] bool ping(); /// Checks if the connection is alive. + [[nodiscard]] operator MYSQL* (); private: diff --git a/Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h b/Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h index 1b9b468608..de4418ff13 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h +++ b/Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h @@ -70,6 +70,7 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl ~SessionImpl() override; /// Destroys the SessionImpl. + [[nodiscard]] Poco::SharedPtr createStatementImpl() override; /// Returns an MySQL StatementImpl @@ -82,9 +83,11 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl void reset() override; /// Reset connection with dababase and clears session state, but without disconnecting + [[nodiscard]] bool isConnected() const override; /// Returns true if connected, false otherwise. + [[nodiscard]] bool isGood() const override; /// Returns true iff the database session is good. /// For the session to be considered good: @@ -100,6 +103,7 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl void setConnectionTimeout(std::size_t timeout) override; /// Sets the session connection timeout value. + [[nodiscard]] std::size_t getConnectionTimeout() const override; /// Returns the session connection timeout value. @@ -112,22 +116,27 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl void rollback() override; /// Aborts a transaction + [[nodiscard]] bool canTransact() const override; /// Returns true if session has transaction capabilities. + [[nodiscard]] bool isTransaction() const override; /// Returns true iff a transaction is a transaction is in progress, false otherwise. void setTransactionIsolation(Poco::UInt32 ti) override; /// Sets the transaction isolation level. + [[nodiscard]] Poco::UInt32 getTransactionIsolation() const override; /// Returns the transaction isolation level. + [[nodiscard]] bool hasTransactionIsolation(Poco::UInt32 ti) const override; /// Returns true iff the transaction isolation level corresponding /// to the supplied bitmask is supported. + [[nodiscard]] bool isTransactionIsolation(Poco::UInt32 ti) const override; /// Returns true iff the transaction isolation level corresponds /// to the supplied bitmask. @@ -135,12 +144,14 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl void autoCommit(const std::string&, bool val); /// Sets autocommit property for the session. + [[nodiscard]] bool isAutoCommit(const std::string& name="") const; /// Returns autocommit property value. void setInsertId(const std::string&, const Poco::Any&); /// Try to set insert id - do nothing. + [[nodiscard]] Poco::Any getInsertId(const std::string&) const; /// Get insert id @@ -148,6 +159,7 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl /// Sets the "failIfInnoReadOnly" feature. If set, isGood() will /// return false if the database is in read-only mode. + [[nodiscard]] bool getFailIfInnoReadOnly(const std::string&) const; /// Returns the state of the "failIfInnoReadOnly" feature. @@ -155,23 +167,28 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl /// Sets an error code. If a non-zero error code is set, the session /// is considered bad. + [[nodiscard]] int getLastError() const; /// Returns the last set error code. + [[nodiscard]] SessionHandle& handle(); // Get handle + [[nodiscard]] const std::string& connectorName() const override; /// Returns the name of the connector. private: template + [[nodiscard]] static inline T& getValue(MYSQL_BIND* pResult, T& val) { return val = *((T*) pResult->buffer); } template + [[nodiscard]] T& getSetting(const std::string& name, T& val) const /// Returns required setting. /// Limited to one setting at a time. @@ -187,7 +204,8 @@ class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl else throw InvalidArgumentException("No data returned."); - ex.execute(); ex.fetch(); + ex.execute(); + [[maybe_unused]] bool b = ex.fetch(); MYSQL_BIND* pResult = metadata.row(); return getValue(pResult, val); } diff --git a/Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h b/Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h index bca1bf5f71..06e26d8767 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h +++ b/Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h @@ -46,6 +46,7 @@ class StatementExecutor ~StatementExecutor(); /// Destroys the StatementExecutor. + [[nodiscard]] int state() const; /// Returns the current state. @@ -61,14 +62,18 @@ class StatementExecutor void execute(); /// Executes the statement. + [[nodiscard]] bool fetch(); /// Fetches the data. + [[nodiscard]] bool fetchColumn(std::size_t n, MYSQL_BIND *bind); /// Fetches the column. + [[nodiscard]] int getAffectedRowCount() const; + [[nodiscard]] operator MYSQL_STMT* (); /// Cast operator to native handle type. diff --git a/Data/MySQL/include/Poco/Data/MySQL/Utility.h b/Data/MySQL/include/Poco/Data/MySQL/Utility.h index 44e0c20c19..4886476166 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/Utility.h +++ b/Data/MySQL/include/Poco/Data/MySQL/Utility.h @@ -30,24 +30,31 @@ class MySQL_API Utility /// Various utility functions for MySQL. { public: + [[nodiscard]] static std::string serverInfo(MYSQL* pHandle); /// Returns server info. + [[nodiscard]] static std::string serverInfo(Poco::Data::Session& session); /// Returns server info. + [[nodiscard]] static unsigned long serverVersion(MYSQL* pHandle); /// Returns server version. + [[nodiscard]] static unsigned long serverVersion(Poco::Data::Session& session); /// Returns server version. + [[nodiscard]] static std::string hostInfo(MYSQL* pHandle); /// Returns host info. + [[nodiscard]] static std::string hostInfo(Poco::Data::Session& session); /// Returns host info. + [[nodiscard]] static MYSQL* handle(Poco::Data::Session& session); /// Returns native MySQL handle for the session. }; diff --git a/Data/MySQL/src/SessionImpl.cpp b/Data/MySQL/src/SessionImpl.cpp index 2751985d79..c89d689680 100644 --- a/Data/MySQL/src/SessionImpl.cpp +++ b/Data/MySQL/src/SessionImpl.cpp @@ -270,19 +270,19 @@ Poco::UInt32 SessionImpl::getTransactionIsolation() const if (serverInfo.find(MARIADB_SERVERINFO) != std::string::npos) //MariaDB { - getSetting("tx_isolation", isolation); + (void)getSetting("tx_isolation", isolation); isolation = isolation.c_str(); } else //MySQL { if (version >= 80000) { - getSetting("transaction_isolation", isolation); + (void)getSetting("transaction_isolation", isolation); isolation = isolation.c_str(); } else { - getSetting("tx_isolation", isolation); + (void)getSetting("tx_isolation", isolation); } } Poco::replaceInPlace(isolation, "-", " "); diff --git a/Data/ODBC/include/Poco/Data/ODBC/Binder.h b/Data/ODBC/include/Poco/Data/ODBC/Binder.h index dcfc4a4ebe..c5cb9d8fcd 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Binder.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Binder.h @@ -372,9 +372,11 @@ class ODBC_API Binder: public Poco::Data::AbstractBinder void setDataBinding(ParameterBinding binding); /// Set data binding type. + [[nodiscard]] ParameterBinding getDataBinding() const; /// Return data binding type. + [[nodiscard]] std::size_t parameterSize(SQLPOINTER pAddr) const; /// Returns bound data size for parameter at specified position. @@ -415,6 +417,7 @@ class ODBC_API Binder: public Poco::Data::AbstractBinder /// This is a private no-op in this implementation /// due to security risk. + [[nodiscard]] SQLSMALLINT toODBCDirection(Direction dir) const; /// Returns ODBC parameter direction based on the parameter binding direction /// specified by user. @@ -1117,6 +1120,7 @@ class ODBC_API Binder: public Poco::Data::AbstractBinder /// size should be set to some default value prior to calling this /// function in order to avoid undefined size value. + [[nodiscard]] std::size_t getParamSizeDirect(std::size_t pos, SQLINTEGER& size); /// A "last ditch" attempt" to obtain parameter size directly from the driver. diff --git a/Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h b/Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h index 0b34423e77..9a45339a6b 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h +++ b/Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h @@ -54,12 +54,14 @@ class ODBC_API ConnectionHandle bool disconnect(); /// Disconnects the handle from database. + [[nodiscard]] bool isConnected() const; /// Returns true if connected. void setTimeout(int timeout); /// Sets the connection timeout in seconds. + [[nodiscard]] int getTimeout() const; /// Returns the connection timeout in seconds. @@ -67,27 +69,34 @@ class ODBC_API ConnectionHandle /// Sets the login timeout in seconds. /// Must be called before the connection attempt. + [[nodiscard]] int getLoginTimeout() const; /// Returns the login timeout in seconds. /// Must be called before the connection attempt. + [[nodiscard]] const SQLHDBC& handle() const; /// Returns const reference to handle; + [[nodiscard]] const SQLHDBC* pHandle() const; /// Returns const pointer to handle; + [[nodiscard]] operator const SQLHDBC& () const; /// Const conversion operator into reference to native type. + [[nodiscard]] operator bool(); /// Returns true if handles are not null. /// True value is not a guarantee that the connection is valid. private: + [[nodiscard]] operator SQLHDBC& (); /// Conversion operator into reference to native type. + [[nodiscard]] SQLHDBC& handle(); /// Returns reference to handle; @@ -100,19 +109,23 @@ class ODBC_API ConnectionHandle void setTimeoutImpl(SQLULEN timeout, SQLINTEGER attribute); /// Sets the timeout for the attribute. + [[nodiscard]] int getTimeoutImpl(SQLINTEGER attribute) const; /// Returns the timeout for the attribute. void setTimeouts(SQLULEN loginTimeout, SQLULEN timeout); + [[nodiscard]] bool isUnsupported(const ConnectionError& e) const; /// Returns true if SQLSTATE is "HYC000" /// (Optional feature not implemented) + [[nodiscard]] bool isGenError(const ConnectionError& e) const; /// Returns true if SQLSTATE is "HY000" /// (General error) + [[nodiscard]] bool cantSetAttr(const ConnectionError& e) const; /// Returns true if SQLSTATE is "HY011" /// (Can't set attribute) diff --git a/Data/ODBC/include/Poco/Data/ODBC/Connector.h b/Data/ODBC/include/Poco/Data/ODBC/Connector.h index e4c17881d6..4f225ed82c 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Connector.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Connector.h @@ -38,9 +38,11 @@ class ODBC_API Connector: public Poco::Data::Connector ~Connector() override; /// Destroys the Connector. + [[nodiscard]] const std::string& name() const override; /// Returns the name associated with this connector. + [[nodiscard]] Poco::AutoPtr createSession(const std::string& connectionString, std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT) override; /// Creates a ODBC SessionImpl object and initializes it with the given connectionString. @@ -64,6 +66,7 @@ class ODBC_API Connector: public Poco::Data::Connector /// This setting should not be changed after the first Session has /// been created. + [[nodiscard]] static bool stringBoundToLongVarChar(); /// Returns true if std::string is bound to SQL_LONGVARCHAR, /// otherwise false (bound to SQL_VARCHAR). diff --git a/Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h b/Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h index c7d519b406..01df4e571a 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h @@ -65,7 +65,7 @@ class Diagnostics { std::memset(_connectionName, 0, sizeof(_connectionName)); std::memset(_serverName, 0, sizeof(_serverName)); - diagnostics(); + (void)diagnostics(); } ~Diagnostics() @@ -73,6 +73,7 @@ class Diagnostics { } + [[nodiscard]] std::string sqlState(int index) const /// Returns SQL state. { @@ -80,6 +81,7 @@ class Diagnostics return std::string((char*) _fields[index]._sqlState); } + [[nodiscard]] std::string message(int index) const /// Returns error message. { @@ -87,6 +89,7 @@ class Diagnostics return std::string((char*) _fields[index]._message); } + [[nodiscard]] long nativeError(int index) const /// Returns native error code. { @@ -94,6 +97,7 @@ class Diagnostics return _fields[index]._nativeError; } + [[nodiscard]] std::string connectionName() const /// Returns the connection name. /// If there is no active connection, connection name defaults to NONE. @@ -103,6 +107,7 @@ class Diagnostics return std::string((char*) _connectionName); } + [[nodiscard]] std::string serverName() const /// Returns the server name. /// If the connection has not been established, server name defaults to NONE. @@ -112,6 +117,7 @@ class Diagnostics return std::string((char*) _serverName); } + [[nodiscard]] int count() const /// Returns the number of contained diagnostic records. { @@ -124,21 +130,25 @@ class Diagnostics _fields.clear(); } + [[nodiscard]] const FieldVec& fields() const { return _fields; } + [[nodiscard]] Iterator begin() const { return _fields.begin(); } + [[nodiscard]] Iterator end() const { return _fields.end(); } + [[nodiscard]] const Diagnostics& diagnostics() { if (POCO_ODBC_NULL_HANDLE == _handle) return *this; @@ -217,6 +227,7 @@ class Diagnostics } protected: + [[nodiscard]] const H& handle() const { return _handle; diff --git a/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h b/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h index 317098b6c3..02571834bc 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h +++ b/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h @@ -38,16 +38,20 @@ class ODBC_API EnvironmentHandle ~EnvironmentHandle(); /// Destroys the EnvironmentHandle. + [[nodiscard]] operator const SQLHENV& () const; /// Const conversion operator into reference to native type. + [[nodiscard]] const SQLHENV& handle() const; /// Returns const reference to handle. private: + [[nodiscard]] operator SQLHENV& (); /// Conversion operator into reference to native type. + [[nodiscard]] SQLHENV& handle(); /// Returns reference to handle. diff --git a/Data/ODBC/include/Poco/Data/ODBC/Error.h b/Data/ODBC/include/Poco/Data/ODBC/Error.h index 6212d0c0e1..3f3de45e51 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Error.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Error.h @@ -60,18 +60,21 @@ class Error return *this; } + [[nodiscard]] const Diagnostics& diagnostics() const /// Returns the associated diagnostics. { return *_pDiag; } + [[nodiscard]] int count() const /// Returns the count of diagnostic records. { - return (int) _pDiag->count(); + return static_cast(_pDiag->count()); } + [[nodiscard]] std::string& toString(int index, std::string& str) const /// Generates the string for the diagnostic record. { @@ -94,6 +97,7 @@ class Error return str; } + [[nodiscard]] std::string toString() const /// Generates the string for the diagnostic record collection. { diff --git a/Data/ODBC/include/Poco/Data/ODBC/Extractor.h b/Data/ODBC/include/Poco/Data/ODBC/Extractor.h index 9519c4794c..225d15a5d6 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Extractor.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Extractor.h @@ -418,9 +418,11 @@ class ODBC_API Extractor: public Poco::Data::AbstractExtractor void setDataExtraction(Preparator::DataExtraction ext); /// Set data extraction mode. + [[nodiscard]] Preparator::DataExtraction getDataExtraction() const; /// Returns data extraction mode. + [[nodiscard]] bool isNull(std::size_t col, std::size_t row = POCO_DATA_INVALID_ROW) override; /// Returns true if the value at [col,row] is null. @@ -446,7 +448,7 @@ class ODBC_API Extractor: public Poco::Data::AbstractExtractor /// Resizes the vector holding extracted data lengths to the /// appropriate size. - template + template bool extractBoundImpl(std::size_t pos, T& val) { if (isNull(pos)) return false; @@ -707,11 +709,13 @@ class ODBC_API Extractor: public Poco::Data::AbstractExtractor return true; } + [[nodiscard]] bool isNullLengthIndicator(SQLLEN val) const; /// The reason for this utility wrapper are platforms where /// SQLLEN macro (a.k.a. SQLINTEGER) yields 64-bit value, /// while SQL_NULL_DATA (#define'd as -1 literal) remains 32-bit. + [[nodiscard]] SQLINTEGER columnSize(std::size_t pos) const; const StatementHandle& _rStmt; diff --git a/Data/ODBC/include/Poco/Data/ODBC/Handle.h b/Data/ODBC/include/Poco/Data/ODBC/Handle.h index e521b28550..256645813f 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Handle.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Handle.h @@ -66,18 +66,21 @@ class Handle } } + [[nodiscard]] operator const H& () const /// Const conversion operator into reference to native type. { return handle(); } + [[nodiscard]] const H& handle() const /// Returns const reference to native type. { return _handle; } + [[nodiscard]] const ConnectionHandle& connection() const /// Returns the connection handle. { @@ -88,12 +91,14 @@ class Handle Handle(const Handle&) = delete; const Handle& operator=(const Handle&) = delete; + [[nodiscard]] operator H& () /// Conversion operator into reference to native type. { return handle(); } + [[nodiscard]] H& handle() /// Returns reference to native type. { diff --git a/Data/ODBC/include/Poco/Data/ODBC/ODBCException.h b/Data/ODBC/include/Poco/Data/ODBC/ODBCException.h index f714eb93bd..91933c9486 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/ODBCException.h +++ b/Data/ODBC/include/Poco/Data/ODBC/ODBCException.h @@ -86,18 +86,21 @@ class HandleException: public ODBCException return *this; } + [[nodiscard]] const char* name() const noexcept /// Returns the name of the exception { return "ODBC handle exception"; } + [[nodiscard]] const char* className() const noexcept /// Returns the HandleException class name. { return typeid(*this).name(); } + [[nodiscard]] Poco::Exception* clone() const /// Clones the HandleException { @@ -110,12 +113,14 @@ class HandleException: public ODBCException throw *this; } + [[nodiscard]] const Diagnostics& diagnostics() const /// Returns error diagnostics. { return _error.diagnostics(); } + [[nodiscard]] std::string toString() const /// Returns the formatted error diagnostics for the handle. { @@ -124,6 +129,7 @@ class HandleException: public ODBCException _error.toString()); } + [[nodiscard]] static std::string errorString(const H& handle) /// Returns the error diagnostics string for the handle. { diff --git a/Data/ODBC/include/Poco/Data/ODBC/ODBCMetaColumn.h b/Data/ODBC/include/Poco/Data/ODBC/ODBCMetaColumn.h index 31276a6b9f..bf2f5e2448 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/ODBCMetaColumn.h +++ b/Data/ODBC/include/Poco/Data/ODBC/ODBCMetaColumn.h @@ -39,6 +39,7 @@ class ODBC_API ODBCMetaColumn: public MetaColumn ~ODBCMetaColumn() override; /// Destroys the ODBCMetaColumn. + [[nodiscard]] std::size_t dataLength() const; /// A numeric value that is either the maximum or actual character length of a character /// string or binary data type. It is the maximum character length for a fixed-length data type, @@ -46,6 +47,7 @@ class ODBC_API ODBCMetaColumn: public MetaColumn /// null-termination byte that ends the character string. /// This information is returned from the SQL_DESC_LENGTH record field of the IRD. + [[nodiscard]] bool isUnsigned() const; /// Returns true if column is unsigned or a non-numeric data type. diff --git a/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h b/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h index 33a07b6d73..b1492f5917 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h +++ b/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h @@ -47,31 +47,39 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl ~ODBCStatementImpl() override; /// Destroys the ODBCStatementImpl. + [[nodiscard]] std::string nativeSQL(); /// Returns the SQL string as modified by the driver. protected: + [[nodiscard]] std::size_t columnsReturned() const override; /// Returns number of columns returned by query. + [[nodiscard]] int affectedRowCount() const override; /// Returns the number of affected rows. /// Used to find out the number of rows affected by insert or update. + [[nodiscard]] const MetaColumn& metaColumn(std::size_t pos) const override; /// Returns column meta data. + [[nodiscard]] bool hasNext() override; /// Returns true if a call to next() will return data. + [[nodiscard]] std::size_t next() override; /// Retrieves the next row or set of rows from the resultset. /// Returns the number of rows retrieved. /// Will throw, if the resultset is empty. + [[nodiscard]] bool canBind() const override; /// Returns true if a valid statement is set and we can bind. + [[nodiscard]] bool canCompile() const override; /// Returns true if another compile is possible. @@ -82,9 +90,11 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl void bindImpl() override; /// Binds all parameters and executes the statement. + [[nodiscard]] AbstractExtraction::ExtractorPtr extractor() override; /// Returns the concrete extractor used by the statement. + [[nodiscard]] AbstractBinding::BinderPtr binder() override; /// Returns the concrete binder used by the statement. @@ -116,6 +126,7 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl void makeInternalExtractors(); /// Creates internal extractors if none were supplied from the user. + [[nodiscard]] bool isStoredProcedure() const override; /// Returns true if SQL is a stored procedure call. @@ -126,12 +137,14 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl /// it is called upon the first check for data availability /// (see hasNext() function). + [[nodiscard]] bool hasData() const; /// Returns true if statement returns data. void makeStep(); /// Fetches the next row of data. + [[nodiscard]] bool nextRowReady() const; /// Returns true if there is a row fetched but not yet extracted. diff --git a/Data/ODBC/include/Poco/Data/ODBC/Parameter.h b/Data/ODBC/include/Poco/Data/ODBC/Parameter.h index 441f071b03..59e0fe417d 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Parameter.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Parameter.h @@ -38,20 +38,25 @@ class ODBC_API Parameter ~Parameter(); /// Destroys the Parameter. + [[nodiscard]] std::size_t number() const; /// Returns the column number. + [[nodiscard]] std::size_t dataType() const; /// Returns the SQL data type. + [[nodiscard]] std::size_t columnSize() const; /// Returns the the size of the column or expression of the corresponding /// parameter marker as defined by the data source. + [[nodiscard]] std::size_t decimalDigits() const; /// Returns the number of decimal digits of the column or expression /// of the corresponding parameter as defined by the data source. + [[nodiscard]] bool isNullable() const; /// Returns true if column allows null values, false otherwise. diff --git a/Data/ODBC/include/Poco/Data/ODBC/Preparator.h b/Data/ODBC/include/Poco/Data/ODBC/Preparator.h index 89f3302974..c3946af1fa 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Preparator.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Preparator.h @@ -380,33 +380,40 @@ class ODBC_API Preparator : public AbstractPreparator void prepare(std::size_t pos, const std::list& val) override; /// Prepares a Dynamic::Var list. + [[nodiscard]] std::size_t columns() const; /// Returns the number of columns. /// Resizes the internal storage iff the size is zero. + [[nodiscard]] Poco::Any& operator [] (std::size_t pos); /// Returns reference to column data. + [[nodiscard]] Poco::Any& at(std::size_t pos); /// Returns reference to column data. void setMaxFieldSize(std::size_t size); /// Sets maximum supported field size. + [[nodiscard]] std::size_t getMaxFieldSize() const; // Returns maximum supported field size. + [[nodiscard]] std::size_t maxDataSize(std::size_t pos) const; /// Returns max supported size for column at position pos. /// Returned length for variable length fields is the one /// supported by this implementation, not the underlying DB. + [[nodiscard]] std::size_t actualDataSize(std::size_t col, std::size_t row = POCO_DATA_INVALID_ROW) const; /// Returns the returned length for the column and row specified. /// This is usually equal to the column size, except for /// variable length fields (BLOB and variable length strings). /// For null values, the return value is -1 (SQL_NO_DATA) + [[nodiscard]] std::size_t bulkSize(std::size_t col = 0) const; /// Returns bulk size. Column argument is optional /// since all columns must be the same size. @@ -414,6 +421,7 @@ class ODBC_API Preparator : public AbstractPreparator void setDataExtraction(DataExtraction ext); /// Set data extraction mode. + [[nodiscard]] DataExtraction getDataExtraction() const; /// Returns data extraction mode. diff --git a/Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h b/Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h index 774bb69f72..afc59d618f 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h +++ b/Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h @@ -84,12 +84,14 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl void close() override; /// Closes the connection + [[nodiscard]] bool isConnected() const override; /// Returns true if session is connected void setConnectionTimeout(std::size_t timeout) override; /// Sets the session connection timeout value. + [[nodiscard]] std::size_t getConnectionTimeout() const override; /// Returns the session connection timeout value. @@ -105,25 +107,31 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl void reset() override; /// Do nothing + [[nodiscard]] bool isTransaction() const override; /// Returns true iff a transaction is in progress. + [[nodiscard]] const std::string& connectorName() const override; /// Returns the name of the connector. + [[nodiscard]] bool canTransact() const override; /// Returns true if connection is transaction-capable. void setTransactionIsolation(Poco::UInt32 ti) override; /// Sets the transaction isolation level. + [[nodiscard]] Poco::UInt32 getTransactionIsolation() const override; /// Returns the transaction isolation level. + [[nodiscard]] bool hasTransactionIsolation(Poco::UInt32) const override; /// Returns true iff the transaction isolation level corresponding /// to the supplied bitmask is supported. + [[nodiscard]] bool isTransactionIsolation(Poco::UInt32) const override; /// Returns true iff the transaction isolation level corresponds /// to the supplied bitmask. @@ -131,27 +139,32 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl void autoCommit(const std::string&, bool val); /// Sets autocommit property for the session. + [[nodiscard]] bool isAutoCommit(const std::string& name="") const; /// Returns autocommit property value. void autoBind(const std::string&, bool val); /// Sets automatic binding for the session. + [[nodiscard]] bool isAutoBind(const std::string& name="") const; /// Returns true if binding is automatic for this session. void autoExtract(const std::string&, bool val); /// Sets automatic extraction for the session. + [[nodiscard]] bool isAutoExtract(const std::string& name="") const; /// Returns true if extraction is automatic for this session. void setMaxFieldSize(const std::string& rName, const Poco::Any& rValue); /// Sets the max field size (the default used when column size is unknown). + [[nodiscard]] Poco::Any getMaxFieldSize(const std::string& rName="") const; /// Returns the max field size (the default used when column size is unknown). + [[nodiscard]] int maxStatementLength() const; /// Returns maximum length of SQL statement allowed by driver. @@ -159,6 +172,7 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl /// Sets the timeout (in seconds) for queries. /// Value must be of type int. + [[nodiscard]] Poco::Any getQueryTimeout(const std::string&) const; /// Returns the timeout (in seconds) for queries, /// or -1 if no timeout has been set. @@ -169,6 +183,7 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl /// - SQL_CUR_USE_IF_NEEDED - if needed /// - SQL_CUR_USE_DRIVER - never + [[nodiscard]] Poco::Any getCursorUse(const std::string&) const; /// Returns the use of cursors. @@ -180,9 +195,11 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl /// Sets the database encoding. /// Value must be of type std::string. + [[nodiscard]] Poco::Any getDBEncoding(const std::string&) const; /// Returns the database encoding. + [[nodiscard]] const std::string& dbEncoding() const; /// Returns the database encoding. @@ -190,13 +207,16 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl /// Sets the multiple active resultset capability, if available. /// Does nothing, if feature is not available. + [[nodiscard]] bool getMultiActiveResultset(const std::string&) const; /// Returns the multiple active resultset capability, if available. /// Returns false, if feature is not available. + [[nodiscard]] const ConnectionHandle& dbc() const; /// Returns the connection handle. + [[nodiscard]] Poco::Any dataTypeInfo(const std::string& rName="") const; /// Returns the data types information. @@ -208,8 +228,10 @@ class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl void checkError(SQLRETURN rc, const std::string& msg="") const; + [[nodiscard]] Poco::UInt32 getDefaultTransactionIsolation() const; + [[nodiscard]] static Poco::UInt32 transactionIsolation(SQLULEN isolation); void setTransactionIsolationImpl(Poco::UInt32 ti) const; diff --git a/Data/ODBC/include/Poco/Data/ODBC/TypeInfo.h b/Data/ODBC/include/Poco/Data/ODBC/TypeInfo.h index 4df944daf9..27ad930e65 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/TypeInfo.h +++ b/Data/ODBC/include/Poco/Data/ODBC/TypeInfo.h @@ -74,10 +74,12 @@ class ODBC_API TypeInfo ~TypeInfo(); /// Destroys the TypeInfo. + [[nodiscard]] SQLSMALLINT cDataType(SQLSMALLINT sqlDataType) const; /// Returns C data type corresponding to supplied SQL data type. template + [[nodiscard]] static constexpr SQLSMALLINT cDataType() /// Returns C data type corresponding to supplied SQL data type. { @@ -127,10 +129,12 @@ class ODBC_API TypeInfo return 0; } + [[nodiscard]] SQLSMALLINT sqlDataType(SQLSMALLINT cDataType) const; /// Returns SQL data type corresponding to supplied C data type. template + [[nodiscard]] static constexpr SQLSMALLINT sqlDataType() /// Returns SQL data type corresponding to supplied C data type. { @@ -186,11 +190,13 @@ class ODBC_API TypeInfo void reset(); /// Clears cached type info, allowing refill on next fillTypeInfo call. + [[nodiscard]] Dynamic::Var getInfo(SQLSMALLINT type, const std::string& param) const; /// Returns information about specified data type as specified by parameter 'type'. /// The requested information is specified by parameter 'param'. /// Will fail with a Poco::NotFoundException thrown if the param is not found + [[nodiscard]] bool tryGetInfo(SQLSMALLINT type, const std::string& param, Dynamic::Var& result) const; /// Returns information about specified data type as specified by parameter 'type' in param result. /// The requested information is specified by parameter 'param'. diff --git a/Data/ODBC/include/Poco/Data/ODBC/Unicode.h b/Data/ODBC/include/Poco/Data/ODBC/Unicode.h index b3551bc973..d52d8202f5 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Unicode.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Unicode.h @@ -54,6 +54,7 @@ namespace Poco::Data::ODBC { #endif +[[nodiscard]] SQLRETURN ODBC_API SQLColAttribute(SQLHSTMT hstmt, SQLUSMALLINT iCol, SQLUSMALLINT iField, @@ -63,6 +64,7 @@ SQLRETURN ODBC_API SQLColAttribute(SQLHSTMT hstmt, NumAttrPtrType pNumAttr); +[[nodiscard]] SQLRETURN ODBC_API SQLColAttributes(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLUSMALLINT fDescType, @@ -71,6 +73,7 @@ SQLRETURN ODBC_API SQLColAttributes(SQLHSTMT hstmt, SQLSMALLINT* pcbDesc, SQLLEN* pfDesc); +[[nodiscard]] SQLRETURN ODBC_API SQLConnect(SQLHDBC hdbc, SQLCHAR* szDSN, SQLSMALLINT cbDSN, @@ -79,6 +82,7 @@ SQLRETURN ODBC_API SQLConnect(SQLHDBC hdbc, SQLCHAR* szAuthStr, SQLSMALLINT cbAuthStr); +[[nodiscard]] SQLRETURN ODBC_API SQLDescribeCol(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLCHAR* szColName, @@ -89,6 +93,7 @@ SQLRETURN ODBC_API SQLDescribeCol(SQLHSTMT hstmt, SQLSMALLINT* pibScale, SQLSMALLINT* pfNullable); +[[nodiscard]] SQLRETURN ODBC_API SQLError(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, @@ -98,27 +103,32 @@ SQLRETURN ODBC_API SQLError(SQLHENV henv, SQLSMALLINT cbErrorMsgMax, SQLSMALLINT* pcbErrorMsg); +[[nodiscard]] SQLRETURN ODBC_API SQLExecDirect(SQLHSTMT hstmt, SQLCHAR* szSqlStr, SQLINTEGER cbSqlStr); +[[nodiscard]] SQLRETURN ODBC_API SQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER fAttribute, SQLPOINTER rgbValue, SQLINTEGER cbValueMax, SQLINTEGER* pcbValue); +[[nodiscard]] SQLRETURN ODBC_API SQLGetCursorName(SQLHSTMT hstmt, SQLCHAR* szCursor, SQLSMALLINT cbCursorMax, SQLSMALLINT* pcbCursor); +[[nodiscard]] SQLRETURN ODBC_API SQLSetDescField(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier, SQLPOINTER Value, SQLINTEGER BufferLength); +[[nodiscard]] SQLRETURN ODBC_API SQLGetDescField(SQLHDESC hdesc, SQLSMALLINT iRecord, SQLSMALLINT iField, @@ -126,6 +136,7 @@ SQLRETURN ODBC_API SQLGetDescField(SQLHDESC hdesc, SQLINTEGER cbValueMax, SQLINTEGER* pcbValue); +[[nodiscard]] SQLRETURN ODBC_API SQLGetDescRec(SQLHDESC hdesc, SQLSMALLINT iRecord, SQLCHAR* szName, @@ -138,6 +149,7 @@ SQLRETURN ODBC_API SQLGetDescRec(SQLHDESC hdesc, SQLSMALLINT* pScale, SQLSMALLINT* pNullable); +[[nodiscard]] SQLRETURN ODBC_API SQLGetDiagField(SQLSMALLINT fHandleType, SQLHANDLE handle, SQLSMALLINT iRecord, @@ -146,6 +158,7 @@ SQLRETURN ODBC_API SQLGetDiagField(SQLSMALLINT fHandleType, SQLSMALLINT cbDiagInfoMax, SQLSMALLINT* pcbDiagInfo); +[[nodiscard]] SQLRETURN ODBC_API SQLGetDiagRec(SQLSMALLINT fHandleType, SQLHANDLE handle, SQLSMALLINT iRecord, @@ -155,30 +168,36 @@ SQLRETURN ODBC_API SQLGetDiagRec(SQLSMALLINT fHandleType, SQLSMALLINT cbErrorMsgMax, SQLSMALLINT* pcbErrorMsg); +[[nodiscard]] SQLRETURN ODBC_API SQLPrepare(SQLHSTMT hstmt, SQLCHAR* szSqlStr, SQLINTEGER cbSqlStr); +[[nodiscard]] SQLRETURN ODBC_API SQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER fAttribute, SQLPOINTER rgbValue, SQLINTEGER cbValue); +[[nodiscard]] SQLRETURN ODBC_API SQLSetCursorName(SQLHSTMT hstmt, SQLCHAR* szCursor, SQLSMALLINT cbCursor); +[[nodiscard]] SQLRETURN ODBC_API SQLSetStmtAttr(SQLHSTMT hstmt, SQLINTEGER fAttribute, SQLPOINTER rgbValue, SQLINTEGER cbValueMax); +[[nodiscard]] SQLRETURN ODBC_API SQLGetStmtAttr(SQLHSTMT hstmt, SQLINTEGER fAttribute, SQLPOINTER rgbValue, SQLINTEGER cbValueMax, SQLINTEGER* pcbValue); +[[nodiscard]] SQLRETURN ODBC_API SQLColumns(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -189,23 +208,28 @@ SQLRETURN ODBC_API SQLColumns(SQLHSTMT hstmt, SQLCHAR* szColumnName, SQLSMALLINT cbColumnName); +[[nodiscard]] SQLRETURN ODBC_API SQLGetConnectOption(SQLHDBC hdbc, SQLUSMALLINT fOption, SQLPOINTER pvParam); +[[nodiscard]] SQLRETURN ODBC_API SQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, SQLPOINTER rgbInfoValue, SQLSMALLINT cbInfoValueMax, SQLSMALLINT* pcbInfoValue); +[[nodiscard]] SQLRETURN ODBC_API SQLGetTypeInfo(SQLHSTMT StatementHandle, SQLSMALLINT DataType); +[[nodiscard]] SQLRETURN ODBC_API SQLSetConnectOption(SQLHDBC hdbc, SQLUSMALLINT fOption, SQLULEN vParam); +[[nodiscard]] SQLRETURN ODBC_API SQLSpecialColumns(SQLHSTMT hstmt, SQLUSMALLINT fColType, SQLCHAR* szCatalogName, @@ -217,6 +241,7 @@ SQLRETURN ODBC_API SQLSpecialColumns(SQLHSTMT hstmt, SQLUSMALLINT fScope, SQLUSMALLINT fNullable); +[[nodiscard]] SQLRETURN ODBC_API SQLStatistics(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -227,6 +252,7 @@ SQLRETURN ODBC_API SQLStatistics(SQLHSTMT hstmt, SQLUSMALLINT fUnique, SQLUSMALLINT fAccuracy); +[[nodiscard]] SQLRETURN ODBC_API SQLTables(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -237,6 +263,7 @@ SQLRETURN ODBC_API SQLTables(SQLHSTMT hstmt, SQLCHAR* szTableType, SQLSMALLINT cbTableType); +[[nodiscard]] SQLRETURN ODBC_API SQLDataSources(SQLHENV henv, SQLUSMALLINT fDirection, SQLCHAR* szDSN, @@ -246,6 +273,7 @@ SQLRETURN ODBC_API SQLDataSources(SQLHENV henv, SQLSMALLINT cbDescriptionMax, SQLSMALLINT* pcbDescription); +[[nodiscard]] SQLRETURN ODBC_API SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR* szConnStrIn, @@ -255,6 +283,7 @@ SQLRETURN ODBC_API SQLDriverConnect(SQLHDBC hdbc, SQLSMALLINT* pcbConnStrOut, SQLUSMALLINT fDriverCompletion); +[[nodiscard]] SQLRETURN ODBC_API SQLBrowseConnect(SQLHDBC hdbc, SQLCHAR* szConnStrIn, SQLSMALLINT cbConnStrIn, @@ -262,6 +291,7 @@ SQLRETURN ODBC_API SQLBrowseConnect(SQLHDBC hdbc, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT* pcbConnStrOut); +[[nodiscard]] SQLRETURN ODBC_API SQLColumnPrivileges(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -272,6 +302,7 @@ SQLRETURN ODBC_API SQLColumnPrivileges(SQLHSTMT hstmt, SQLCHAR* szColumnName, SQLSMALLINT cbColumnName); +[[nodiscard]] SQLRETURN ODBC_API SQLForeignKeys(SQLHSTMT hstmt, SQLCHAR* szPkCatalogName, SQLSMALLINT cbPkCatalogName, @@ -286,6 +317,7 @@ SQLRETURN ODBC_API SQLForeignKeys(SQLHSTMT hstmt, SQLCHAR* szFkTableName, SQLSMALLINT cbFkTableName); +[[nodiscard]] SQLRETURN ODBC_API SQLNativeSql(SQLHDBC hdbc, SQLCHAR* szSqlStrIn, SQLINTEGER cbSqlStrIn, @@ -293,6 +325,7 @@ SQLRETURN ODBC_API SQLNativeSql(SQLHDBC hdbc, SQLINTEGER cbSqlStrMax, SQLINTEGER* pcbSqlStr); +[[nodiscard]] SQLRETURN ODBC_API SQLPrimaryKeys(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -301,6 +334,7 @@ SQLRETURN ODBC_API SQLPrimaryKeys(SQLHSTMT hstmt, SQLCHAR* szTableName, SQLSMALLINT cbTableName); +[[nodiscard]] SQLRETURN ODBC_API SQLProcedureColumns(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -311,6 +345,7 @@ SQLRETURN ODBC_API SQLProcedureColumns(SQLHSTMT hstmt, SQLCHAR* szColumnName, SQLSMALLINT cbColumnName); +[[nodiscard]] SQLRETURN ODBC_API SQLProcedures(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -319,6 +354,7 @@ SQLRETURN ODBC_API SQLProcedures(SQLHSTMT hstmt, SQLCHAR* szProcName, SQLSMALLINT cbProcName); +[[nodiscard]] SQLRETURN ODBC_API SQLTablePrivileges(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -327,6 +363,7 @@ SQLRETURN ODBC_API SQLTablePrivileges(SQLHSTMT hstmt, SQLCHAR* szTableName, SQLSMALLINT cbTableName); +[[nodiscard]] SQLRETURN ODBC_API SQLDrivers(SQLHENV henv, SQLUSMALLINT fDirection, SQLCHAR* szDriverDesc, @@ -341,12 +378,14 @@ SQLRETURN ODBC_API SQLDrivers(SQLHENV henv, /// inlines /// +[[nodiscard]] inline bool isString(SQLPOINTER pValue, SQLINTEGER length) { return (SQL_NTS == length || length > 0) && pValue; } +[[nodiscard]] inline SQLINTEGER stringLength(SQLPOINTER pValue, SQLINTEGER length) { if (SQL_NTS != length) return length; @@ -362,6 +401,7 @@ inline SQLINTEGER stringLength(SQLPOINTER pValue, SQLINTEGER length) /// inlines /// +[[nodiscard]] inline SQLRETURN SQLColAttribute(SQLHSTMT hstmt, SQLUSMALLINT iCol, SQLUSMALLINT iField, @@ -380,6 +420,7 @@ inline SQLRETURN SQLColAttribute(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLColAttributes(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLUSMALLINT fDescType, @@ -398,6 +439,7 @@ inline SQLRETURN SQLColAttributes(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLConnect(SQLHDBC hdbc, SQLCHAR* szDSN, SQLSMALLINT cbDSN, @@ -416,6 +458,7 @@ inline SQLRETURN SQLConnect(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLDescribeCol(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLCHAR* szColName, @@ -438,6 +481,7 @@ inline SQLRETURN SQLDescribeCol(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLError(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, @@ -452,6 +496,7 @@ inline SQLRETURN SQLError(SQLHENV henv, } +[[nodiscard]] inline SQLRETURN SQLExecDirect(SQLHSTMT hstmt, SQLCHAR* szSqlStr, SQLINTEGER cbSqlStr) @@ -460,6 +505,7 @@ inline SQLRETURN SQLExecDirect(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER fAttribute, SQLPOINTER rgbValue, @@ -474,6 +520,7 @@ inline SQLRETURN SQLGetConnectAttr(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLGetCursorName(SQLHSTMT hstmt, SQLCHAR* szCursor, SQLSMALLINT cbCursorMax, @@ -483,6 +530,7 @@ inline SQLRETURN SQLGetCursorName(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLSetDescField(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier, @@ -497,6 +545,7 @@ inline SQLRETURN SQLSetDescField(SQLHDESC DescriptorHandle, } +[[nodiscard]] inline SQLRETURN SQLGetDescField(SQLHDESC hdesc, SQLSMALLINT iRecord, SQLSMALLINT iField, @@ -513,6 +562,7 @@ inline SQLRETURN SQLGetDescField(SQLHDESC hdesc, } +[[nodiscard]] inline SQLRETURN SQLGetDescRec(SQLHDESC hdesc, SQLSMALLINT iRecord, SQLCHAR* szName, @@ -539,6 +589,7 @@ inline SQLRETURN SQLGetDescRec(SQLHDESC hdesc, } +[[nodiscard]] inline SQLRETURN SQLGetDiagField(SQLSMALLINT fHandleType, SQLHANDLE handle, SQLSMALLINT iRecord, @@ -557,6 +608,7 @@ inline SQLRETURN SQLGetDiagField(SQLSMALLINT fHandleType, } +[[nodiscard]] inline SQLRETURN SQLGetDiagRec(SQLSMALLINT fHandleType, SQLHANDLE handle, SQLSMALLINT iRecord, @@ -577,6 +629,7 @@ inline SQLRETURN SQLGetDiagRec(SQLSMALLINT fHandleType, } +[[nodiscard]] inline SQLRETURN SQLPrepare(SQLHSTMT hstmt, SQLCHAR* szSqlStr, SQLINTEGER cbSqlStr) @@ -585,6 +638,7 @@ inline SQLRETURN SQLPrepare(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER fAttribute, SQLPOINTER rgbValue, @@ -594,6 +648,7 @@ inline SQLRETURN SQLSetConnectAttr(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLSetCursorName(SQLHSTMT hstmt, SQLCHAR* szCursor, SQLSMALLINT cbCursor) @@ -602,6 +657,7 @@ inline SQLRETURN SQLSetCursorName(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLSetStmtAttr(SQLHSTMT hstmt, SQLINTEGER fAttribute, SQLPOINTER rgbValue, @@ -611,6 +667,7 @@ inline SQLRETURN SQLSetStmtAttr(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLGetStmtAttr(SQLHSTMT hstmt, SQLINTEGER fAttribute, SQLPOINTER rgbValue, @@ -625,6 +682,7 @@ inline SQLRETURN SQLGetStmtAttr(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLColumns(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -647,6 +705,7 @@ inline SQLRETURN SQLColumns(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLGetConnectOption(SQLHDBC hdbc, SQLUSMALLINT fOption, SQLPOINTER pvParam) @@ -655,6 +714,7 @@ inline SQLRETURN SQLGetConnectOption(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, SQLPOINTER rgbInfoValue, @@ -669,6 +729,7 @@ inline SQLRETURN SQLGetInfo(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLGetTypeInfo(SQLHSTMT StatementHandle, SQLSMALLINT DataType) { @@ -676,6 +737,7 @@ inline SQLRETURN SQLGetTypeInfo(SQLHSTMT StatementHandle, } +[[nodiscard]] inline SQLRETURN SQLSetConnectOption(SQLHDBC hdbc, SQLUSMALLINT fOption, SQLULEN vParam) @@ -684,6 +746,7 @@ inline SQLRETURN SQLSetConnectOption(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLSpecialColumns(SQLHSTMT hstmt, SQLUSMALLINT fColType, SQLCHAR* szCatalogName, @@ -708,6 +771,7 @@ inline SQLRETURN SQLSpecialColumns(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLStatistics(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -730,6 +794,7 @@ inline SQLRETURN SQLStatistics(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLTables(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -752,6 +817,7 @@ inline SQLRETURN SQLTables(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLDataSources(SQLHENV henv, SQLUSMALLINT fDirection, SQLCHAR* szDSN, @@ -772,6 +838,7 @@ inline SQLRETURN SQLDataSources(SQLHENV henv, } +[[nodiscard]] inline SQLRETURN SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR* szConnStrIn, @@ -792,6 +859,7 @@ inline SQLRETURN SQLDriverConnect(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLBrowseConnect(SQLHDBC hdbc, SQLCHAR* szConnStrIn, SQLSMALLINT cbConnStrIn, @@ -808,6 +876,7 @@ inline SQLRETURN SQLBrowseConnect(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLColumnPrivileges(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -830,6 +899,7 @@ inline SQLRETURN SQLColumnPrivileges(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLForeignKeys(SQLHSTMT hstmt, SQLCHAR* szPkCatalogName, SQLSMALLINT cbPkCatalogName, @@ -860,6 +930,7 @@ inline SQLRETURN SQLForeignKeys(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLNativeSql(SQLHDBC hdbc, SQLCHAR* szSqlStrIn, SQLINTEGER cbSqlStrIn, @@ -876,6 +947,7 @@ inline SQLRETURN SQLNativeSql(SQLHDBC hdbc, } +[[nodiscard]] inline SQLRETURN SQLPrimaryKeys(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -894,6 +966,7 @@ inline SQLRETURN SQLPrimaryKeys(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLProcedureColumns(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -916,6 +989,7 @@ inline SQLRETURN SQLProcedureColumns(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLProcedures(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -934,6 +1008,7 @@ inline SQLRETURN SQLProcedures(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLTablePrivileges(SQLHSTMT hstmt, SQLCHAR* szCatalogName, SQLSMALLINT cbCatalogName, @@ -952,6 +1027,7 @@ inline SQLRETURN SQLTablePrivileges(SQLHSTMT hstmt, } +[[nodiscard]] inline SQLRETURN SQLDrivers(SQLHENV henv, SQLUSMALLINT fDirection, SQLCHAR* szDriverDesc, diff --git a/Data/ODBC/include/Poco/Data/ODBC/Utility.h b/Data/ODBC/include/Poco/Data/ODBC/Utility.h index d8490cb33d..f5610497d8 100644 --- a/Data/ODBC/include/Poco/Data/ODBC/Utility.h +++ b/Data/ODBC/include/Poco/Data/ODBC/Utility.h @@ -42,12 +42,15 @@ class ODBC_API Utility typedef std::map DSNMap; typedef DSNMap DriverMap; + [[nodiscard]] static bool isError(SQLRETURN rc); /// Returns true if return code is error + [[nodiscard]] static DriverMap& drivers(DriverMap& driverMap); /// Returns driver-attributes map of available ODBC drivers. + [[nodiscard]] static DSNMap& dataSources(DSNMap& dsnMap); /// Returns DSN-description map of available ODBC data sources. @@ -68,9 +71,11 @@ class ODBC_API Utility } } + [[nodiscard]] static int cDataType(int sqlDataType); /// Returns C data type corresponding to supplied SQL data type. + [[nodiscard]] static int sqlDataType(int cDataType); /// Returns SQL data type corresponding to supplied C data type. @@ -164,26 +169,33 @@ class ODBC_API Utility for (; it != end; ++it, ++tIt) dateTimeSync(*tIt, *it); } + [[nodiscard]] static std::string sqlGetInfo(const ConnectionHandle& db, SQLUSMALLINT type); /// Returns the requested info about the DBMS or ODBC driver. /// On error, returns "unknown". + [[nodiscard]] static std::string dbmsName(const ConnectionHandle& db); /// Returns the back end DBMS name. + [[nodiscard]] std::string dbmsVersion(const ConnectionHandle& db); /// Returns the back end DBMS version. + [[nodiscard]] std::string driverName(const ConnectionHandle& db); /// Returns the driver name. + [[nodiscard]] std::string driverVersion(const ConnectionHandle& db); /// Returns the driver version. + [[nodiscard]] std::string driverODBCVersion(const ConnectionHandle& db); /// Returns the driver ODBC standard version. template + [[nodiscard]] static constexpr SQLINTEGER sizeOf() /// Returns size of the data type. { @@ -202,6 +214,7 @@ class ODBC_API Utility } template + [[nodiscard]] static constexpr SQLINTEGER sizeOf(const T&) /// Returns size of the data type. { diff --git a/Data/ODBC/src/ODBCStatementImpl.cpp b/Data/ODBC/src/ODBCStatementImpl.cpp index 0e667cd1f9..5b2a5cdf50 100644 --- a/Data/ODBC/src/ODBCStatementImpl.cpp +++ b/Data/ODBC/src/ODBCStatementImpl.cpp @@ -345,7 +345,7 @@ bool ODBCStatementImpl::hasNext() if (!nextRowReady()) { - if (hasMoreDataSets()) activateNextDataSet(); + if (hasMoreDataSets()) (void)activateNextDataSet(); else return false; if (SQL_NO_DATA == SQLMoreResults(_stmt)) diff --git a/Data/ODBC/src/SessionImpl.cpp b/Data/ODBC/src/SessionImpl.cpp index 442daf4a5f..f60d87ae2b 100644 --- a/Data/ODBC/src/SessionImpl.cpp +++ b/Data/ODBC/src/SessionImpl.cpp @@ -167,7 +167,7 @@ void SessionImpl::open(const std::string& connect) &SessionImpl::setDataTypeInfo, &SessionImpl::dataTypeInfo); - Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, nullptr, 0); + (void)Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, nullptr, 0); if (!canTransact()) autoCommit("", true); } @@ -182,7 +182,7 @@ void SessionImpl::open(const std::string& connect) void SessionImpl::setDBEncoding(const std::string&, const Poco::Any& value) { const std::string& enc = Poco::RefAnyCast(value); - Poco::TextEncoding::byName(enc); // throws if not found + (void)Poco::TextEncoding::byName(enc); // throws if not found _dbEncoding = enc; } @@ -224,7 +224,7 @@ inline Poco::Any SessionImpl::getCursorUse(const std::string&) const #pragma warning (disable : 4995) // ignore marked as deprecated #endif SQLUINTEGER curUse = 0; - Poco::Data::ODBC::SQLGetConnectAttr(_db, SQL_ATTR_ODBC_CURSORS, &curUse, SQL_IS_UINTEGER, nullptr); + (void)Poco::Data::ODBC::SQLGetConnectAttr(_db, SQL_ATTR_ODBC_CURSORS, &curUse, SQL_IS_UINTEGER, nullptr); switch (curUse) { case SQL_CUR_USE_ODBC: @@ -315,7 +315,7 @@ bool SessionImpl::getMultiActiveResultset(const std::string&) const { #ifdef POCO_DATA_ODBC_HAVE_SQL_SERVER_EXT SQLINTEGER mars; - Poco::Data::ODBC::SQLGetConnectAttr(_db, SQL_COPT_SS_MARS_ENABLED, &mars, SQL_IS_INTEGER, nullptr); + (void)Poco::Data::ODBC::SQLGetConnectAttr(_db, SQL_COPT_SS_MARS_ENABLED, &mars, SQL_IS_INTEGER, nullptr); return mars == SQL_MARS_ENABLED_YES; #else return false; diff --git a/Data/ODBC/testsuite/src/ODBCAccessTest.cpp b/Data/ODBC/testsuite/src/ODBCAccessTest.cpp index b4a07d16f3..b1bb8deda7 100644 --- a/Data/ODBC/testsuite/src/ODBCAccessTest.cpp +++ b/Data/ODBC/testsuite/src/ODBCAccessTest.cpp @@ -136,7 +136,7 @@ bool ODBCAccessTest::canConnect(const std::string& driver, const std::string& ds } Utility::DSNMap dataSources; - Utility::dataSources(dataSources); + [[maybe_unused]] Utility::DSNMap m = Utility::dataSources(dataSources); Utility::DSNMap::iterator itDSN = dataSources.begin(); for (; itDSN != dataSources.end(); ++itDSN) { @@ -179,7 +179,7 @@ void ODBCAccessTest::tearDown() bool ODBCAccessTest::init(const std::string& driver, const std::string& dsn) { - Utility::drivers(_drivers); + [[maybe_unused]] Utility::DriverMap m = Utility::drivers(_drivers); if (!canConnect(driver, dsn)) return false; try diff --git a/Data/ODBC/testsuite/src/ODBCTest.cpp b/Data/ODBC/testsuite/src/ODBCTest.cpp index e5cb6385c8..10b78fe64e 100644 --- a/Data/ODBC/testsuite/src/ODBCTest.cpp +++ b/Data/ODBC/testsuite/src/ODBCTest.cpp @@ -1448,7 +1448,7 @@ bool ODBCTest::canConnect(const std::string& driver, } Utility::DSNMap dataSources; - Utility::dataSources(dataSources); + [[maybe_unused]] Utility::DSNMap m = Utility::dataSources(dataSources); if (dataSources.size() > 0) { Utility::DSNMap::iterator itDSN = dataSources.begin(); diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/BinaryExtractor.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/BinaryExtractor.h index d044ef3d31..d7335d5c25 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/BinaryExtractor.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/BinaryExtractor.h @@ -401,7 +401,9 @@ class PostgreSQL_API BinaryExtractor: public Poco::Data::AbstractExtractor /// Extracts a Dynamic::Var list. private: + [[nodiscard]] const OutputParameter& extractPreamble(std::size_t aPosition) const; + [[nodiscard]] bool isColumnNull(const OutputParameter& anOutputParameter) const; // Prevent VC8 warning "operator= could not be generated" diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h index ea3874a628..38e5227fe5 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h @@ -228,9 +228,11 @@ class PostgreSQL_API Binder: public Poco::Data::AbstractBinder void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; + [[nodiscard]] std::size_t size() const; /// Return count of bound parameters + [[nodiscard]] InputParameterVector bindVector() const; /// Return the vector of bound parameters. diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Connector.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Connector.h index a287b7cc4b..c33ba12303 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Connector.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Connector.h @@ -40,9 +40,11 @@ class PostgreSQL_API Connector: public Poco::Data::Connector ~Connector() override; /// Destroys the Connector. + [[nodiscard]] const std::string& name() const override; /// Returns the name associated with this connector. + [[nodiscard]] Poco::Data::SessionImpl::Ptr createSession(const std::string& aConnectionString, std::size_t aTimeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT) override; /// Creates a PostgreSQL SessionImpl object and initializes it with the given connectionString. diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Extractor.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Extractor.h index 351d9af541..f9e0db11b2 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Extractor.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Extractor.h @@ -190,6 +190,7 @@ class PostgreSQL_API Extractor: public Poco::Data::AbstractExtractor bool extract(std::size_t pos, Poco::Nullable& val) override; /// Extracts a nullable Var. + [[nodiscard]] bool isNull(std::size_t col, std::size_t row) override; /// Returns true if the value at [col,row] position is null. @@ -401,7 +402,9 @@ class PostgreSQL_API Extractor: public Poco::Data::AbstractExtractor /// Extracts a Dynamic::Var list. private: + [[nodiscard]] const OutputParameter& extractPreamble(std::size_t aPosition) const; + [[nodiscard]] bool isColumnNull(const OutputParameter& anOutputParameter) const; template diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLException.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLException.h index 7a5de7df84..df12eaf8f9 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLException.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLException.h @@ -47,12 +47,15 @@ class PostgreSQL_API PostgreSQLException: public Poco::Data::DataException PostgreSQLException& operator = (const PostgreSQLException& exc); /// Assignment operator. + [[nodiscard]] const char* name() const noexcept; /// Returns exception name. + [[nodiscard]] const char* className() const noexcept; /// Returns the name of the exception class. + [[nodiscard]] Poco::Exception* clone() const; /// Creates an exact copy of the exception. /// @@ -66,6 +69,7 @@ class PostgreSQL_API PostgreSQLException: public Poco::Data::DataException /// copy of an exception (see clone()), then /// throwing it again. + [[nodiscard]] const char* sqlState() const noexcept; /// Returns the SqlState diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h index 658ed5a724..633ce90631 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h @@ -42,26 +42,33 @@ class PostgreSQL_API PostgreSQLStatementImpl: public Poco::Data::StatementImpl /// Destroys the PostgreSQLStatementImpl. protected: + [[nodiscard]] std::size_t columnsReturned() const override; /// Returns number of columns returned by query. + [[nodiscard]] int affectedRowCount() const override; /// Returns the number of affected rows. /// Used to find out the number of rows affected by insert, delete or update. + [[nodiscard]] const MetaColumn& metaColumn(std::size_t aPosition) const override; /// Returns column meta data. + [[nodiscard]] bool hasNext() override; /// Returns true if a call to next() will return data. + [[nodiscard]] std::size_t next() override; /// Retrieves the next row from the resultset. /// Will throw, if the resultset is empty. + [[nodiscard]] bool canBind() const override; /// Returns true if a valid statement is set and we can bind. + [[nodiscard]] bool canCompile() const override; /// Returns true if another compile is possible. @@ -71,9 +78,11 @@ class PostgreSQL_API PostgreSQLStatementImpl: public Poco::Data::StatementImpl void bindImpl() override; /// Binds parameters + [[nodiscard]] Poco::Data::AbstractExtractor::Ptr extractor() override; /// Returns the concrete extractor used by the statement. + [[nodiscard]] Poco::Data::AbstractBinder::Ptr binder() override; /// Returns the concrete binder used by the statement. diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLTypes.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLTypes.h index f8308dae7e..c5b3567453 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLTypes.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLTypes.h @@ -62,6 +62,7 @@ const Oid MACADDROID = 829; const Oid UUIDOID = 2950; +[[nodiscard]] Poco::Data::MetaColumn::ColumnDataType oidToColumnDataType(const Oid anOID); @@ -76,14 +77,19 @@ class InputParameter ~InputParameter(); + [[nodiscard]] CDT fieldType() const; + [[nodiscard]] const void* pData() const; + [[nodiscard]] std::size_t size() const; + [[nodiscard]] bool isBinary() const; void setStringVersionRepresentation(const std::string& aString); void setNonStringVersionRepresentation(const void* aPtr, std::size_t theSize); + [[nodiscard]] const void* pInternalRepresentation() const; private: @@ -114,11 +120,17 @@ class OutputParameter void setValues(CDT fieldType, Oid internalFieldType, std::size_t rowNumber, const char* dataPtr, std::size_t size, bool isNull); + [[nodiscard]] CDT fieldType() const; + [[nodiscard]] Oid internalFieldType() const; + [[nodiscard]] std::size_t rowNumber() const; + [[nodiscard]] const char* pData() const; + [[nodiscard]] std::size_t size() const; + [[nodiscard]] bool isNull() const; private: diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionHandle.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionHandle.h index f6387a4b87..1b4a6f3d32 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionHandle.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionHandle.h @@ -89,6 +89,7 @@ class SessionHandle void connect(const char* aHost, const char* aUser, const char* aPassword, const char* aDatabase, unsigned short aPort, unsigned int aConnectionTimeout); + [[nodiscard]] bool isConnected() const; /// is a connection established? @@ -98,12 +99,14 @@ class SessionHandle bool reset(); /// reset the connection + [[nodiscard]] std::string lastError() const; /// last error on the connection void startTransaction(); /// Start transaction + [[nodiscard]] bool isTransaction() const; /// Returns true iff a transaction is a transaction is in progress, false otherwise. @@ -113,12 +116,14 @@ class SessionHandle void rollback(); /// Rollback trabsaction + [[nodiscard]] bool isAutoCommit() const; /// is the connection in auto commit mode? void autoCommit(bool val); /// is the connection in auto commit mode? + [[nodiscard]] bool isAsynchronousCommit() const; /// is the connection in Asynchronous commit mode? @@ -131,9 +136,11 @@ class SessionHandle void setTransactionIsolation(Poco::UInt32 aTI); /// Sets the transaction isolation level. + [[nodiscard]] Poco::UInt32 transactionIsolation() const; /// Returns the transaction isolation level. + [[nodiscard]] static bool hasTransactionIsolation(Poco::UInt32 aTI); /// Returns true iff the transaction isolation level corresponding /// to the supplied bitmask is supported. @@ -141,46 +148,60 @@ class SessionHandle void deallocatePreparedStatement(const std::string& aPreparedStatementToDeAllocate); /// deallocates a previously prepared statement + [[nodiscard]] int serverVersion() const; /// remote server version + [[nodiscard]] int serverProcessID() const; /// the process ID of the remotee server process + [[nodiscard]] int protocoVersion() const; /// the protocol version between the client and the server + [[nodiscard]] std::string clientEncoding() const; /// returns the client encoding + [[nodiscard]] std::string parameterStatus(const std::string& param) const; /// Returns the value configured on the server for the given parameter. + [[nodiscard]] int libpqVersion() const; /// returns the version of libpq + [[nodiscard]] static SessionParametersMap connectionDefaultParameters(); /// returns the default parameters used on a connection + [[nodiscard]] SessionParametersMap connectionParameters() const; /// returns the parameters used on the connection + [[nodiscard]] std::string connectionString() const; /// returns the string used to connect + [[nodiscard]] operator PGconn* (); /// Get the PostgreSQL connection pointer + [[nodiscard]] Poco::FastMutex& mutex(); /// Get the sessionHandle mutex to protect the connection pointer private: + [[nodiscard]] static SessionParametersMap setConnectionInfoParameters(PQconninfoOption* aConnectionInfoOptionsPtr); void deallocateStoredPreparedStatements(); void deallocatePreparedStatementNoLock(const std::string& aPreparedStatementToDeAllocate); + [[nodiscard]] bool isConnectedNoLock() const; + [[nodiscard]] std::string lastErrorNoLock() const; SessionHandle(const SessionHandle&) = delete; diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionImpl.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionImpl.h index a43548edb2..85d7238861 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionImpl.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/SessionImpl.h @@ -50,6 +50,7 @@ class PostgreSQL_API SessionImpl: public Poco::Data::AbstractSessionImpl& col = rset.column(0); assertTrue (col[0] == 1); - try { rset.column(100); fail("must fail"); } - catch (Poco::RangeException&) {} + try { [[maybe_unused]] const Column& _ = rset.column(100); fail("must fail"); } + catch ([[maybe_unused]] Poco::RangeException& e) {} const Column& col1 = rset.column(0); assertTrue ("int0" == col1.name()); @@ -1058,8 +1058,8 @@ void SQLExecutor::internalExtraction() stmt = (*_pSession << "DELETE FROM Vectors", now); rset = stmt; - try { rset.column(0); fail("must fail"); } - catch (RangeException&) {} + try { [[maybe_unused]] const Column& _ = rset.column(0); fail("must fail"); } + catch ([[maybe_unused]] RangeException& e) {} } diff --git a/Data/SQLite/include/Poco/Data/SQLite/Connector.h b/Data/SQLite/include/Poco/Data/SQLite/Connector.h index f09b9aa6c1..75ad37d335 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/Connector.h +++ b/Data/SQLite/include/Poco/Data/SQLite/Connector.h @@ -38,9 +38,11 @@ class SQLite_API Connector: public Poco::Data::Connector ~Connector() override; /// Destroys the Connector. + [[nodiscard]] const std::string& name() const override; /// Returns the name associated with this connector. + [[nodiscard]] Poco::AutoPtr createSession(const std::string& connectionString, std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT) override; /// Creates a SQLite SessionImpl object and initializes it with the given connectionString. diff --git a/Data/SQLite/include/Poco/Data/SQLite/Extractor.h b/Data/SQLite/include/Poco/Data/SQLite/Extractor.h index 65bb8b093d..494817cba4 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/Extractor.h +++ b/Data/SQLite/include/Poco/Data/SQLite/Extractor.h @@ -421,6 +421,7 @@ class SQLite_API Extractor: public Poco::Data::AbstractExtractor bool extract(std::size_t pos, std::list& val) override; /// Throws NotImplementedException. + [[nodiscard]] bool isNull(std::size_t pos, std::size_t row = POCO_DATA_INVALID_ROW) override; /// Returns true if the current row value at pos column is null. /// Because of the loss of information about null-ness of the diff --git a/Data/SQLite/include/Poco/Data/SQLite/Notifier.h b/Data/SQLite/include/Poco/Data/SQLite/Notifier.h index 8f12c754e8..0068878970 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/Notifier.h +++ b/Data/SQLite/include/Poco/Data/SQLite/Notifier.h @@ -83,6 +83,7 @@ class SQLite_API Notifier bool disableUpdate(); /// Disables update callbacks. + [[nodiscard]] bool updateEnabled() const; /// Returns true if update callbacks are enabled, false otherwise. @@ -92,6 +93,7 @@ class SQLite_API Notifier bool disableCommit(); /// Disables commit callbacks. + [[nodiscard]] bool commitEnabled() const; /// Returns true if update callbacks are enabled, false otherwise. @@ -101,6 +103,7 @@ class SQLite_API Notifier bool disableRollback(); /// Disables rollback callbacks. + [[nodiscard]] bool rollbackEnabled() const; /// Returns true if rollback callbacks are enabled, false otherwise. @@ -123,22 +126,26 @@ class SQLite_API Notifier static void sqliteRollbackCallbackFn(void* pVal); /// Rollback callback event dispatcher. + [[nodiscard]] bool operator == (const Notifier& other) const; /// Equality operator. Compares value, row and database handles and /// returns true iff all are equal. + [[nodiscard]] const std::string& getTable() const; /// Returns the table name. void setTable(const std::string& table); /// Sets the row number. + [[nodiscard]] Poco::Int64 getRow() const; /// Returns the row number. void setRow(Poco::Int64 row); /// Sets the row number. + [[nodiscard]] const Poco::Dynamic::Var& getValue() const; /// Returns the value. diff --git a/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h b/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h index b15fd32539..ffe70dc7ec 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h +++ b/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h @@ -47,28 +47,35 @@ class SQLite_API SQLiteStatementImpl: public Poco::Data::StatementImpl /// Destroys the SQLiteStatementImpl. protected: + [[nodiscard]] std::size_t columnsReturned() const override; /// Returns number of columns returned by query. + [[nodiscard]] int affectedRowCount() const override; /// Returns the number of affected rows. /// Used to find out the number of rows affected by insert, delete or update. /// All changes are counted, even if they are later undone by a ROLLBACK or ABORT. /// Changes associated with creating and dropping tables are not counted. + [[nodiscard]] const MetaColumn& metaColumn(std::size_t pos) const override; /// Returns column meta data. + [[nodiscard]] bool hasNext() override; /// Returns true if a call to next() will return data. + [[nodiscard]] std::size_t next() override; /// Retrieves the next row from the resultset and returns 1. /// Will throw, if the resultset is empty. + [[nodiscard]] bool canBind() const override; /// Returns true if a valid statement is set and we can bind. + [[nodiscard]] bool canCompile() const override; /// Returns true if statement can compile. @@ -83,9 +90,11 @@ class SQLite_API SQLiteStatementImpl: public Poco::Data::StatementImpl void bindImpl() override; /// Binds parameters + [[nodiscard]] AbstractExtraction::ExtractorPtr extractor() override; /// Returns the concrete extractor used by the statement. + [[nodiscard]] AbstractBinding::BinderPtr binder() override; /// Returns the concrete binder used by the statement. diff --git a/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h b/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h index 5a6e2aa148..67cb1e0d35 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h +++ b/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h @@ -70,6 +70,7 @@ class SQLite_API SessionImpl: public Poco::Data::AbstractSessionImpl& col = rset.column(0); assertTrue (col[0] == 1); - try { rset.column(100); fail ("must fail"); } - catch (RangeException&) { } + try { [[maybe_unused]] const Column& _ = rset.column(100); fail ("must fail"); } + catch ([[maybe_unused]] RangeException& e) { } const Column& col1 = rset.column(0); assertTrue ("int0" == col1.name()); @@ -2247,8 +2247,8 @@ void SQLiteTest::testInternalExtraction() stmt = (tmp << "DELETE FROM Vectors", now); rset = stmt; - try { rset.column(0); fail ("must fail"); } - catch (RangeException&) { } + try { [[maybe_unused]] const Column& _ = rset.column(0); fail ("must fail"); } + catch ([[maybe_unused]] RangeException& e) { } } @@ -2271,7 +2271,7 @@ void SQLiteTest::testPrimaryKeyConstraint() if (i > 0) fail("must fail"); } - catch(Poco::Exception&) + catch([[maybe_unused]] Poco::Exception& e) { if (i == 0) // the very first insert must work throw; diff --git a/Data/include/Poco/Data/AbstractBinder.h b/Data/include/Poco/Data/AbstractBinder.h index 886b7e98f4..9b62aeb1d8 100644 --- a/Data/include/Poco/Data/AbstractBinder.h +++ b/Data/include/Poco/Data/AbstractBinder.h @@ -352,17 +352,21 @@ class Data_API AbstractBinder virtual void reset(); /// Resets a binder. No-op by default. Implement for binders that cache data. + [[nodiscard]] static bool isOutBound(Direction dir); /// Returns true if direction is out bound; + [[nodiscard]] static bool isInBound(Direction dir); /// Returns true if direction is in bound; protected: + [[nodiscard]] bool transcodeRequired() const; void transcode(const std::string& from, std::string& to); void reverseTranscode(const std::string& from, std::string& to); + [[nodiscard]] const std::string& toString(const UUID& uuid); /// Stores a string representation of uuid and returns a reference to it diff --git a/Data/include/Poco/Data/AbstractBinding.h b/Data/include/Poco/Data/AbstractBinding.h index 8e7450c5ec..712efab6a0 100644 --- a/Data/include/Poco/Data/AbstractBinding.h +++ b/Data/include/Poco/Data/AbstractBinding.h @@ -55,21 +55,25 @@ class Data_API AbstractBinding void setBinder(BinderPtr pBinder); /// Sets the object used for binding; object does NOT take ownership of the pointer. + [[nodiscard]] BinderPtr getBinder() const; /// Returns the AbstractBinder used for binding data. + [[nodiscard]] virtual std::size_t numOfColumnsHandled() const = 0; /// Returns the number of columns that the binding handles. /// /// The trivial case will be one single column but when /// complex types are used this value can be larger than one. + [[nodiscard]] virtual std::size_t numOfRowsHandled() const = 0; /// Returns the number of rows that the binding handles. /// /// The trivial case will be one single row but /// for collection data types it can be larger. + [[nodiscard]] virtual bool canBind() const = 0; /// Returns true if we have enough data to bind @@ -79,15 +83,19 @@ class Data_API AbstractBinding virtual void reset() = 0; /// Allows a binding to be reused. + [[nodiscard]] AbstractBinder::Direction getDirection() const; /// Returns the binding direction. + [[nodiscard]] const std::string& name() const; /// Returns the name for this binding. + [[nodiscard]] bool isBulk() const; /// Returns true if extraction is bulk. + [[nodiscard]] Poco::UInt32 bulkSize() const; /// Returns the size of the bulk binding. diff --git a/Data/include/Poco/Data/AbstractExtraction.h b/Data/include/Poco/Data/AbstractExtraction.h index 9e4e94fbb3..7956364151 100644 --- a/Data/include/Poco/Data/AbstractExtraction.h +++ b/Data/include/Poco/Data/AbstractExtraction.h @@ -58,24 +58,29 @@ class Data_API AbstractExtraction void setExtractor(ExtractorPtr pExtractor); /// Sets the class used for extracting the data. Does not take ownership of the pointer. + [[nodiscard]] ExtractorPtr getExtractor() const; /// Retrieves the extractor object + [[nodiscard]] Poco::UInt32 position() const; /// Returns the extraction position. + [[nodiscard]] virtual std::size_t numOfColumnsHandled() const = 0; /// Returns the number of columns that the extraction handles. /// /// The trivial case will be one single column but when /// complex types are used this value can be larger than one. + [[nodiscard]] virtual std::size_t numOfRowsHandled() const = 0; /// Returns the number of rows that the extraction handles. /// /// The trivial case will be one single row but /// for collection data types (ie vector) it can be larger. + [[nodiscard]] virtual std::size_t numOfRowsAllowed() const = 0; /// Returns the upper limit on number of rows that the extraction will handle. @@ -88,18 +93,22 @@ class Data_API AbstractExtraction /// Does nothing in this implementation. /// Implementations should override it for different behavior. + [[nodiscard]] virtual bool canExtract() const; /// Returns true. Implementations should override it for different behavior. + [[nodiscard]] virtual AbstractPreparation::Ptr createPreparation(PreparatorPtr& pPrep, std::size_t pos) = 0; /// Creates and returns shared pointer to Preparation object for the extracting object. void setLimit(Poco::UInt32 limit); /// Sets the limit. + [[nodiscard]] Poco::UInt32 getLimit() const; /// Gets the limit. + [[nodiscard]] virtual bool isNull(std::size_t row) const; /// In implementations, this function returns true if value at row is null, /// false otherwise. @@ -108,23 +117,27 @@ class Data_API AbstractExtraction /// null values and be able to later provide information about them. /// Here, this function throws NotImplementedException. + [[nodiscard]] bool isBulk() const; /// Returns true if this is bulk extraction. void setEmptyStringIsNull(bool emptyStringIsNull); /// Sets the empty string handling flag. + [[nodiscard]] bool getEmptyStringIsNull() const; /// Returns the empty string handling flag. void setForceEmptyString(bool forceEmptyString); /// Sets the force empty string flag. + [[nodiscard]] bool getForceEmptyString() const; /// Returns the force empty string flag. template - bool isValueNull(const T& /*str*/, bool deflt) + [[nodiscard]] + bool isValueNull([[maybe_unused]] const T& str, bool deflt) /// Utility function to determine the nullness of the value. /// This generic version always returns default value /// (i.e. does nothing). The std::string overload does @@ -134,6 +147,7 @@ class Data_API AbstractExtraction return deflt; } + [[nodiscard]] bool isValueNull(const std::string& str, bool deflt); /// Overload for const reference to std::string. /// @@ -142,6 +156,7 @@ class Data_API AbstractExtraction /// - string is empty /// - getEmptyStringIsNull() returns true + [[nodiscard]] bool isValueNull(const Poco::UTF16String& str, bool deflt); /// Overload for const reference to UTF16String. /// @@ -150,6 +165,7 @@ class Data_API AbstractExtraction /// - string is empty /// - getEmptyStringIsNull() returns true + [[nodiscard]] std::string getHeldType() const /// Returns the held type name, if set. /// If held type name is not set, returns empty string. @@ -171,6 +187,7 @@ class Data_API AbstractExtraction private: template + [[nodiscard]] bool isStringNull(const S& str, bool deflt) { if (getForceEmptyString()) return false; @@ -226,7 +243,7 @@ inline Poco::UInt32 AbstractExtraction::getLimit() const } -inline bool AbstractExtraction::isNull(std::size_t /*row*/) const +inline bool AbstractExtraction::isNull([[maybe_unused]] std::size_t row) const { throw NotImplementedException("Check for null values not implemented."); } diff --git a/Data/include/Poco/Data/AbstractExtractor.h b/Data/include/Poco/Data/AbstractExtractor.h index 6893df1294..c254b589b9 100644 --- a/Data/include/Poco/Data/AbstractExtractor.h +++ b/Data/include/Poco/Data/AbstractExtractor.h @@ -428,6 +428,7 @@ class Data_API AbstractExtractor virtual bool extract(std::size_t pos, Poco::Nullable& val); /// Extracts a nullable Var. + [[nodiscard]] virtual bool isNull(std::size_t col, std::size_t row = POCO_DATA_INVALID_ROW) = 0; /// Returns true if the value at [col,row] position is null. @@ -435,6 +436,7 @@ class Data_API AbstractExtractor /// Resets any information internally cached by the extractor. protected: + [[nodiscard]] bool transcodeRequired() const; void transcode(const std::string& from, std::string& to); void reverseTranscode(const std::string& from, std::string& to); diff --git a/Data/include/Poco/Data/AbstractPreparation.h b/Data/include/Poco/Data/AbstractPreparation.h index bda3cbb944..af3bf7e06e 100644 --- a/Data/include/Poco/Data/AbstractPreparation.h +++ b/Data/include/Poco/Data/AbstractPreparation.h @@ -48,6 +48,7 @@ class Data_API AbstractPreparation /// Prepares data. protected: + [[nodiscard]] PreparatorPtr preparation(); /// Returns the preparation object diff --git a/Data/include/Poco/Data/AbstractPreparator.h b/Data/include/Poco/Data/AbstractPreparator.h index 13932bfc20..26b9df6829 100644 --- a/Data/include/Poco/Data/AbstractPreparator.h +++ b/Data/include/Poco/Data/AbstractPreparator.h @@ -67,7 +67,7 @@ class Data_API AbstractPreparator virtual ~AbstractPreparator(); /// Destroys the AbstractPreparator. - virtual void prepare(std::size_t pos, const Poco::Int8&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::Int8& val) = 0; /// Prepares an Int8. virtual void prepare(std::size_t pos, const std::vector& val); @@ -79,7 +79,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an Int8 list. - virtual void prepare(std::size_t pos, const Poco::UInt8&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::UInt8& val) = 0; /// Prepares an UInt8. virtual void prepare(std::size_t pos, const std::vector& val); @@ -91,7 +91,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an UInt8 list. - virtual void prepare(std::size_t pos, const Poco::Int16&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::Int16& val) = 0; /// Prepares an Int16. virtual void prepare(std::size_t pos, const std::vector& val); @@ -103,7 +103,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an Int16 list. - virtual void prepare(std::size_t pos, const Poco::UInt16&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::UInt16& val) = 0; /// Prepares an UInt16. virtual void prepare(std::size_t pos, const std::vector& val); @@ -115,7 +115,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an UInt16 list. - virtual void prepare(std::size_t pos, const Poco::Int32&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::Int32& val) = 0; /// Prepares an Int32. virtual void prepare(std::size_t pos, const std::vector& val); @@ -127,7 +127,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an Int32 list. - virtual void prepare(std::size_t pos, const Poco::UInt32&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::UInt32& val) = 0; /// Prepares an UInt32. virtual void prepare(std::size_t pos, const std::vector& val); @@ -139,7 +139,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an UInt32 list. - virtual void prepare(std::size_t pos, const Poco::Int64&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::Int64& val) = 0; /// Prepares an Int64. virtual void prepare(std::size_t pos, const std::vector& val); @@ -151,7 +151,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares an Int64 list. - virtual void prepare(std::size_t pos, const Poco::UInt64&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Poco::UInt64& val) = 0; /// Prepares an UInt64. virtual void prepare(std::size_t pos, const std::vector& val); @@ -164,10 +164,10 @@ class Data_API AbstractPreparator /// Prepares an UInt64 list. #ifndef POCO_INT64_IS_LONG - virtual void prepare(std::size_t pos, const long&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const long& val) = 0; /// Prepares a long. - virtual void prepare(std::size_t pos, const unsigned long&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const unsigned long& val) = 0; /// Prepares an unsigned long. virtual void prepare(std::size_t pos, const std::vector& val); @@ -189,7 +189,7 @@ class Data_API AbstractPreparator /// Prepares a unsigned long list. #endif - virtual void prepare(std::size_t pos, const bool&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const bool& val) = 0; /// Prepares a boolean. virtual void prepare(std::size_t pos, const std::vector& val); @@ -201,7 +201,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a boolean list. - virtual void prepare(std::size_t pos, const float&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const float& val) = 0; /// Prepares a float. virtual void prepare(std::size_t pos, const std::vector& val); @@ -213,7 +213,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a float list. - virtual void prepare(std::size_t pos, const double&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const double& val) = 0; /// Prepares a double. virtual void prepare(std::size_t pos, const std::vector& val); @@ -225,7 +225,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a double list. - virtual void prepare(std::size_t pos, const char&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const char& val) = 0; /// Prepares a single character. virtual void prepare(std::size_t pos, const std::vector& val); @@ -237,7 +237,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a character list. - virtual void prepare(std::size_t pos, const std::string&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const std::string& val) = 0; /// Prepares a string. virtual void prepare(std::size_t pos, const std::vector& val); @@ -249,7 +249,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a character list. - virtual void prepare(std::size_t pos, const UTF16String&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const UTF16String& val) = 0; /// Prepares a UTF16String. virtual void prepare(std::size_t pos, const std::vector& val); @@ -261,10 +261,10 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a UTF16String list. - virtual void prepare(std::size_t pos, const BLOB&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const BLOB& val) = 0; /// Prepares a BLOB. - virtual void prepare(std::size_t pos, const CLOB&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const CLOB& val) = 0; /// Prepares a CLOB. virtual void prepare(std::size_t pos, const std::vector& val); @@ -285,7 +285,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a CLOB list. - virtual void prepare(std::size_t pos, const DateTime&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const DateTime& val) = 0; /// Prepares a DateTime. virtual void prepare(std::size_t pos, const std::vector& val); @@ -297,7 +297,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a DateTime list. - virtual void prepare(std::size_t pos, const Date&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Date& val) = 0; /// Prepares a Date. virtual void prepare(std::size_t pos, const std::vector& val); @@ -309,7 +309,7 @@ class Data_API AbstractPreparator virtual void prepare(std::size_t pos, const std::list& val); /// Prepares a Date list. - virtual void prepare(std::size_t pos, const Time&) = 0; + virtual void prepare(std::size_t pos, [[maybe_unused]] const Time& val) = 0; /// Prepares a Time. virtual void prepare(std::size_t pos, const std::vector