diff --git a/include/pqxx/basic_connection.hxx b/include/pqxx/basic_connection.hxx index 9f5937ce9..6bd9c5b9d 100644 --- a/include/pqxx/basic_connection.hxx +++ b/include/pqxx/basic_connection.hxx @@ -48,7 +48,7 @@ template class basic_connection_base : public: basic_connection_base() : connection_base(m_policy), - m_options(std::string()), + m_options(std::string{}), m_policy(m_options) { init(); } @@ -62,7 +62,7 @@ public: /// See: @c basic_connection(const std::string &opt) explicit basic_connection_base(const char opt[]) : - basic_connection_base(opt ? std::string(opt) : std::string()) {} + basic_connection_base(opt ? std::string{opt} : std::string{}) {} explicit basic_connection_base(std::nullptr_t) : basic_connection_base() {} diff --git a/include/pqxx/binarystring.hxx b/include/pqxx/binarystring.hxx index cbbb415df..93146274a 100644 --- a/include/pqxx/binarystring.hxx +++ b/include/pqxx/binarystring.hxx @@ -92,10 +92,10 @@ public: { return *(data()+m_size-1); } const_reverse_iterator rbegin() const //[t62] - { return const_reverse_iterator(end()); } + { return const_reverse_iterator{end()}; } const_reverse_iterator crbegin() const { return rbegin(); } const_reverse_iterator rend() const //[t62] - { return const_reverse_iterator(begin()); } + { return const_reverse_iterator{begin()}; } const_reverse_iterator crend() const { return rend(); } /// Unescaped field contents @@ -138,9 +138,9 @@ private: /// Shorthand: construct a smart_pointer_type. static smart_pointer_type make_smart_pointer(unsigned char *buf=nullptr) { - return smart_pointer_type( + return smart_pointer_type{ buf, - internal::freemallocmem_templated); + internal::freemallocmem_templated}; } smart_pointer_type m_buf; diff --git a/include/pqxx/connection.hxx b/include/pqxx/connection.hxx index 0101f4d29..261c06123 100644 --- a/include/pqxx/connection.hxx +++ b/include/pqxx/connection.hxx @@ -89,7 +89,7 @@ class PQXX_LIBEXPORT connect_direct : public connectionpolicy public: /// The parsing of options is the same as in libpq's PQconnect. /// See: https://www.postgresql.org/docs/10/static/libpq-connect.html - explicit connect_direct(const std::string &opts) : connectionpolicy(opts) {} + explicit connect_direct(const std::string &opts) : connectionpolicy{opts} {} virtual handle do_startconnect(handle) override; }; @@ -107,7 +107,7 @@ class PQXX_LIBEXPORT connect_lazy : public connectionpolicy public: /// The parsing of options is the same as in libpq's PQconnect. /// See: https://www.postgresql.org/docs/10/static/libpq-connect.html - explicit connect_lazy(const std::string &opts) : connectionpolicy(opts) {} + explicit connect_lazy(const std::string &opts) : connectionpolicy{opts} {} virtual handle do_completeconnect(handle) override; }; @@ -152,7 +152,7 @@ using asyncconnection = basic_connection_base; class PQXX_LIBEXPORT connect_null : public connectionpolicy { public: - explicit connect_null(const std::string &opts) : connectionpolicy(opts) {} + explicit connect_null(const std::string &opts) : connectionpolicy{opts} {} }; diff --git a/include/pqxx/connection_base.hxx b/include/pqxx/connection_base.hxx index a29f54284..55bd99b2d 100644 --- a/include/pqxx/connection_base.hxx +++ b/include/pqxx/connection_base.hxx @@ -504,9 +504,9 @@ public: * void foo(connection_base &C) * { * C.prepare("findtable", "select * from pg_tables where name=$1"); - * work W(C); + * work W{C}; * result R = W.exec_prepared("findtable", "mytable"); - * if (R.empty()) throw runtime_error("mytable not found!"); + * if (R.empty()) throw runtime_error{"mytable not found!"}; * } * @endcode * @@ -679,7 +679,7 @@ public: protected: explicit connection_base(connectionpolicy &pol) : - m_policy(pol) + m_policy{pol} { // Check library version. The check_library_version template is declared // for any library version, but only actually defined for the version of diff --git a/include/pqxx/cursor.hxx b/include/pqxx/cursor.hxx index ced01ddb9..e79e8bd71 100644 --- a/include/pqxx/cursor.hxx +++ b/include/pqxx/cursor.hxx @@ -271,7 +271,7 @@ public: const std::string &query, const std::string &cname, bool hold) : - m_cur(trans, query, cname, cursor_base::random_access, up, op, hold) + m_cur{trans, query, cname, cursor_base::random_access, up, op, hold} { } @@ -279,7 +279,7 @@ public: stateless_cursor( transaction_base &trans, const std::string adopted_cursor) : - m_cur(trans, adopted_cursor, op) + m_cur{trans, adopted_cursor, op} { // Put cursor in known position m_cur.move(cursor_base::backward_all()); diff --git a/include/pqxx/errorhandler.hxx b/include/pqxx/errorhandler.hxx index 196443e14..54417f820 100644 --- a/include/pqxx/errorhandler.hxx +++ b/include/pqxx/errorhandler.hxx @@ -75,7 +75,7 @@ private: class quiet_errorhandler : public errorhandler { public: - quiet_errorhandler(connection_base &conn) : errorhandler(conn) {} + quiet_errorhandler(connection_base &conn) : errorhandler{conn} {} virtual bool operator()(const char[]) noexcept override { return false; } }; diff --git a/include/pqxx/except.hxx b/include/pqxx/except.hxx index b1fdc89c3..bda4c3f0c 100644 --- a/include/pqxx/except.hxx +++ b/include/pqxx/except.hxx @@ -262,7 +262,7 @@ class PQXX_LIBEXPORT unexpected_rows : public range_error virtual const std::exception &base() const noexcept override { return *this; } public: - explicit unexpected_rows(const std::string &msg) : range_error(msg) {} + explicit unexpected_rows(const std::string &msg) : range_error{msg} {} }; @@ -274,7 +274,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; /// Error in data provided to SQL statement @@ -285,7 +285,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT integrity_constraint_violation : public sql_error @@ -295,7 +295,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT restrict_violation : @@ -306,7 +306,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - integrity_constraint_violation(err, Q, sqlstate) {} + integrity_constraint_violation{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT not_null_violation : @@ -317,7 +317,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - integrity_constraint_violation(err, Q, sqlstate) {} + integrity_constraint_violation{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT foreign_key_violation : @@ -328,7 +328,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - integrity_constraint_violation(err, Q, sqlstate) {} + integrity_constraint_violation{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT unique_violation : @@ -339,7 +339,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - integrity_constraint_violation(err, Q, sqlstate) {} + integrity_constraint_violation{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT check_violation : @@ -350,7 +350,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - integrity_constraint_violation(err, Q, sqlstate) {} + integrity_constraint_violation{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT invalid_cursor_state : public sql_error @@ -360,7 +360,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT invalid_sql_statement_name : public sql_error @@ -370,7 +370,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT invalid_cursor_name : public sql_error @@ -380,7 +380,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT syntax_error : public sql_error @@ -394,7 +394,7 @@ public: const std::string &Q="", const char sqlstate[]=nullptr, int pos=-1) : - sql_error(err, Q, sqlstate), error_position(pos) {} + sql_error{err, Q, sqlstate}, error_position{pos} {} }; class PQXX_LIBEXPORT undefined_column : public syntax_error @@ -404,7 +404,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - syntax_error(err, Q, sqlstate) {} + syntax_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT undefined_function : public syntax_error @@ -414,7 +414,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - syntax_error(err, Q, sqlstate) {} + syntax_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT undefined_table : public syntax_error @@ -424,7 +424,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - syntax_error(err, Q, sqlstate) {} + syntax_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT insufficient_privilege : public sql_error @@ -434,7 +434,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; /// Resource shortage on the server @@ -445,7 +445,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err,Q, sqlstate) {} + sql_error{err,Q, sqlstate} {} }; class PQXX_LIBEXPORT disk_full : public insufficient_resources @@ -455,7 +455,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - insufficient_resources(err, Q, sqlstate) {} + insufficient_resources{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT out_of_memory : public insufficient_resources @@ -465,14 +465,14 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - insufficient_resources(err, Q, sqlstate) {} + insufficient_resources{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT too_many_connections : public broken_connection { public: explicit too_many_connections(const std::string &err) : - broken_connection(err) {} + broken_connection{err} {} }; /// PL/pgSQL error @@ -485,7 +485,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - sql_error(err, Q, sqlstate) {} + sql_error{err, Q, sqlstate} {} }; /// Exception raised in PL/pgSQL procedure @@ -496,7 +496,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - plpgsql_error(err, Q, sqlstate) {} + plpgsql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT plpgsql_no_data_found : public plpgsql_error @@ -506,7 +506,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - plpgsql_error(err, Q, sqlstate) {} + plpgsql_error{err, Q, sqlstate} {} }; class PQXX_LIBEXPORT plpgsql_too_many_rows : public plpgsql_error @@ -516,7 +516,7 @@ public: const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr) : - plpgsql_error(err, Q, sqlstate) {} + plpgsql_error{err, Q, sqlstate} {} }; /** diff --git a/include/pqxx/field.hxx b/include/pqxx/field.hxx index 7f3700ac7..c482462ed 100644 --- a/include/pqxx/field.hxx +++ b/include/pqxx/field.hxx @@ -207,7 +207,7 @@ public: * you keep the @c row of @c field object alive, it will keep the @c result * object alive as well. */ - array_parser as_array() const { return array_parser(c_str()); } + array_parser as_array() const { return array_parser{c_str()}; } //@} @@ -234,7 +234,7 @@ inline bool field::to(std::string &Obj) const { const char *const bytes = c_str(); if (bytes[0] == '\0' and is_null()) return false; - Obj = std::string(bytes, size()); + Obj = std::string{bytes, size()}; return true; } @@ -267,7 +267,7 @@ public: using seekdir = std::ios::seekdir; explicit field_streambuf(const field &F) : //[t74] - m_field(F) + m_field{F} { initialize(); } @@ -320,7 +320,7 @@ public: using pos_type = typename traits_type::pos_type; using off_type = typename traits_type::off_type; - basic_fieldstream(const field &F) : super(nullptr), m_buf(F) + basic_fieldstream(const field &F) : super{nullptr}, m_buf{F} { super::init(&m_buf); } private: diff --git a/include/pqxx/internal/gates/transaction-stream_to.hxx b/include/pqxx/internal/gates/transaction-stream_to.hxx index b2fe1ac3f..6ee9e9b7d 100644 --- a/include/pqxx/internal/gates/transaction-stream_to.hxx +++ b/include/pqxx/internal/gates/transaction-stream_to.hxx @@ -14,7 +14,7 @@ class PQXX_PRIVATE transaction_stream_to : callgate void BeginCopyWrite( const std::string &table, - const std::string &columns = std::string()) + const std::string &columns = std::string{}) { home().BeginCopyWrite(table, columns); } void write_copy_line(const std::string &line) diff --git a/include/pqxx/internal/gates/transaction-tablewriter.hxx b/include/pqxx/internal/gates/transaction-tablewriter.hxx index 755eb0bad..3256090a2 100644 --- a/include/pqxx/internal/gates/transaction-tablewriter.hxx +++ b/include/pqxx/internal/gates/transaction-tablewriter.hxx @@ -14,7 +14,7 @@ class PQXX_PRIVATE transaction_tablewriter : callgate void BeginCopyWrite( const std::string &table, - const std::string &columns = std::string()) + const std::string &columns = std::string{}) { home().BeginCopyWrite(table, columns); } void write_copy_line(const std::string &line) diff --git a/include/pqxx/isolation.hxx b/include/pqxx/isolation.hxx index 0d7e1bcc0..a745a85bc 100644 --- a/include/pqxx/isolation.hxx +++ b/include/pqxx/isolation.hxx @@ -84,5 +84,4 @@ inline constexpr const char *isolation_traits::name() noexcept } #include "pqxx/compiler-internal-post.hxx" - #endif diff --git a/include/pqxx/largeobject.hxx b/include/pqxx/largeobject.hxx index 270fdeb0e..3328a6ead 100644 --- a/include/pqxx/largeobject.hxx +++ b/include/pqxx/largeobject.hxx @@ -49,7 +49,7 @@ public: * large object identity. Does not affect the database. * @param O Object identifier for the given object */ - explicit largeobject(oid O) noexcept : m_id(O) {} //[t48] + explicit largeobject(oid O) noexcept : m_id{O} {} //[t48] /// Import large object from a local file /** Creates a large object containing the data found in the given file. @@ -363,10 +363,10 @@ public: largeobject O, openmode mode=std::ios::in|std::ios::out, size_type BufSize=512) : - m_bufsize(BufSize), - m_obj(T, O, mode), - m_g(nullptr), - m_p(nullptr) + m_bufsize{BufSize}, + m_obj{T, O, mode}, + m_g{nullptr}, + m_p{nullptr} { initialize(mode); } largeobject_streambuf( //[t48] @@ -374,10 +374,10 @@ public: oid O, openmode mode=std::ios::in|std::ios::out, size_type BufSize=512) : - m_bufsize(BufSize), - m_obj(T, O, mode), - m_g(nullptr), - m_p(nullptr) + m_bufsize{BufSize}, + m_obj{T, O, mode}, + m_g{nullptr}, + m_p{nullptr} { initialize(mode); } virtual ~largeobject_streambuf() noexcept @@ -504,8 +504,8 @@ public: dbtransaction &T, largeobject O, largeobject::size_type BufSize=512) : - super(nullptr), - m_buf(T, O, std::ios::in, BufSize) + super{nullptr}, + m_buf{T, O, std::ios::in, BufSize} { super::init(&m_buf); } /// Create a basic_ilostream @@ -518,8 +518,8 @@ public: dbtransaction &T, oid O, largeobject::size_type BufSize=512) : - super(nullptr), - m_buf(T, O, std::ios::in, BufSize) + super{nullptr}, + m_buf{T, O, std::ios::in, BufSize} { super::init(&m_buf); } private: @@ -560,8 +560,8 @@ public: dbtransaction &T, largeobject O, largeobject::size_type BufSize=512) : - super(nullptr), - m_buf(T, O, std::ios::out, BufSize) + super{nullptr}, + m_buf{T, O, std::ios::out, BufSize} { super::init(&m_buf); } /// Create a basic_olostream @@ -574,8 +574,8 @@ public: dbtransaction &T, oid O, largeobject::size_type BufSize=512) : - super(nullptr), - m_buf(T, O, std::ios::out, BufSize) + super{nullptr}, + m_buf{T, O, std::ios::out, BufSize} { super::init(&m_buf); } ~basic_olostream() @@ -629,8 +629,8 @@ public: dbtransaction &T, largeobject O, largeobject::size_type BufSize=512) : - super(nullptr), - m_buf(T, O, std::ios::in | std::ios::out, BufSize) + super{nullptr}, + m_buf{T, O, std::ios::in | std::ios::out, BufSize} { super::init(&m_buf); } /// Create a basic_lostream @@ -643,8 +643,8 @@ public: dbtransaction &T, oid O, largeobject::size_type BufSize=512) : - super(nullptr), - m_buf(T, O, std::ios::in | std::ios::out, BufSize) + super{nullptr}, + m_buf{T, O, std::ios::in | std::ios::out, BufSize} { super::init(&m_buf); } ~basic_lostream() diff --git a/include/pqxx/nontransaction.hxx b/include/pqxx/nontransaction.hxx index 40930c1c7..e248d8b62 100644 --- a/include/pqxx/nontransaction.hxx +++ b/include/pqxx/nontransaction.hxx @@ -62,8 +62,8 @@ public: */ explicit nontransaction( //[t14] connection_base &C, - const std::string &Name=std::string()) : - namedclass("nontransaction", Name), transaction_base(C) { Begin(); } + const std::string &Name=std::string{}) : + namedclass{"nontransaction", Name}, transaction_base{C} { Begin(); } virtual ~nontransaction(); //[t14] @@ -77,5 +77,4 @@ private: } // namespace pqxx #include "pqxx/compiler-internal-post.hxx" - #endif diff --git a/include/pqxx/pipeline.hxx b/include/pqxx/pipeline.hxx index a206b91f9..27bb75b22 100644 --- a/include/pqxx/pipeline.hxx +++ b/include/pqxx/pipeline.hxx @@ -55,7 +55,7 @@ public: explicit pipeline( //[t69] transaction_base &, - const std::string &Name=std::string()); + const std::string &Name=std::string{}); ~pipeline() noexcept; @@ -214,5 +214,4 @@ private: } // namespace #include "pqxx/compiler-internal-post.hxx" - #endif diff --git a/include/pqxx/result.hxx b/include/pqxx/result.hxx index 5cea6d780..73023a886 100644 --- a/include/pqxx/result.hxx +++ b/include/pqxx/result.hxx @@ -200,7 +200,7 @@ private: /// Factory for data_pointer. static data_pointer make_data_pointer( const internal::pq::PGresult *res=nullptr) - { return data_pointer(res, internal::clear_result); } + { return data_pointer{res, internal::clear_result}; } /// Query string. std::shared_ptr m_query; diff --git a/include/pqxx/result_iterator.hxx b/include/pqxx/result_iterator.hxx index ac03379d1..5311bbe8c 100644 --- a/include/pqxx/result_iterator.hxx +++ b/include/pqxx/result_iterator.hxx @@ -47,8 +47,8 @@ public: using size_type = result_size_type; using difference_type = result_difference_type; - const_result_iterator() noexcept : row(result(), 0) {} - const_result_iterator(const row &t) noexcept : row(t) {} + const_result_iterator() noexcept : row{result(), 0} {} + const_result_iterator(const row &t) noexcept : row{t} {} /** * @name Dereferencing operators @@ -66,7 +66,7 @@ public: * distinguished company. */ pointer operator->() const { return this; } //[t12] - reference operator*() const { return row(*this); } //[t12] + reference operator*() const { return row{*this}; } //[t12] //@} /** @@ -117,7 +117,7 @@ public: private: friend class pqxx::result; const_result_iterator(const pqxx::result *r, result_size_type i) noexcept : - row(*r, i) {} + row{*r, i} {} }; @@ -136,10 +136,10 @@ public: const_reverse_result_iterator( //[t75] const const_reverse_result_iterator &rhs) : - const_result_iterator(rhs) {} + const_result_iterator{rhs} {} explicit const_reverse_result_iterator( //[t75] const const_result_iterator &rhs) : - const_result_iterator(rhs) { super::operator--(); } + const_result_iterator{rhs} { super::operator--(); } PQXX_PURE const_result_iterator base() const noexcept; //[t75] @@ -209,8 +209,8 @@ public: inline const_result_iterator const_result_iterator::operator+(result::difference_type o) const { - return const_result_iterator( - &m_result, size_type(result::difference_type(m_index) + o)); + return const_result_iterator{ + &m_result, size_type(result::difference_type(m_index) + o)}; } inline const_result_iterator @@ -220,9 +220,9 @@ operator+(result::difference_type o, const_result_iterator i) inline const_result_iterator const_result_iterator::operator-(result::difference_type o) const { - return const_result_iterator( + return const_result_iterator{ &m_result, - result_size_type(result::difference_type(m_index) - o)); + result_size_type(result::difference_type(m_index) - o)}; } inline result::difference_type @@ -230,7 +230,7 @@ const_result_iterator::operator-(const_result_iterator i) const { return result::difference_type(num() - i.num()); } inline const_result_iterator result::end() const noexcept - { return const_result_iterator(this, size()); } + { return const_result_iterator{this, size()}; } inline const_result_iterator result::cend() const noexcept @@ -241,7 +241,7 @@ inline const_reverse_result_iterator operator+( result::difference_type n, const const_reverse_result_iterator &i) - { return const_reverse_result_iterator(i.base() - n); } + { return const_reverse_result_iterator{i.base() - n}; } } // namespace pqxx diff --git a/include/pqxx/robusttransaction.hxx b/include/pqxx/robusttransaction.hxx index 03942013b..af73a6b88 100644 --- a/include/pqxx/robusttransaction.hxx +++ b/include/pqxx/robusttransaction.hxx @@ -40,7 +40,7 @@ protected: basic_robusttransaction( connection_base &C, const std::string &IsolationLevel, - const std::string &table_name=std::string()); //[t16] + const std::string &table_name=std::string{}); //[t16] private: using IDType = unsigned long; @@ -149,9 +149,9 @@ public: */ explicit robusttransaction( connection_base &C, - const std::string &Name=std::string()) : - namedclass(fullname("robusttransaction",isolation_tag::name()), Name), - internal::basic_robusttransaction(C, isolation_tag::name()) + const std::string &Name=std::string{}) : + namedclass{fullname("robusttransaction",isolation_tag::name()), Name}, + internal::basic_robusttransaction{C, isolation_tag::name()} { Begin(); } virtual ~robusttransaction() noexcept diff --git a/include/pqxx/row.hxx b/include/pqxx/row.hxx index bc4b9f3fe..b2cde9688 100644 --- a/include/pqxx/row.hxx +++ b/include/pqxx/row.hxx @@ -224,15 +224,15 @@ public: using reference = field; const_row_iterator(const row &T, row_size_type C) noexcept : //[t82] - field(T, C) {} - const_row_iterator(const field &F) noexcept : field(F) {} //[t82] + field{T, C} {} + const_row_iterator(const field &F) noexcept : field{F} {} //[t82] /** * @name Dereferencing operators */ //@{ pointer operator->() const { return this; } //[t82] - reference operator*() const { return field(*this); } //[t82] + reference operator*() const { return field{*this}; } //[t82] //@} /** @@ -297,10 +297,10 @@ public: using reference = iterator_type::reference; const_reverse_row_iterator(const const_reverse_row_iterator &r) : //[t82] - const_row_iterator(r) {} + const_row_iterator{r} {} explicit const_reverse_row_iterator(const super &rhs) noexcept : //[t82] - const_row_iterator(rhs) { super::operator--(); } + const_row_iterator{rhs} { super::operator--(); } PQXX_PURE iterator_type base() const noexcept; //[t82] @@ -336,9 +336,9 @@ public: */ //@{ const_reverse_row_iterator operator+(difference_type i) const //[t82] - { return const_reverse_row_iterator(base()-i); } + { return const_reverse_row_iterator{base()-i}; } const_reverse_row_iterator operator-(difference_type i) //[t82] - { return const_reverse_row_iterator(base()+i); } + { return const_reverse_row_iterator{base()+i}; } difference_type operator-(const const_reverse_row_iterator &rhs) const //[t82] { return rhs.const_row_iterator::operator-(*this); } @@ -368,9 +368,9 @@ public: inline const_row_iterator const_row_iterator::operator+(difference_type o) const { - return const_row_iterator( + return const_row_iterator{ row(home(), idx()), - size_type(difference_type(col()) + o)); + size_type(difference_type(col()) + o)}; } inline const_row_iterator @@ -380,9 +380,9 @@ operator+(const_row_iterator::difference_type o, const_row_iterator i) inline const_row_iterator const_row_iterator::operator-(difference_type o) const { - return const_row_iterator( + return const_row_iterator{ row(home(), idx()), - size_type(difference_type(col()) - o)); + size_type(difference_type(col()) - o)}; } inline const_row_iterator::difference_type diff --git a/include/pqxx/strconv.hxx b/include/pqxx/strconv.hxx index 201b93290..3390a3dea 100644 --- a/include/pqxx/strconv.hxx +++ b/include/pqxx/strconv.hxx @@ -191,7 +191,7 @@ template<> struct PQXX_LIBEXPORT string_traits static constexpr bool has_null() noexcept { return false; } static bool is_null(const std::string &) { return false; } static std::string null() - { internal::throw_null_conversion(name()); return std::string(); } + { internal::throw_null_conversion(name()); return std::string{}; } static void from_string(const char Str[], std::string &Obj) { Obj=Str; } static std::string to_string(const std::string &Obj) { return Obj; } }; @@ -202,7 +202,7 @@ template<> struct PQXX_LIBEXPORT string_traits static constexpr bool has_null() noexcept { return false; } static bool is_null(const std::string &) { return false; } static const std::string null() - { internal::throw_null_conversion(name()); return std::string(); } + { internal::throw_null_conversion(name()); return std::string{}; } static const std::string to_string(const std::string &Obj) { return Obj; } }; @@ -242,7 +242,7 @@ template<> struct PQXX_LIBEXPORT string_traits template inline void from_string(const char Str[], T &Obj) { - if (Str == nullptr) throw std::runtime_error("Attempt to read null string"); + if (Str == nullptr) throw std::runtime_error{"Attempt to read null string."}; string_traits::from_string(Str, Obj); } @@ -265,7 +265,7 @@ template<> std::string &Obj, size_t len) { - if (Str == nullptr) throw std::runtime_error("Attempt to read null string"); + if (Str == nullptr) throw std::runtime_error{"Attempt to read null string."}; Obj.assign(Str, len); } diff --git a/include/pqxx/stream_base.hxx b/include/pqxx/stream_base.hxx index 2051edb42..ff8ea542d 100644 --- a/include/pqxx/stream_base.hxx +++ b/include/pqxx/stream_base.hxx @@ -59,5 +59,3 @@ template std::string stream_base::columnlist(I begin, I end) #include "pqxx/compiler-internal-post.hxx" #endif - - diff --git a/include/pqxx/stream_from.hxx b/include/pqxx/stream_from.hxx index c3ea4138f..04defa9e0 100644 --- a/include/pqxx/stream_from.hxx +++ b/include/pqxx/stream_from.hxx @@ -102,12 +102,12 @@ template stream_from::stream_from( transaction_base &tb, const std::string &table_name, const Columns& columns -) : stream_from( +) : stream_from{ tb, table_name, std::begin(columns), std::end(columns) -) {} +} {} template stream_from::stream_from( @@ -116,8 +116,8 @@ template stream_from::stream_from( Iter columns_begin, Iter columns_end ) : - namedclass("stream_from", table_name), - stream_base(tb) + namedclass{"stream_from", table_name}, + stream_base{tb} { setup( tb, diff --git a/include/pqxx/stream_to.hxx b/include/pqxx/stream_to.hxx index e6890b347..58be84f4b 100644 --- a/include/pqxx/stream_to.hxx +++ b/include/pqxx/stream_to.hxx @@ -76,12 +76,12 @@ template stream_to::stream_to( transaction_base &tb, const std::string &table_name, const Columns& columns -) : stream_to( +) : stream_to{ tb, table_name, std::begin(columns), std::end(columns) -) +} {} @@ -91,8 +91,8 @@ template stream_to::stream_to( Iter columns_begin, Iter columns_end ) : - namedclass("stream_from", table_name), - stream_base(tb) + namedclass{"stream_from", table_name}, + stream_base{tb} { setup( tb, diff --git a/include/pqxx/subtransaction.hxx b/include/pqxx/subtransaction.hxx index d70fb8e4b..0cca705d4 100644 --- a/include/pqxx/subtransaction.hxx +++ b/include/pqxx/subtransaction.hxx @@ -52,7 +52,7 @@ namespace pqxx * try * { * subtransaction S(W, "droptemp"); - * S.exec("DROP TABLE " + temptable); + * S.exec0("DROP TABLE " + temptable); * S.commit(); * } * catch (const undefined_table &) @@ -83,11 +83,11 @@ class PQXX_LIBEXPORT subtransaction : public: /// Nest a subtransaction nested in another transaction. explicit subtransaction( //[t88] - dbtransaction &T, const std::string &Name=std::string()); + dbtransaction &T, const std::string &Name=std::string{}); /// Nest a subtransaction in another subtransaction. explicit subtransaction( - subtransaction &T, const std::string &Name=std::string()); + subtransaction &T, const std::string &Name=std::string{}); virtual ~subtransaction() noexcept { End(); } @@ -99,10 +99,7 @@ private: dbtransaction &m_parent; }; - } - #include "pqxx/compiler-internal-post.hxx" - #endif diff --git a/include/pqxx/tablereader.hxx b/include/pqxx/tablereader.hxx index 6c1454a04..9adfb0ed2 100644 --- a/include/pqxx/tablereader.hxx +++ b/include/pqxx/tablereader.hxx @@ -32,7 +32,7 @@ public: PQXX_DEPRECATED tablereader( transaction_base &, const std::string &Name, - const std::string &Null=std::string()); + const std::string &Null=std::string{}); template PQXX_DEPRECATED tablereader( transaction_base &, @@ -58,7 +58,7 @@ private: void setup( transaction_base &T, const std::string &RName, - const std::string &Columns=std::string()); + const std::string &Columns=std::string{}); PQXX_PRIVATE void reader_close(); std::string extract_field( const std::string &, @@ -73,9 +73,9 @@ tablereader::tablereader( const std::string &Name, ITER begincolumns, ITER endcolumns) : - namedclass(Name, "tablereader"), - tablestream(T, std::string()), - m_done(true) + namedclass{Name, "tablereader"}, + tablestream{T, std::string{}}, + m_done{true} { setup(T, Name, columnlist(begincolumns, endcolumns)); } @@ -88,9 +88,9 @@ tablereader::tablereader( ITER begincolumns, ITER endcolumns, const std::string &Null) : - namedclass(Name, "tablereader"), - tablestream(T, Null), - m_done(true) + namedclass{Name, "tablereader"}, + tablestream{T, Null}, + m_done{true} { setup(T, Name, columnlist(begincolumns, endcolumns)); } @@ -100,7 +100,7 @@ template inline void tablereader::tokenize(std::string Line, TUPLE &T) const { std::back_insert_iterator ins = std::back_inserter(T); - std::string::size_type here=0; + std::string::size_type here = 0; while (here < Line.size()) *ins++ = extract_field(Line, here); } diff --git a/include/pqxx/tablestream.hxx b/include/pqxx/tablestream.hxx index b46a35fe7..065936602 100644 --- a/include/pqxx/tablestream.hxx +++ b/include/pqxx/tablestream.hxx @@ -29,7 +29,7 @@ class PQXX_LIBEXPORT PQXX_NOVTABLE tablestream : public: explicit tablestream( transaction_base &Trans, - const std::string &Null=std::string()); + const std::string &Null=std::string{}); virtual ~tablestream() noexcept =0; virtual void complete() =0; protected: diff --git a/include/pqxx/tablewriter.hxx b/include/pqxx/tablewriter.hxx index 58df2194a..7a6d87ae3 100644 --- a/include/pqxx/tablewriter.hxx +++ b/include/pqxx/tablewriter.hxx @@ -34,7 +34,7 @@ public: PQXX_DEPRECATED tablewriter( transaction_base &, const std::string &WName, - const std::string &Null=std::string()); + const std::string &Null=std::string{}); template PQXX_DEPRECATED tablewriter( transaction_base &, @@ -64,7 +64,7 @@ private: void setup( transaction_base &, const std::string &WName, - const std::string &Columns = std::string()); + const std::string &Columns = std::string{}); PQXX_PRIVATE void writer_close(); }; } // namespace pqxx @@ -78,7 +78,7 @@ template<> { public: explicit back_insert_iterator(pqxx::tablewriter &W) noexcept : - m_writer(&W) {} + m_writer{&W} {} back_insert_iterator & operator=(const back_insert_iterator &rhs) noexcept @@ -111,8 +111,8 @@ template inline tablewriter::tablewriter( const std::string &WName, ITER begincolumns, ITER endcolumns) : - namedclass("tablewriter", WName), - tablestream(T, std::string()) + namedclass{"tablewriter", WName}, + tablestream{T, std::string{}} { setup(T, WName, columnlist(begincolumns, endcolumns)); } @@ -124,8 +124,8 @@ template inline tablewriter::tablewriter( ITER begincolumns, ITER endcolumns, const std::string &Null) : - namedclass("tablewriter", WName), - tablestream(T, Null) + namedclass{"tablewriter", WName}, + tablestream{T, Null} { setup(T, WName, columnlist(begincolumns, endcolumns)); } @@ -145,7 +145,7 @@ inline std::string escape_any( inline std::string escape_any( const char s[], const std::string &null) -{ return s ? escape(std::string(s), null) : "\\N"; } +{ return s ? escape(std::string{s}, null) : "\\N"; } template inline std::string escape_any( const T &t, @@ -157,7 +157,7 @@ template class Escaper { const std::string &m_null; public: - explicit Escaper(const std::string &null) : m_null(null) {} + explicit Escaper(const std::string &null) : m_null{null} {} std::string operator()(IT i) const { return escape_any(*i, m_null); } }; } @@ -166,7 +166,7 @@ public: template inline std::string tablewriter::generate(IT Begin, IT End) const { - return separated_list("\t", Begin, End, internal::Escaper(NullStr())); + return separated_list("\t", Begin, End, internal::Escaper{NullStr()}); } template inline std::string tablewriter::generate(const TUPLE &T) const diff --git a/include/pqxx/transaction.hxx b/include/pqxx/transaction.hxx index 951cffb32..4ec5493f0 100644 --- a/include/pqxx/transaction.hxx +++ b/include/pqxx/transaction.hxx @@ -91,12 +91,12 @@ public: * may contain letters and digits only */ explicit transaction(connection_base &C, const std::string &TName): //[t01] - namedclass(fullname("transaction", isolation_tag::name()), TName), - internal::basic_transaction(C, isolation_tag::name(), READWRITE) + namedclass{fullname("transaction", isolation_tag::name()), TName}, + internal::basic_transaction{C, isolation_tag::name(), READWRITE} { Begin(); } explicit transaction(connection_base &C) : //[t01] - transaction(C, "") {} + transaction{C, ""} {} virtual ~transaction() noexcept { End(); } diff --git a/include/pqxx/transaction_base.hxx b/include/pqxx/transaction_base.hxx index e6bf5e0a3..c431a1819 100644 --- a/include/pqxx/transaction_base.hxx +++ b/include/pqxx/transaction_base.hxx @@ -44,9 +44,9 @@ class PQXX_LIBEXPORT transactionfocus : public virtual namedclass { public: explicit transactionfocus(transaction_base &t) : - namedclass("transactionfocus"), - m_trans(t), - m_registered(false) + namedclass{"transactionfocus"}, + m_trans{t}, + m_registered{false} { } @@ -243,11 +243,11 @@ public: */ result exec( const std::string &Query, - const std::string &Desc=std::string()); //[t01] + const std::string &Desc=std::string{}); //[t01] result exec( const std::stringstream &Query, - const std::string &Desc=std::string()) + const std::string &Desc=std::string{}) { return exec(Query.str(), Desc); } /// Execute query, which should zero rows of data. @@ -258,7 +258,7 @@ public: */ result exec0( const std::string &Query, - const std::string &Desc=std::string()) + const std::string &Desc=std::string{}) { return exec_n(0, Query, Desc); } /// Execute query returning a single row of data. @@ -268,7 +268,7 @@ public: * * @throw unexpected_rows If the query returned the wrong number of rows. */ - row exec1(const std::string &Query, const std::string &Desc=std::string()) + row exec1(const std::string &Query, const std::string &Desc=std::string{}) { return exec_n(1, Query, Desc).front(); } /// Execute query, expect given number of rows. @@ -280,7 +280,7 @@ public: result exec_n( size_t rows, const std::string &Query, - const std::string &Desc=std::string()); + const std::string &Desc=std::string{}); /** * @name Parameterized statements @@ -315,7 +315,8 @@ public: template result exec_params(const std::string &query, Args &&...args) { - return internal_exec_params(query, internal::params(std::forward(args)...)); + return internal_exec_params( + query, internal::params(std::forward(args)...)); } // Execute parameterised statement, expect a single-row result. @@ -389,7 +390,8 @@ public: template result exec_prepared(const std::string &statement, Args&&... args) { - return internal_exec_prepared(statement, internal::params(std::forward(args)...)); + return internal_exec_prepared( + statement, internal::params(std::forward(args)...)); } /// Execute a prepared statement, and expect a single-row result. @@ -465,7 +467,7 @@ public: * statement instead. */ PQXX_DEPRECATED prepare::invocation - prepared(const std::string &statement=std::string()); + prepared(const std::string &statement=std::string{}); //@} @@ -646,5 +648,4 @@ private: } // namespace pqxx #include "pqxx/compiler-internal-post.hxx" - #endif diff --git a/include/pqxx/transactor.hxx b/include/pqxx/transactor.hxx index 78db48c65..39ad0b23a 100644 --- a/include/pqxx/transactor.hxx +++ b/include/pqxx/transactor.hxx @@ -101,8 +101,8 @@ inline auto perform(const TRANSACTION_CALLBACK &callback, int attempts=3) -> decltype(callback()) { if (attempts <= 0) - throw std::invalid_argument( - "Zero or negative number of attempts passed to pqxx::perform()."); + throw std::invalid_argument{ + "Zero or negative number of attempts passed to pqxx::perform()."}; for (; attempts > 0; --attempts) { @@ -136,7 +136,7 @@ inline auto perform(const TRANSACTION_CALLBACK &callback, int attempts=3) continue; } } - throw pqxx::internal_error("No outcome reached on perform()."); + throw pqxx::internal_error{"No outcome reached on perform()."}; } /// @deprecated Pre-C++11 wrapper for automatically retrying transactions. @@ -160,7 +160,7 @@ public: using argument_type = TRANSACTION; PQXX_DEPRECATED explicit transactor( //[t04] const std::string &TName="transactor") : - m_name(TName) { } + m_name{TName} { } /// Overridable transaction definition; insert your database code here /** The operation will be retried if the connection to the backend is lost or @@ -237,10 +237,10 @@ inline void connection_base::perform( --Attempts; // Work on a copy of T2 so we can restore the starting situation if need be - TRANSACTOR T2(T); + TRANSACTOR T2{T}; try { - typename TRANSACTOR::argument_type X(*this, T2.name()); + typename TRANSACTOR::argument_type X{*this, T2.name()}; T2(X); X.commit(); Done = true; diff --git a/include/pqxx/util.hxx b/include/pqxx/util.hxx index ba916430d..8265d3b54 100644 --- a/include/pqxx/util.hxx +++ b/include/pqxx/util.hxx @@ -253,14 +253,14 @@ class PQXX_LIBEXPORT namedclass { public: explicit namedclass(const std::string &Classname) : - m_classname(Classname), - m_name() + m_classname{Classname}, + m_name{} { } namedclass(const std::string &Classname, const std::string &Name) : - m_classname(Classname), - m_name(Name) + m_classname{Classname}, + m_name{Name} { } diff --git a/src/array.cxx b/src/array.cxx index 768c105c5..d98c1a410 100644 --- a/src/array.cxx +++ b/src/array.cxx @@ -52,13 +52,13 @@ const char*scan_single_quoted_string(const char begin[]) // Backslash escape. Skip ahead by one more character. here++; if (*here == '\0') - throw pqxx::argument_error( - "SQL string ends in escape: " + std::string(begin)); + throw pqxx::argument_error{ + "SQL string ends in escape: " + std::string{begin}}; break; } } - throw pqxx::argument_error( - "Null byte in SQL string: " + std::string(begin)); + throw pqxx::argument_error{ + "Null byte in SQL string: " + std::string{begin}}; } @@ -104,15 +104,15 @@ const char *scan_double_quoted_string(const char begin[]) // Backslash escape. Skip ahead by one more character. here++; if (*here == '\0') - throw pqxx::argument_error( - "SQL string ends in escape: " + std::string(begin)); + throw pqxx::argument_error{ + "SQL string ends in escape: " + std::string{begin}}; break; case '"': return here + 1; } } - throw pqxx::argument_error( - "Null byte in SQL string: " + std::string(begin)); + throw pqxx::argument_error{ + "Null byte in SQL string: " + std::string{begin}}; } @@ -166,7 +166,7 @@ const char *scan_unquoted_string(const char begin[]) */ std::string parse_unquoted_string(const char begin[], const char end[]) { - return std::string(begin, end); + return std::string{begin, end}; } } // namespace diff --git a/src/binarystring.cxx b/src/binarystring.cxx index d8e0a7fb8..4bd654873 100644 --- a/src/binarystring.cxx +++ b/src/binarystring.cxx @@ -30,11 +30,11 @@ using buffer = std::pair; buffer to_buffer(const void *data, size_t len) { - void *const output(malloc(len + 1)); - if (output == nullptr) throw std::bad_alloc(); + void *const output{malloc(len + 1)}; + if (output == nullptr) throw std::bad_alloc{}; static_cast(output)[len] = '\0'; memcpy(static_cast(output), data, len); - return buffer(static_cast(output), len); + return buffer{static_cast(output), len}; } @@ -58,7 +58,7 @@ buffer unescape(const unsigned char escaped[]) PQunescapeBytea(const_cast(escaped), &unescaped_len), freepqmem_templated); void *data = A.get(); - if (data == nullptr) throw std::bad_alloc(); + if (data == nullptr) throw std::bad_alloc{}; return to_buffer(data, unescaped_len); #else /* On non-Windows platforms, it's okay to free libpq-allocated memory using @@ -67,7 +67,7 @@ buffer unescape(const unsigned char escaped[]) buffer unescaped; unescaped.first = PQunescapeBytea( const_cast(escaped), &unescaped.second); - if (unescaped.first == nullptr) throw std::bad_alloc(); + if (unescaped.first == nullptr) throw std::bad_alloc{}; return unescaped; #endif } @@ -76,26 +76,26 @@ buffer unescape(const unsigned char escaped[]) pqxx::binarystring::binarystring(const field &F) : - m_buf(make_smart_pointer()), - m_size(0) + m_buf{make_smart_pointer()}, + m_size{0} { - buffer unescaped(unescape(reinterpret_cast(F.c_str()))); + buffer unescaped{unescape(reinterpret_cast(F.c_str()))}; m_buf = make_smart_pointer(unescaped.first); m_size = unescaped.second; } pqxx::binarystring::binarystring(const std::string &s) : - m_buf(make_smart_pointer()), - m_size(s.size()) + m_buf{make_smart_pointer()}, + m_size{s.size()} { m_buf = make_smart_pointer(to_buffer(s).first); } pqxx::binarystring::binarystring(const void *binary_data, size_t len) : - m_buf(make_smart_pointer()), - m_size(len) + m_buf{make_smart_pointer()}, + m_size{len} { m_buf = make_smart_pointer(to_buffer(binary_data, len).first); } @@ -122,9 +122,10 @@ pqxx::binarystring::const_reference pqxx::binarystring::at(size_type n) const if (n >= m_size) { if (m_size == 0) - throw std::out_of_range("Accessing empty binarystring"); - throw std::out_of_range("binarystring index out of range: " + - to_string(n) + " (should be below " + to_string(m_size) + ")"); + throw std::out_of_range{"Accessing empty binarystring"}; + throw std::out_of_range{ + "binarystring index out of range: " + + to_string(n) + " (should be below " + to_string(m_size) + ")"}; } return data()[n]; } @@ -143,5 +144,5 @@ void pqxx::binarystring::swap(binarystring &rhs) std::string pqxx::binarystring::str() const { - return std::string(get(), m_size); + return std::string{get(), m_size}; } diff --git a/src/connection.cxx b/src/connection.cxx index e2d85b2a9..966c5974b 100644 --- a/src/connection.cxx +++ b/src/connection.cxx @@ -18,7 +18,7 @@ pqxx::connectionpolicy::connectionpolicy(const std::string &opts) : - m_options(opts) + m_options{opts} { } @@ -33,12 +33,12 @@ pqxx::connectionpolicy::normalconnect(handle orig) { if (orig) return orig; orig = PQconnectdb(options().c_str()); - if (orig == nullptr) throw std::bad_alloc(); + if (orig == nullptr) throw std::bad_alloc{}; if (PQstatus(orig) != CONNECTION_OK) { - const std::string msg(PQerrorMessage(orig)); + const std::string msg{PQerrorMessage(orig)}; PQfinish(orig); - throw broken_connection(msg); + throw broken_connection{msg}; } return orig; } @@ -84,9 +84,9 @@ pqxx::connect_direct::do_startconnect(handle orig) orig = normalconnect(orig); if (PQstatus(orig) != CONNECTION_OK) { - const std::string msg(PQerrorMessage(orig)); + const std::string msg{PQerrorMessage(orig)}; do_disconnect(orig); - throw broken_connection(msg); + throw broken_connection{msg}; } return orig; } @@ -100,8 +100,8 @@ pqxx::connect_lazy::do_completeconnect(handle orig) pqxx::connect_async::connect_async(const std::string &opts) : - connectionpolicy(opts), - m_connecting(false) + connectionpolicy{opts}, + m_connecting{false} { } @@ -111,11 +111,11 @@ pqxx::connect_async::do_startconnect(handle orig) if (orig != nullptr) return orig; // Already connecting or connected. m_connecting = false; orig = PQconnectStart(options().c_str()); - if (orig == nullptr) throw std::bad_alloc(); + if (orig == nullptr) throw std::bad_alloc{}; if (PQstatus(orig) == CONNECTION_BAD) { do_dropconnect(orig); - throw broken_connection(std::string(PQerrorMessage(orig))); + throw broken_connection{std::string{PQerrorMessage(orig)}}; } m_connecting = true; return orig; @@ -140,7 +140,7 @@ pqxx::connect_async::do_completeconnect(handle orig) { case PGRES_POLLING_FAILED: if (makenew) do_disconnect(orig); - throw broken_connection(std::string(PQerrorMessage(orig))); + throw broken_connection{std::string{PQerrorMessage(orig)}}; case PGRES_POLLING_READING: internal::wait_read(orig); diff --git a/src/connection_base.cxx b/src/connection_base.cxx index 35c779ded..b01bf06ae 100644 --- a/src/connection_base.cxx +++ b/src/connection_base.cxx @@ -83,10 +83,10 @@ void pqxx_notice_processor(void *conn, const char *msg) std::string pqxx::encrypt_password( const std::string &user, const std::string &password) { - std::unique_ptr p( + std::unique_ptr p{ PQencryptPassword(password.c_str(), user.c_str()), - freepqmem_templated); - return std::string(p.get()); + freepqmem_templated}; + return std::string{p.get()}; } @@ -133,9 +133,9 @@ void pqxx::connection_base::activate() if (not is_open()) { if (m_inhibit_reactivation) - throw broken_connection( + throw broken_connection{ "Could not reactivate connection; " - "reactivation is inhibited"); + "reactivation is inhibited"}; // If any objects were open that didn't survive the closing of our // connection, don't try to reactivate @@ -147,7 +147,7 @@ void pqxx::connection_base::activate() m_conn = m_policy.do_completeconnect(m_conn); m_completed = true; // (But retracted if error is thrown below) - if (not is_open()) throw broken_connection(); + if (not is_open()) throw broken_connection{}; set_up_state(); } @@ -155,7 +155,7 @@ void pqxx::connection_base::activate() { disconnect(); m_completed = false; - throw broken_connection(e.what()); + throw broken_connection{e.what()}; } catch (const std::exception &) { @@ -171,9 +171,9 @@ void pqxx::connection_base::deactivate() if (m_conn == nullptr) return; if (m_trans.get()) - throw usage_error( + throw usage_error{ "Attempt to deactivate connection while " + - m_trans.get()->description() + " still open"); + m_trans.get()->description() + " still open"}; if (m_reactivation_avoidance.get()) { @@ -241,7 +241,7 @@ std::string pqxx::connection_base::raw_get_var(const std::string &Var) const auto i = m_vars.find(Var); if (i != m_vars.end()) return i->second; - return exec(("SHOW " + Var).c_str(), 0).at(0).at(0).as(std::string()); + return exec(("SHOW " + Var).c_str(), 0).at(0).at(0).as(std::string{}); } @@ -258,13 +258,13 @@ void pqxx::connection_base::clearcaps() noexcept void pqxx::connection_base::set_up_state() { if (m_conn == nullptr) - throw internal_error("set_up_state() on no connection"); + throw internal_error{"set_up_state() on no connection"}; if (status() != CONNECTION_OK) { const auto msg = err_msg(); m_conn = m_policy.do_disconnect(m_conn); - throw failure(msg); + throw failure{msg}; } read_capabilities(); @@ -310,18 +310,18 @@ void pqxx::connection_base::set_up_state() } m_completed = true; - if (not is_open()) throw broken_connection(); + if (not is_open()) throw broken_connection{}; } void pqxx::connection_base::check_result(const result &R) { - if (not is_open()) throw broken_connection(); + if (not is_open()) throw broken_connection{}; // A shame we can't quite detect out-of-memory to turn this into a bad_alloc! - if (not gate::result_connection(R)) throw failure(err_msg()); + if (not gate::result_connection{R}) throw failure(err_msg()); - gate::result_creation(R).check_status(); + gate::result_creation{R}.check_status(); } @@ -362,7 +362,7 @@ void pqxx::connection_base::process_notice(const char msg[]) noexcept else try { // Newline is missing. Try the C++ string version of this function. - process_notice(std::string(msg)); + process_notice(std::string{msg}); } catch (const std::exception &) { @@ -420,7 +420,7 @@ void pqxx::connection_base::trace(FILE *Out) noexcept void pqxx::connection_base::add_receiver(pqxx::notification_receiver *T) { - if (T == nullptr) throw argument_error("Null receiver registered"); + if (T == nullptr) throw argument_error{"Null receiver registered"}; // Add to receiver list and attempt to start listening. const auto p = m_receivers.find(T->channel()); @@ -454,8 +454,8 @@ void pqxx::connection_base::remove_receiver(pqxx::notification_receiver *T) try { - const std::pair needle( - T->channel(), T); + const std::pair needle{ + T->channel(), T}; auto R = m_receivers.equal_range(needle.first); const auto i = find(R.first, R.second, needle); @@ -502,13 +502,13 @@ class cancel_wrapper public: explicit cancel_wrapper(PGconn *conn) : - m_cancel(nullptr), - m_errbuf() + m_cancel{nullptr}, + m_errbuf{} { if (conn) { m_cancel = PQgetCancel(conn); - if (m_cancel == nullptr) throw std::bad_alloc(); + if (m_cancel == nullptr) throw std::bad_alloc{}; } } ~cancel_wrapper() { if (m_cancel) PQfreeCancel(m_cancel); } @@ -516,8 +516,8 @@ class cancel_wrapper void operator()() { if (not m_cancel) return; - if (PQcancel(m_cancel, m_errbuf, int(sizeof(m_errbuf))) == 0) - throw sql_error(std::string(m_errbuf)); + if (PQcancel(m_cancel, m_errbuf, int{sizeof(m_errbuf)}) == 0) + throw sql_error{std::string{m_errbuf}}; } }; } @@ -525,7 +525,7 @@ class cancel_wrapper void pqxx::connection_base::cancel_query() { - cancel_wrapper cancel(m_conn); + cancel_wrapper cancel{m_conn}; cancel(); } @@ -555,7 +555,7 @@ int pqxx::connection_base::get_notifs() { if (not is_open()) return 0; - if (not consume_input()) throw broken_connection(); + if (not consume_input()) throw broken_connection{}; // Even if somehow we receive notifications during our transaction, don't // deliver them. @@ -566,7 +566,7 @@ int pqxx::connection_base::get_notifs() { notifs++; - const auto Hit = m_receivers.equal_range(std::string(N->relname)); + const auto Hit = m_receivers.equal_range(std::string{N->relname}); for (auto i = Hit.first; i != Hit.second; ++i) try { (*i->second)(N->extra, N->be_pid); @@ -662,8 +662,8 @@ void pqxx::connection_base::unregister_errorhandler(errorhandler *handler) std::vector pqxx::connection_base::get_errorhandlers() const { - return std::vector( - std::begin(m_errorhandlers), std::end(m_errorhandlers)); + return std::vector{ + std::begin(m_errorhandlers), std::end(m_errorhandlers)}; } @@ -675,7 +675,7 @@ pqxx::result pqxx::connection_base::exec(const char Query[], int Retries) auto R = make_result(PQexec(m_conn, Query), Query); - while ((Retries > 0) and not gate::result_connection(R) and not is_open()) + while ((Retries > 0) and not gate::result_connection{R} and not is_open()) { Retries--; reset(); @@ -699,8 +699,8 @@ void pqxx::connection_base::prepare( if (definition != i->second.definition) { if (not name.empty()) - throw argument_error( - "Inconsistent redefinition of prepared statement " + name); + throw argument_error{ + "Inconsistent redefinition of prepared statement " + name}; i->second.registered = false; i->second.definition = definition; @@ -710,14 +710,14 @@ void pqxx::connection_base::prepare( { m_prepared.insert(make_pair( name, - prepare::internal::prepared_def(definition))); + prepare::internal::prepared_def{definition})); } } void pqxx::connection_base::prepare(const std::string &definition) { - this->prepare(std::string(), definition); + this->prepare(std::string{}, definition); } @@ -740,7 +740,7 @@ pqxx::connection_base::find_prepared(const std::string &statement) { auto s = m_prepared.find(statement); if (s == m_prepared.end()) - throw argument_error("Unknown prepared statement '" + statement + "'"); + throw argument_error{"Unknown prepared statement '" + statement + "'"}; return s->second; } @@ -835,8 +835,8 @@ bool pqxx::connection_base::prepared_exists(const std::string &statement) const void pqxx::connection_base::reset() { if (m_inhibit_reactivation) - throw broken_connection( - "Could not reset connection: reactivation is inhibited"); + throw broken_connection{ + "Could not reset connection: reactivation is inhibited"}; if (m_reactivation_avoidance.get()) return; // TODO: Probably need to go through a full disconnect/reconnect! @@ -887,7 +887,7 @@ void pqxx::connection_base::close() noexcept rbegin = old_handlers.rbegin(), rend = old_handlers.rend(); for (auto i = rbegin; i!=rend; ++i) - gate::errorhandler_connection_base(**i).unregister(); + gate::errorhandler_connection_base{**i}.unregister(); m_conn = m_policy.do_disconnect(m_conn); } @@ -951,7 +951,7 @@ void pqxx::connection_base::unregister_transaction(transaction_base *T) bool pqxx::connection_base::read_copy_line(std::string &Line) { if (not is_open()) - throw internal_error("read_copy_line() without connection"); + throw internal_error{"read_copy_line() without connection"}; Line.erase(); bool Result; @@ -962,7 +962,7 @@ bool pqxx::connection_base::read_copy_line(std::string &Line) switch (line_len) { case -2: - throw failure("Reading of table data failed: " + std::string(err_msg())); + throw failure{"Reading of table data failed: " + std::string{err_msg()}}; case -1: for ( @@ -975,7 +975,7 @@ bool pqxx::connection_base::read_copy_line(std::string &Line) break; case 0: - throw internal_error("table read inexplicably went asynchronous"); + throw internal_error{"table read inexplicably went asynchronous"}; default: if (Buf) @@ -994,7 +994,7 @@ bool pqxx::connection_base::read_copy_line(std::string &Line) void pqxx::connection_base::write_copy_line(const std::string &Line) { if (not is_open()) - throw internal_error("write_copy_line() without connection"); + throw internal_error{"write_copy_line() without connection"}; const std::string L = Line + '\n'; const char *const LC = L.c_str(); @@ -1003,9 +1003,9 @@ void pqxx::connection_base::write_copy_line(const std::string &Line) if (PQputCopyData(m_conn, LC, int(Len)) <= 0) { const std::string msg = ( - std::string("Error writing to table: ") + err_msg()); + std::string{"Error writing to table: "} + err_msg()); PQendcopy(m_conn); - throw failure(msg); + throw failure{msg}; } } @@ -1016,16 +1016,16 @@ void pqxx::connection_base::end_copy_write() switch (Res) { case -1: - throw failure("Write to table failed: " + std::string(err_msg())); + throw failure{"Write to table failed: " + std::string{err_msg()}}; case 0: - throw internal_error("table write is inexplicably asynchronous"); + throw internal_error{"table write is inexplicably asynchronous"}; case 1: // Normal termination. Retrieve result object. break; default: - throw internal_error( - "unexpected result " + to_string(Res) + " from PQputCopyEnd()"); + throw internal_error{ + "unexpected result " + to_string(Res) + " from PQputCopyEnd()"}; } check_result(make_result(PQgetResult(m_conn), "[END COPY]")); @@ -1037,13 +1037,13 @@ void pqxx::connection_base::start_exec(const std::string &Q) #include activate(); #include - if (PQsendQuery(m_conn, Q.c_str()) == 0) throw failure(err_msg()); + if (PQsendQuery(m_conn, Q.c_str()) == 0) throw failure{err_msg()}; } pqxx::internal::pq::PGresult *pqxx::connection_base::get_result() { - if (m_conn == nullptr) throw broken_connection(); + if (m_conn == nullptr) throw broken_connection{}; return PQgetResult(m_conn); } @@ -1065,8 +1065,8 @@ std::string pqxx::connection_base::esc(const char str[], size_t maxlen) std::vector buf(2 * maxlen + 1); int err = 0; PQescapeStringConn(m_conn, buf.data(), str, maxlen, &err); - if (err) throw argument_error(err_msg()); - return std::string(buf.data()); + if (err) throw argument_error{err_msg()}; + return std::string{buf.data()}; } @@ -1093,11 +1093,11 @@ std::string pqxx::connection_base::esc_raw( activate(); #include - std::unique_ptr buf( + std::unique_ptr buf{ PQescapeByteaConn(m_conn, str, len, &bytes), - freepqmem_templated); - if (buf.get() == nullptr) throw std::bad_alloc(); - return std::string(reinterpret_cast(buf.get())); + freepqmem_templated}; + if (buf.get() == nullptr) throw std::bad_alloc{}; + return std::string{reinterpret_cast(buf.get())}; } @@ -1107,7 +1107,7 @@ std::string pqxx::connection_base::unesc_raw(const char *text) unsigned char *bytes = const_cast( reinterpret_cast(text)); const unsigned char *const buf = PQunescapeBytea(bytes, &len); - return std::string(buf, buf + len); + return std::string{buf, buf + len}; } @@ -1132,22 +1132,22 @@ std::string pqxx::connection_base::quote_name(const std::string &identifier) #include activate(); #include - std::unique_ptr buf( + std::unique_ptr buf{ PQescapeIdentifier(m_conn, identifier.c_str(), identifier.size()), - freepqmem_templated); - if (buf.get() == nullptr) throw failure(err_msg()); - return std::string(buf.get()); + freepqmem_templated}; + if (buf.get() == nullptr) throw failure{err_msg()}; + return std::string{buf.get()}; } pqxx::internal::reactivation_avoidance_exemption:: reactivation_avoidance_exemption( connection_base &C) : - m_home(C), - m_count(gate::connection_reactivation_avoidance_exemption(C).get_counter()), - m_open(C.is_open()) + m_home{C}, + m_count{gate::connection_reactivation_avoidance_exemption(C).get_counter()}, + m_open{C.is_open()} { - gate::connection_reactivation_avoidance_exemption gate(C); + gate::connection_reactivation_avoidance_exemption gate{C}; gate.clear_counter(); } @@ -1163,7 +1163,7 @@ pqxx::internal::reactivation_avoidance_exemption:: m_home.deactivate(); #include "pqxx/internal/ignore-deprecated-post.hxx" } - gate::connection_reactivation_avoidance_exemption gate(m_home); + gate::connection_reactivation_avoidance_exemption gate{m_home}; gate.add_counter(m_count); } @@ -1174,7 +1174,7 @@ namespace // Convert a timeval to milliseconds, or -1 if no timeval is given. inline int tv_milliseconds(timeval *tv = nullptr) { - return tv ? int(tv->tv_sec * 1000 + tv->tv_usec/1000) : -1; + return tv ? int{tv->tv_sec * 1000 + tv->tv_usec/1000} : -1; } #endif @@ -1182,7 +1182,7 @@ inline int tv_milliseconds(timeval *tv = nullptr) /// Wait for an fd to become free for reading/writing. Optional timeout. void wait_fd(int fd, bool forwrite=false, timeval *tv=nullptr) { - if (fd < 0) throw pqxx::broken_connection(); + if (fd < 0) throw pqxx::broken_connection{}; // WSAPoll is available in winsock2.h only for versions of Windows >= 0x0600 #if defined(_WIN32) && (_WIN32_WINNT >= 0x0600) @@ -1190,8 +1190,8 @@ void wait_fd(int fd, bool forwrite=false, timeval *tv=nullptr) WSAPOLLFD fdarray{SOCKET(fd), events, 0}; WSAPoll(&fdarray, 1, tv_milliseconds(tv)); #elif defined(HAVE_POLL) - const short events = short( - POLLERR|POLLHUP|POLLNVAL | (forwrite?POLLOUT:POLLIN)); + const short events = short{ + POLLERR|POLLHUP|POLLNVAL | (forwrite?POLLOUT:POLLIN)}; pollfd pfd{fd, events, 0}; poll(&pfd, 1, tv_milliseconds(tv)); #else @@ -1295,16 +1295,16 @@ void pqxx::connection_base::read_capabilities() { m_serverversion = PQserverVersion(m_conn); if (m_serverversion <= 90000) - throw feature_not_supported( - "Unsupported server version; 9.0 is the minimum."); + throw feature_not_supported{ + "Unsupported server version; 9.0 is the minimum."}; switch (protocol_version()) { case 0: - throw broken_connection(); + throw broken_connection{}; case 1: case 2: - throw feature_not_supported( - "Unsupported frontend/backend protocol version; 3.0 is the minimum."); + throw feature_not_supported{ + "Unsupported frontend/backend protocol version; 3.0 is the minimum."}; default: break; } diff --git a/src/cursor.cxx b/src/cursor.cxx index e447f4b59..6e9aa3184 100644 --- a/src/cursor.cxx +++ b/src/cursor.cxx @@ -65,13 +65,13 @@ pqxx::internal::sql_cursor::sql_cursor( cursor_base::updatepolicy up, cursor_base::ownershippolicy op, bool hold) : - cursor_base(t.conn(), cname), - m_home(t.conn()), - m_adopted(false), - m_at_end(-1), - m_pos(0) + cursor_base{t.conn(), cname}, + m_home{t.conn()}, + m_adopted{false}, + m_at_end{-1}, + m_pos{0} { - if (&t.conn() != &m_home) throw internal_error("Cursor in wrong connection"); + if (&t.conn() != &m_home) throw internal_error{"Cursor in wrong connection"}; std::stringstream cq, qn; /* Strip trailing semicolons (and whitespace, as side effect) off query. The @@ -84,7 +84,7 @@ pqxx::internal::sql_cursor::sql_cursor( // TODO: May break on multibyte encodings! for (--last; last!=std::begin(query) and useless_trail(*last); --last) ; if (last==std::begin(query) and useless_trail(*last)) - throw argument_error("Cursor created on empty query"); + throw argument_error{"Cursor created on empty query."}; ++last; cq << "DECLARE " << t.quote_name(name()) << " "; @@ -100,7 +100,7 @@ pqxx::internal::sql_cursor::sql_cursor( if (hold) cq << "WITH HOLD "; - cq << "FOR " << std::string(std::begin(query),last) << ' '; + cq << "FOR " << std::string{std::begin(query),last} << ' '; if (up != cursor_base::update) cq << "FOR READ ONLY "; else cq << "FOR UPDATE "; @@ -118,7 +118,7 @@ pqxx::internal::sql_cursor::sql_cursor( // after this transaction. That means the connection cannot be deactivated // without losing the cursor. if (hold) - gate::connection_sql_cursor(t.conn()).add_reactivation_avoidance_count(1); + gate::connection_sql_cursor{t.conn()}.add_reactivation_avoidance_count(1); m_ownership = op; } @@ -128,18 +128,18 @@ pqxx::internal::sql_cursor::sql_cursor( transaction_base &t, const std::string &cname, cursor_base::ownershippolicy op) : - cursor_base(t.conn(), cname, false), - m_home(t.conn()), - m_empty_result(), - m_adopted(true), - m_at_end(0), - m_pos(-1) + cursor_base{t.conn(), cname, false}, + m_home{t.conn()}, + m_empty_result{}, + m_adopted{true}, + m_at_end{0}, + m_pos{-1} { // If we take responsibility for destroying the cursor, that's one less // reason not to allow the connection to be deactivated and reactivated. // TODO: Go over lifetime/reactivation rules again to be sure they work if (op==cursor_base::owned) - gate::connection_sql_cursor(t.conn()).add_reactivation_avoidance_count(-1); + gate::connection_sql_cursor{t.conn()}.add_reactivation_avoidance_count(-1); m_adopted = true; m_ownership = op; } @@ -151,7 +151,7 @@ void pqxx::internal::sql_cursor::close() noexcept { try { - gate::connection_sql_cursor(m_home).exec( + gate::connection_sql_cursor{m_home}.exec( ("CLOSE " + m_home.quote_name(name())).c_str(), 0); } @@ -160,7 +160,7 @@ void pqxx::internal::sql_cursor::close() noexcept } if (m_adopted) - gate::connection_sql_cursor(m_home).add_reactivation_avoidance_count(-1); + gate::connection_sql_cursor{m_home}.add_reactivation_avoidance_count(-1); m_ownership = cursor_base::loose; } @@ -169,7 +169,7 @@ void pqxx::internal::sql_cursor::close() noexcept void pqxx::internal::sql_cursor::init_empty_result(transaction_base &t) { - if (pos() != 0) throw internal_error("init_empty_result() from bad pos()"); + if (pos() != 0) throw internal_error{"init_empty_result() from bad pos()."}; m_empty_result = t.exec("FETCH 0 IN " + m_home.quote_name(name())); } @@ -179,14 +179,14 @@ internal::sql_cursor::difference_type pqxx::internal::sql_cursor::adjust(difference_type hoped, difference_type actual) { - if (actual < 0) throw internal_error("Negative rows in cursor movement"); + if (actual < 0) throw internal_error{"Negative rows in cursor movement."}; if (hoped == 0) return 0; const int direction = ((hoped < 0) ? -1 : 1); bool hit_end = false; if (actual != labs(hoped)) { if (actual > labs(hoped)) - throw internal_error("Cursor displacement larger than requested"); + throw internal_error{"Cursor displacement larger than requested."}; // If we see fewer rows than requested, then we've hit an end (on either // side) of the result set. Wether we make an extra step to a one-past-end @@ -202,12 +202,12 @@ pqxx::internal::sql_cursor::adjust(difference_type hoped, if (direction > 0) hit_end = true; else if (m_pos == -1) m_pos = actual; else if (m_pos != actual) - throw internal_error( + throw internal_error{ "Moved back to beginning, but wrong position: " "hoped=" + to_string(hoped) + ", " "actual=" + to_string(actual) + ", " "m_pos=" + to_string(m_pos) + ", " - "direction=" + to_string(direction)); + "direction=" + to_string(direction) + "."}; m_at_end = direction; } @@ -220,7 +220,7 @@ pqxx::internal::sql_cursor::adjust(difference_type hoped, if (hit_end) { if (m_endpos >= 0 and m_pos != m_endpos) - throw internal_error("Inconsistent cursor end positions"); + throw internal_error{"Inconsistent cursor end positions."}; m_endpos = m_pos; } return direction*actual; @@ -238,7 +238,7 @@ result pqxx::internal::sql_cursor::fetch( } const std::string query = "FETCH " + stridestring(rows) + " IN " + m_home.quote_name(name()); - const result r(gate::connection_sql_cursor(m_home).exec(query.c_str(), 0)); + const result r{gate::connection_sql_cursor{m_home}.exec(query.c_str(), 0)}; displacement = adjust(rows, difference_type(r.size())); return r; } @@ -256,7 +256,7 @@ cursor_base::difference_type pqxx::internal::sql_cursor::move( const std::string query = "MOVE " + stridestring(rows) + " IN " + m_home.quote_name(name()); - const result r(gate::connection_sql_cursor(m_home).exec(query.c_str(), 0)); + const result r(gate::connection_sql_cursor{m_home}.exec(query.c_str(), 0)); difference_type d = difference_type(r.affected_rows()); displacement = adjust(rows, d); return d; @@ -272,7 +272,7 @@ std::string pqxx::internal::sql_cursor::stridestring(difference_type n) * We could change the alias to match this behaviour, but that would break * if/when Postgres is changed to accept 64-bit displacements. */ - static const std::string All("ALL"), BackAll("BACKWARD ALL"); + static const std::string All{"ALL"}, BackAll{"BACKWARD ALL"}; if (n >= cursor_base::all()) return All; else if (n <= cursor_base::backward_all()) return BackAll; return to_string(n); @@ -283,7 +283,7 @@ pqxx::cursor_base::cursor_base( connection_base &context, const std::string &Name, bool embellish_name) : - m_name(embellish_name ? context.adorn_name(Name) : Name) + m_name{embellish_name ? context.adorn_name(Name) : Name} { } @@ -302,7 +302,7 @@ result pqxx::internal::stateless_cursor_retrieve( result::difference_type end_pos) { if (begin_pos < 0 or begin_pos > size) - throw range_error("Starting position out of range"); + throw range_error{"Starting position out of range"}; if (end_pos < -1) end_pos = -1; else if (end_pos > size) end_pos = size; @@ -320,18 +320,18 @@ pqxx::icursorstream::icursorstream( const std::string &query, const std::string &basename, difference_type sstride) : - m_cur(context, + m_cur{context, query, basename, cursor_base::forward_only, cursor_base::read_only, cursor_base::owned, - false), - m_stride(sstride), - m_realpos(0), - m_reqpos(0), - m_iterators(nullptr), - m_done(false) + false}, + m_stride{sstride}, + m_realpos{0}, + m_reqpos{0}, + m_iterators{nullptr}, + m_done{false} { set_stride(sstride); } @@ -342,12 +342,12 @@ pqxx::icursorstream::icursorstream( const field &cname, difference_type sstride, cursor_base::ownershippolicy op) : - m_cur(context, cname.c_str(), op), - m_stride(sstride), - m_realpos(0), - m_reqpos(0), - m_iterators(nullptr), - m_done(false) + m_cur{context, cname.c_str(), op}, + m_stride{sstride}, + m_realpos{0}, + m_reqpos{0}, + m_iterators{nullptr}, + m_done{false} { set_stride(sstride); } @@ -356,13 +356,13 @@ pqxx::icursorstream::icursorstream( void pqxx::icursorstream::set_stride(difference_type n) { if (n < 1) - throw argument_error("Attempt to set cursor stride to " + to_string(n)); + throw argument_error{"Attempt to set cursor stride to " + to_string(n)}; m_stride = n; } result pqxx::icursorstream::fetchblock() { - const result r(m_cur.fetch(m_stride)); + const result r{m_cur.fetch(m_stride)}; m_realpos += r.size(); if (r.empty()) m_done = true; return r; @@ -387,27 +387,27 @@ icursorstream::size_type pqxx::icursorstream::forward(size_type n) void pqxx::icursorstream::insert_iterator(icursor_iterator *i) noexcept { - gate::icursor_iterator_icursorstream(*i).set_next(m_iterators); + gate::icursor_iterator_icursorstream{*i}.set_next(m_iterators); if (m_iterators) - gate::icursor_iterator_icursorstream(*m_iterators).set_prev(i); + gate::icursor_iterator_icursorstream{*m_iterators}.set_prev(i); m_iterators = i; } void pqxx::icursorstream::remove_iterator(icursor_iterator *i) const noexcept { - gate::icursor_iterator_icursorstream igate(*i); + gate::icursor_iterator_icursorstream igate{*i}; if (i == m_iterators) { m_iterators = igate.get_next(); if (m_iterators) - gate::icursor_iterator_icursorstream(*m_iterators).set_prev(nullptr); + gate::icursor_iterator_icursorstream{*m_iterators}.set_prev(nullptr); } else { auto prev = igate.get_prev(), next = igate.get_next(); - gate::icursor_iterator_icursorstream(*prev).set_next(next); - if (next) gate::icursor_iterator_icursorstream(*next).set_prev(prev); + gate::icursor_iterator_icursorstream{*prev}.set_next(next); + if (next) gate::icursor_iterator_icursorstream{*next}.set_prev(prev); } igate.set_prev(nullptr); igate.set_next(nullptr); @@ -422,7 +422,7 @@ void pqxx::icursorstream::service_iterators(difference_type topos) todolist todo; for (icursor_iterator *i = m_iterators, *next; i; i = next) { - gate::icursor_iterator_icursorstream gate(*i); + gate::icursor_iterator_icursorstream gate{*i}; const auto ipos = gate.pos(); if (ipos >= m_realpos and ipos <= topos) todo.insert(todolist::value_type(ipos, i)); @@ -435,48 +435,48 @@ void pqxx::icursorstream::service_iterators(difference_type topos) if (readpos > m_realpos) ignore(readpos - m_realpos); const result r = fetchblock(); for ( ; i != todo_end and i->first == readpos; ++i) - gate::icursor_iterator_icursorstream(*i->second).fill(r); + gate::icursor_iterator_icursorstream{*i->second}.fill(r); } } pqxx::icursor_iterator::icursor_iterator() noexcept : - m_pos(0) + m_pos{0} { } pqxx::icursor_iterator::icursor_iterator(istream_type &s) noexcept : - m_stream(&s), - m_pos(difference_type(gate::icursorstream_icursor_iterator(s).forward(0))) + m_stream{&s}, + m_pos{difference_type(gate::icursorstream_icursor_iterator(s).forward(0))} { - gate::icursorstream_icursor_iterator(*m_stream).insert_iterator(this); + gate::icursorstream_icursor_iterator{*m_stream}.insert_iterator(this); } pqxx::icursor_iterator::icursor_iterator(const icursor_iterator &rhs) noexcept : - m_stream(rhs.m_stream), - m_here(rhs.m_here), - m_pos(rhs.m_pos) + m_stream{rhs.m_stream}, + m_here{rhs.m_here}, + m_pos{rhs.m_pos} { if (m_stream) - gate::icursorstream_icursor_iterator(*m_stream).insert_iterator(this); + gate::icursorstream_icursor_iterator{*m_stream}.insert_iterator(this); } pqxx::icursor_iterator::~icursor_iterator() noexcept { if (m_stream) - gate::icursorstream_icursor_iterator(*m_stream).remove_iterator(this); + gate::icursorstream_icursor_iterator{*m_stream}.remove_iterator(this); } icursor_iterator pqxx::icursor_iterator::operator++(int) { - icursor_iterator old(*this); + icursor_iterator old{*this}; m_pos = difference_type( - gate::icursorstream_icursor_iterator(*m_stream).forward()); + gate::icursorstream_icursor_iterator{*m_stream}.forward()); m_here.clear(); return old; } @@ -485,7 +485,7 @@ icursor_iterator pqxx::icursor_iterator::operator++(int) icursor_iterator &pqxx::icursor_iterator::operator++() { m_pos = difference_type( - gate::icursorstream_icursor_iterator(*m_stream).forward()); + gate::icursorstream_icursor_iterator{*m_stream}.forward()); m_here.clear(); return *this; } @@ -496,10 +496,10 @@ icursor_iterator &pqxx::icursor_iterator::operator+=(difference_type n) if (n <= 0) { if (n == 0) return *this; - throw argument_error("Advancing icursor_iterator by negative offset"); + throw argument_error{"Advancing icursor_iterator by negative offset."}; } m_pos = difference_type( - gate::icursorstream_icursor_iterator(*m_stream).forward( + gate::icursorstream_icursor_iterator{*m_stream}.forward( icursorstream::size_type(n))); m_here.clear(); return *this; @@ -517,12 +517,12 @@ pqxx::icursor_iterator::operator=(const icursor_iterator &rhs) noexcept else { if (m_stream) - gate::icursorstream_icursor_iterator(*m_stream).remove_iterator(this); + gate::icursorstream_icursor_iterator{*m_stream}.remove_iterator(this); m_here = rhs.m_here; m_pos = rhs.m_pos; m_stream = rhs.m_stream; if (m_stream) - gate::icursorstream_icursor_iterator(*m_stream).insert_iterator(this); + gate::icursorstream_icursor_iterator{*m_stream}.insert_iterator(this); } return *this; } @@ -550,7 +550,7 @@ bool pqxx::icursor_iterator::operator<(const icursor_iterator &rhs) const void pqxx::icursor_iterator::refresh() const { if (m_stream) - gate::icursorstream_icursor_iterator(*m_stream).service_iterators(pos()); + gate::icursorstream_icursor_iterator{*m_stream}.service_iterators(pos()); } diff --git a/src/dbtransaction.cxx b/src/dbtransaction.cxx index 8c97d8c0a..18d9e8c9d 100644 --- a/src/dbtransaction.cxx +++ b/src/dbtransaction.cxx @@ -21,7 +21,7 @@ namespace { std::string generate_set_transaction( pqxx::readwrite_policy rw, - const std::string &IsolationString=std::string()) + const std::string &IsolationString=std::string{}) { std::string args; @@ -35,7 +35,7 @@ std::string generate_set_transaction( pqxx::internal::sql_begin_work : ( - std::string(pqxx::internal::sql_begin_work) + + std::string{pqxx::internal::sql_begin_work} + "; SET TRANSACTION" + args ); @@ -47,8 +47,8 @@ pqxx::dbtransaction::dbtransaction( connection_base &C, const std::string &IsolationString, readwrite_policy rw) : - namedclass("dbtransaction"), - transaction_base(C), + namedclass{"dbtransaction"}, + transaction_base{C}, m_start_cmd(generate_set_transaction(rw, IsolationString)) { } @@ -58,9 +58,9 @@ pqxx::dbtransaction::dbtransaction( connection_base &C, bool direct, readwrite_policy rw) : - namedclass("dbtransaction"), - transaction_base(C, direct), - m_start_cmd(generate_set_transaction(rw)) + namedclass{"dbtransaction"}, + transaction_base{C, direct}, + m_start_cmd{generate_set_transaction(rw)} { } diff --git a/src/errorhandler.cxx b/src/errorhandler.cxx index 62fde3f41..81f1862d7 100644 --- a/src/errorhandler.cxx +++ b/src/errorhandler.cxx @@ -2,7 +2,7 @@ * * pqxx::errorhandler allows programs to receive errors and warnings. * - * Copyright (c) 2011-2017, Jeroen T. Vermeulen. + * Copyright (c) 2011-2018, Jeroen T. Vermeulen. * * See COPYING for copyright license. If you did not receive a file called * COPYING with this source code, please notify the distributor of this mistake, @@ -21,9 +21,9 @@ using namespace pqxx::internal; pqxx::errorhandler::errorhandler(connection_base &conn) : - m_home(&conn) + m_home{&conn} { - gate::connection_errorhandler(*m_home).register_errorhandler(this); + gate::connection_errorhandler{*m_home}.register_errorhandler(this); } @@ -37,7 +37,7 @@ void pqxx::errorhandler::unregister() noexcept { if (m_home) { - gate::connection_errorhandler connection_gate(*m_home); + gate::connection_errorhandler connection_gate{*m_home}; m_home = nullptr; connection_gate.unregister_errorhandler(this); } diff --git a/src/except.cxx b/src/except.cxx index 4f88f1f24..a08b1ccfd 100644 --- a/src/except.cxx +++ b/src/except.cxx @@ -17,19 +17,19 @@ pqxx::pqxx_exception::~pqxx_exception() noexcept pqxx::failure::failure(const std::string &whatarg) : - std::runtime_error(whatarg) + std::runtime_error{whatarg} { } pqxx::broken_connection::broken_connection() : - failure("Connection to database failed") + failure{"Connection to database failed"} { } pqxx::broken_connection::broken_connection(const std::string &whatarg) : - failure(whatarg) + failure{whatarg} { } @@ -38,9 +38,9 @@ pqxx::sql_error::sql_error( const std::string &whatarg, const std::string &Q, const char sqlstate[]) : - failure(whatarg), - m_query(Q), - m_sqlstate(sqlstate ? sqlstate : "") + failure{whatarg}, + m_query{Q}, + m_sqlstate{sqlstate ? sqlstate : ""} { } @@ -63,62 +63,62 @@ PQXX_PURE const std::string &pqxx::sql_error::sqlstate() const noexcept pqxx::in_doubt_error::in_doubt_error(const std::string &whatarg) : - failure(whatarg) + failure{whatarg} { } pqxx::transaction_rollback::transaction_rollback(const std::string &whatarg) : - failure(whatarg) + failure{whatarg} { } pqxx::serialization_failure::serialization_failure( const std::string &whatarg) : - transaction_rollback(whatarg) + transaction_rollback{whatarg} { } pqxx::statement_completion_unknown::statement_completion_unknown( const std::string &whatarg) : - transaction_rollback(whatarg) + transaction_rollback{whatarg} { } pqxx::deadlock_detected::deadlock_detected(const std::string &whatarg) : - transaction_rollback(whatarg) + transaction_rollback{whatarg} { } pqxx::internal_error::internal_error(const std::string &whatarg) : - logic_error("libpqxx internal error: " + whatarg) + logic_error{"libpqxx internal error: " + whatarg} { } pqxx::usage_error::usage_error(const std::string &whatarg) : - logic_error(whatarg) + logic_error{whatarg} { } pqxx::argument_error::argument_error(const std::string &whatarg) : - invalid_argument(whatarg) + invalid_argument{whatarg} { } pqxx::conversion_error::conversion_error(const std::string &whatarg) : - domain_error(whatarg) + domain_error{whatarg} { } pqxx::range_error::range_error(const std::string &whatarg) : - out_of_range(whatarg) + out_of_range{whatarg} { } diff --git a/src/field.cxx b/src/field.cxx index 2afd84d81..ae342ab18 100644 --- a/src/field.cxx +++ b/src/field.cxx @@ -2,7 +2,7 @@ * * pqxx::field refers to a field in a query result. * - * Copyright (c) 2001-2017, Jeroen T. Vermeulen. + * Copyright (c) 2001-2018, Jeroen T. Vermeulen. * * See COPYING for copyright license. If you did not receive a file called * COPYING with this source code, please notify the distributor of this mistake, @@ -16,9 +16,9 @@ pqxx::field::field(const pqxx::row &R, pqxx::row::size_type C) noexcept : - m_col(C), - m_home(R.m_result), - m_row(pqxx::result_size_type(R.m_index)) + m_col{C}, + m_home{R.m_result}, + m_row{pqxx::result_size_type(R.m_index)} { } @@ -29,7 +29,7 @@ bool pqxx::field::operator==(const field &rhs) const // TODO: Verify null handling decision const size_type s = size(); if (s != rhs.size()) return false; - const char *const l(c_str()), *const r(rhs.c_str()); + const char *const l{c_str()}, *const r{rhs.c_str()}; for (size_type i = 0; i < s; ++i) if (l[i] != r[i]) return false; return true; } diff --git a/src/largeobject.cxx b/src/largeobject.cxx index 639c6759e..17d20813f 100644 --- a/src/largeobject.cxx +++ b/src/largeobject.cxx @@ -2,7 +2,7 @@ * * Allows direct access to large objects, as well as though I/O streams. * - * Copyright (c) 2003-2017, Jeroen T. Vermeulen. + * Copyright (c) 2003-2018, Jeroen T. Vermeulen. * * See COPYING for copyright license. If you did not receive a file called * COPYING with this source code, please notify the distributor of this mistake, @@ -66,36 +66,36 @@ inline int StdDirToPQDir(std::ios::seekdir dir) noexcept pqxx::largeobject::largeobject(dbtransaction &T) : - m_id() + m_id{} { // (Mode is ignored as of postgres 8.1.) m_id = lo_creat(raw_connection(T), 0); if (m_id == oid_none) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure("Could not create large object: " + reason(T.conn(), err)); + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{"Could not create large object: " + reason(T.conn(), err)}; } } pqxx::largeobject::largeobject(dbtransaction &T, const std::string &File) : - m_id() + m_id{} { m_id = lo_import(raw_connection(T), File.c_str()); if (m_id == oid_none) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure( + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{ "Could not import file '" + File + "' to large object: " + - reason(T.conn(), err)); + reason(T.conn(), err)}; } } pqxx::largeobject::largeobject(const largeobjectaccess &O) noexcept : - m_id(O.id()) + m_id{O.id()} { } @@ -107,10 +107,10 @@ void pqxx::largeobject::to_file( if (lo_export(raw_connection(T), id(), File.c_str()) == -1) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure( + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{ "Could not export large object " + to_string(m_id) + " " - "to file '" + File + "': " + reason(T.conn(), err)); + "to file '" + File + "': " + reason(T.conn(), err)}; } } @@ -120,10 +120,10 @@ void pqxx::largeobject::remove(dbtransaction &T) const if (lo_unlink(raw_connection(T), id()) == -1) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure( + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{ "Could not delete large object " + to_string(m_id) + ": " + - reason(T.conn(), err)); + reason(T.conn(), err)}; } } @@ -131,7 +131,7 @@ void pqxx::largeobject::remove(dbtransaction &T) const pqxx::internal::pq::PGconn *pqxx::largeobject::raw_connection( const dbtransaction &T) { - return gate::connection_largeobject(T.conn()).raw_connection(); + return gate::connection_largeobject{T.conn()}.raw_connection(); } @@ -139,13 +139,13 @@ std::string pqxx::largeobject::reason(const connection_base &c, int err) const { if (err == ENOMEM) return "Out of memory"; if (id() == oid_none) return "No object selected"; - return gate::const_connection_largeobject(c).error_message(); + return gate::const_connection_largeobject{c}.error_message(); } pqxx::largeobjectaccess::largeobjectaccess(dbtransaction &T, openmode mode) : - largeobject(T), - m_trans(T) + largeobject{T}, + m_trans{T} { open(mode); } @@ -155,8 +155,8 @@ pqxx::largeobjectaccess::largeobjectaccess( dbtransaction &T, oid O, openmode mode) : - largeobject(O), - m_trans(T) + largeobject{O}, + m_trans{T} { open(mode); } @@ -166,8 +166,8 @@ pqxx::largeobjectaccess::largeobjectaccess( dbtransaction &T, largeobject O, openmode mode) : - largeobject(O), - m_trans(T) + largeobject{O}, + m_trans{T} { open(mode); } @@ -177,8 +177,8 @@ pqxx::largeobjectaccess::largeobjectaccess( dbtransaction &T, const std::string &File, openmode mode) : - largeobject(T, File), - m_trans(T) + largeobject{T, File}, + m_trans{T} { open(mode); } @@ -191,8 +191,8 @@ pqxx::largeobjectaccess::seek(size_type dest, seekdir dir) if (Result == -1) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure("Error seeking in large object: " + reason(err)); + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{"Error seeking in large object: " + reason(err)}; } return Result; @@ -236,19 +236,19 @@ void pqxx::largeobjectaccess::write(const char Buf[], size_type Len) if (Bytes < Len) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); + if (err == ENOMEM) throw std::bad_alloc{}; if (Bytes < 0) - throw failure( + throw failure{ "Error writing to large object #" + to_string(id()) + ": " + - reason(err)); + reason(err)}; if (Bytes == 0) - throw failure( + throw failure{ "Could not write to large object #" + to_string(id()) + ": " + - reason(err)); + reason(err)}; - throw failure( + throw failure{ "Wanted to write " + to_string(Len) + " bytes to large object #" + - to_string(id()) + "; " "could only write " + to_string(Bytes)); + to_string(id()) + "; " "could only write " + to_string(Bytes)}; } } @@ -260,10 +260,10 @@ pqxx::largeobjectaccess::read(char Buf[], size_type Len) if (Bytes < 0) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure( + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{ "Error reading from large object #" + to_string(id()) + ": " + - reason(err)); + reason(err)}; } return Bytes; } @@ -275,10 +275,10 @@ void pqxx::largeobjectaccess::open(openmode mode) if (m_fd < 0) { const int err = errno; - if (err == ENOMEM) throw std::bad_alloc(); - throw failure( + if (err == ENOMEM) throw std::bad_alloc{}; + throw failure{ "Could not open large object " + to_string(id()) + ": " + - reason(err)); + reason(err)}; } } @@ -292,7 +292,7 @@ void pqxx::largeobjectaccess::close() noexcept pqxx::largeobjectaccess::size_type pqxx::largeobjectaccess::tell() const { const size_type res = ctell(); - if (res == -1) throw failure(reason(errno)); + if (res == -1) throw failure{reason(errno)}; return res; } diff --git a/src/notification.cxx b/src/notification.cxx index a9f35175c..b027b78d7 100644 --- a/src/notification.cxx +++ b/src/notification.cxx @@ -2,7 +2,7 @@ * * pqxx::notification_receiver processes notifications. * - * Copyright (c) 2011-2017, Jeroen T. Vermeulen. + * Copyright (c) 2011-2018, Jeroen T. Vermeulen. * * See COPYING for copyright license. If you did not receive a file called * COPYING with this source code, please notify the distributor of this mistake, @@ -23,14 +23,14 @@ using namespace pqxx::internal; pqxx::notification_receiver::notification_receiver( connection_base &c, const std::string &channel_name) : - m_conn(c), - m_channel(channel_name) + m_conn{c}, + m_channel{channel_name} { - gate::connection_notification_receiver(c).add_receiver(this); + gate::connection_notification_receiver{c}.add_receiver(this); } pqxx::notification_receiver::~notification_receiver() { - gate::connection_notification_receiver(this->conn()).remove_receiver(this); + gate::connection_notification_receiver{this->conn()}.remove_receiver(this); } diff --git a/src/pipeline.cxx b/src/pipeline.cxx index 8133a943f..57fc8fe52 100644 --- a/src/pipeline.cxx +++ b/src/pipeline.cxx @@ -33,8 +33,8 @@ const std::string theDummyQuery("SELECT " + theDummyValue + theSeparator); pqxx::pipeline::pipeline(transaction_base &t, const std::string &Name) : - namedclass("pipeline", Name), - transactionfocus(t) + namedclass{"pipeline", Name}, + transactionfocus{t} { m_issuedrange = make_pair(m_queries.end(), m_queries.end()); attach(); @@ -136,8 +136,8 @@ void pqxx::pipeline::cancel() bool pqxx::pipeline::is_finished(pipeline::query_id q) const { if (m_queries.find(q) == m_queries.end()) - throw std::logic_error( - "Requested status for unknown query " + to_string(q)); + throw std::logic_error{ + "Requested status for unknown query '" + to_string(q) + "'."}; return (QueryMap::const_iterator(m_issuedrange.first)==m_queries.end()) or (q < m_issuedrange.first->first and q < m_error); @@ -147,7 +147,7 @@ bool pqxx::pipeline::is_finished(pipeline::query_id q) const std::pair pqxx::pipeline::retrieve() { if (m_queries.empty()) - throw std::logic_error("Attempt to retrieve result from empty pipeline"); + throw std::logic_error{"Attempt to retrieve result from empty pipeline."}; return retrieve(std::begin(m_queries)); } @@ -155,9 +155,9 @@ std::pair pqxx::pipeline::retrieve() int pqxx::pipeline::retain(int retain_max) { if (retain_max < 0) - throw range_error( + throw range_error{ "Attempt to make pipeline retain " + - to_string(retain_max) + " queries"); + to_string(retain_max) + " queries"}; const int oldvalue = m_retain; m_retain = retain_max; @@ -182,7 +182,7 @@ void pqxx::pipeline::resume() pipeline::query_id pqxx::pipeline::generate_id() { if (m_q_id == qid_limit()) - throw std::overflow_error("Too many queries went through pipeline"); + throw std::overflow_error{"Too many queries went through pipeline."}; ++m_q_id; return m_q_id; } @@ -216,7 +216,7 @@ void pqxx::pipeline::issue() const bool prepend_dummy = (num_issued > 1); if (prepend_dummy) cum = theDummyQuery + cum; - gate::connection_pipeline(m_trans.conn()).start_exec(cum); + gate::connection_pipeline{m_trans.conn()}.start_exec(cum); // Since we managed to send out these queries, update state to reflect this m_dummy_pending = prepend_dummy; @@ -229,7 +229,7 @@ void pqxx::pipeline::issue() void pqxx::pipeline::internal_error(const std::string &err) { set_error_at(0); - throw pqxx::internal_error(err); + throw pqxx::internal_error{err}; } @@ -238,7 +238,7 @@ bool pqxx::pipeline::obtain_result(bool expect_none) pqxxassert(not m_dummy_pending); pqxxassert(not m_queries.empty()); - gate::connection_pipeline gate(m_trans.conn()); + gate::connection_pipeline gate{m_trans.conn()}; const auto r = gate.get_result(); if (r == nullptr) { @@ -257,13 +257,13 @@ bool pqxx::pipeline::obtain_result(bool expect_none) if (not have_pending()) { set_error_at(std::begin(m_queries)->first); - throw std::logic_error( - "Got more results from pipeline than there were queries"); + throw std::logic_error{ + "Got more results from pipeline than there were queries."}; } // Must be the result for the oldest pending query if (not m_issuedrange.first->second.get_result().empty()) - internal_error("multiple results for one query"); + internal_error("Multiple results for one query."); m_issuedrange.first->second.set_result(res); ++m_issuedrange.first; @@ -275,19 +275,19 @@ bool pqxx::pipeline::obtain_result(bool expect_none) void pqxx::pipeline::obtain_dummy() { pqxxassert(m_dummy_pending); - gate::connection_pipeline gate(m_trans.conn()); + gate::connection_pipeline gate{m_trans.conn()}; const auto r = gate.get_result(); m_dummy_pending = false; if (r == nullptr) - internal_error("pipeline got no result from backend when it expected one"); + internal_error("Pipeline got no result from backend when it expected one."); result R = gate::result_creation::create(r, "[DUMMY PIPELINE QUERY]"); bool OK = false; try { - gate::result_creation(R).check_status(); + gate::result_creation{R}.check_status(); OK = true; } catch (const sql_error &) @@ -296,10 +296,10 @@ void pqxx::pipeline::obtain_dummy() if (OK) { if (R.size() > 1) - internal_error("unexpected result for dummy query in pipeline"); + internal_error("Unexpected result for dummy query in pipeline."); - if (std::string(R.at(0).at(0).c_str()) != theDummyValue) - internal_error("dummy query in pipeline returned unexpected value"); + if (std::string{R.at(0).at(0).c_str()} != theDummyValue) + internal_error("Dummy query in pipeline returned unexpected value."); return; } @@ -336,9 +336,9 @@ void pqxx::pipeline::obtain_dummy() { m_num_waiting--; const std::string &query = m_issuedrange.first->second.get_query(); - const result res(m_trans.exec(query)); + const result res{m_trans.exec(query)}; m_issuedrange.first->second.set_result(res); - gate::result_creation(res).check_status(); + gate::result_creation{res}.check_status(); ++m_issuedrange.first; } while (m_issuedrange.first != stop); @@ -366,11 +366,11 @@ std::pair pqxx::pipeline::retrieve(pipeline::QueryMap::iterator q) { if (q == m_queries.end()) - throw std::logic_error("Attempt to retrieve result for unknown query"); + throw std::logic_error{"Attempt to retrieve result for unknown query."}; if (q->first >= m_error) - throw std::runtime_error( - "Could not complete query in pipeline due to error in earlier query"); + throw std::runtime_error{ + "Could not complete query in pipeline due to error in earlier query."}; // If query hasn't issued yet, do it now if (m_issuedrange.second != m_queries.end() and @@ -400,8 +400,8 @@ pqxx::pipeline::retrieve(pipeline::QueryMap::iterator q) pqxxassert((m_error <= q->first) or (q != m_issuedrange.first)); if (q->first >= m_error) - throw std::runtime_error( - "Could not complete query in pipeline due to error in earlier query"); + throw std::runtime_error{ + "Could not complete query in pipeline due to error in earlier query."}; // Don't leave the backend idle if there are queries waiting to be issued if (m_num_waiting and not have_pending() and (m_error==qid_limit())) issue(); @@ -411,7 +411,7 @@ pqxx::pipeline::retrieve(pipeline::QueryMap::iterator q) m_queries.erase(q); - gate::result_creation(R).check_status(); + gate::result_creation{R}.check_status(); return P; } @@ -419,16 +419,16 @@ pqxx::pipeline::retrieve(pipeline::QueryMap::iterator q) void pqxx::pipeline::get_further_available_results() { pqxxassert(not m_dummy_pending); - gate::connection_pipeline gate(m_trans.conn()); + gate::connection_pipeline gate{m_trans.conn()}; while (not gate.is_busy() and obtain_result()) - if (not gate.consume_input()) throw broken_connection(); + if (not gate.consume_input()) throw broken_connection{}; } void pqxx::pipeline::receive_if_available() { - gate::connection_pipeline gate(m_trans.conn()); - if (not gate.consume_input()) throw broken_connection(); + gate::connection_pipeline gate{m_trans.conn()}; + if (not gate.consume_input()) throw broken_connection{}; if (gate.is_busy()) return; if (m_dummy_pending) obtain_dummy(); @@ -443,9 +443,9 @@ void pqxx::pipeline::receive(pipeline::QueryMap::const_iterator stop) if (m_dummy_pending) obtain_dummy(); while (obtain_result() and - QueryMap::const_iterator(m_issuedrange.first) != stop) ; + QueryMap::const_iterator{m_issuedrange.first} != stop) ; // Also haul in any remaining "targets of opportunity" - if (QueryMap::const_iterator(m_issuedrange.first) == stop) + if (QueryMap::const_iterator{m_issuedrange.first} == stop) get_further_available_results(); } diff --git a/src/prepared_statement.cxx b/src/prepared_statement.cxx index 93c899ba7..1d1700c5d 100644 --- a/src/prepared_statement.cxx +++ b/src/prepared_statement.cxx @@ -25,8 +25,8 @@ using namespace pqxx::internal; pqxx::prepare::invocation::invocation( transaction_base &home, const std::string &statement) : - m_home(home), - m_statement(statement) + m_home{home}, + m_statement{statement} { } @@ -38,7 +38,7 @@ pqxx::result pqxx::prepare::invocation::exec() const std::vector binaries; const int elts = marshall(ptrs, lens, binaries); - return gate::connection_prepare_invocation(m_home.conn()).prepared_exec( + return gate::connection_prepare_invocation{m_home.conn()}.prepared_exec( m_statement, ptrs.data(), lens.data(), @@ -49,12 +49,12 @@ pqxx::result pqxx::prepare::invocation::exec() const bool pqxx::prepare::invocation::exists() const { - return gate::connection_prepare_invocation(m_home.conn()).prepared_exists( + return gate::connection_prepare_invocation{m_home.conn()}.prepared_exists( m_statement); } pqxx::prepare::internal::prepared_def::prepared_def(const std::string &def) : - definition(def) + definition{def} { } diff --git a/src/result.cxx b/src/result.cxx index db8f25121..536629d4a 100644 --- a/src/result.cxx +++ b/src/result.cxx @@ -33,8 +33,8 @@ void pqxx::internal::clear_result(const pq::PGresult *data) pqxx::result::result( pqxx::internal::pq::PGresult *rhs, const std::string &Query) : - m_data(make_data_pointer(rhs)), - m_query(std::make_shared(Query)) + m_data{make_data_pointer(rhs)}, + m_query{std::make_shared(Query)} { } @@ -52,7 +52,7 @@ bool pqxx::result::operator==(const result &rhs) const noexcept pqxx::result::const_reverse_iterator pqxx::result::rbegin() const { - return const_reverse_iterator(end()); + return const_reverse_iterator{end()}; } @@ -64,7 +64,7 @@ pqxx::result::const_reverse_iterator pqxx::result::crbegin() const pqxx::result::const_reverse_iterator pqxx::result::rend() const { - return const_reverse_iterator(begin()); + return const_reverse_iterator{begin()}; } @@ -76,7 +76,7 @@ pqxx::result::const_reverse_iterator pqxx::result::crend() const pqxx::result::const_iterator pqxx::result::begin() const noexcept { - return const_iterator(this, 0); + return const_iterator{this, 0}; } @@ -100,13 +100,13 @@ bool pqxx::result::empty() const noexcept pqxx::result::reference pqxx::result::front() const noexcept { - return row(*this, 0); + return row{*this, 0}; } pqxx::result::reference pqxx::result::back() const noexcept { - return row(*this, size() - 1); + return row{*this, size() - 1}; } @@ -119,17 +119,26 @@ void pqxx::result::swap(result &rhs) noexcept const pqxx::row pqxx::result::operator[](result_size_type i) const noexcept { - return row(*this, i); + return row{*this, i}; } const pqxx::row pqxx::result::at(pqxx::result::size_type i) const { - if (i >= size()) throw range_error("Row number out of range"); + if (i >= size()) throw range_error{"Row number out of range."}; return operator[](i); } +namespace +{ +/// C string comparison. +inline constexpr bool equal(const char lhs[], const char rhs[]) +{ + return strcmp(lhs, rhs) == 0; +} +} // namespace + void pqxx::result::ThrowSQLError( const std::string &Err, const std::string &Query) const @@ -143,76 +152,76 @@ void pqxx::result::ThrowSQLError( switch (code[1]) { case '8': - throw broken_connection(Err); + throw broken_connection{Err}; case 'A': - throw feature_not_supported(Err, Query, code); + throw feature_not_supported{Err, Query, code}; } break; case '2': switch (code[1]) { case '2': - throw data_exception(Err, Query, code); + throw data_exception{Err, Query, code}; case '3': - if (strcmp(code,"23001")==0) throw restrict_violation(Err, Query, code); - if (strcmp(code,"23502")==0) throw not_null_violation(Err, Query, code); - if (strcmp(code,"23503")==0) - throw foreign_key_violation(Err, Query, code); - if (strcmp(code,"23505")==0) throw unique_violation(Err, Query, code); - if (strcmp(code,"23514")==0) throw check_violation(Err, Query, code); - throw integrity_constraint_violation(Err, Query, code); + if (equal(code,"23001")) throw restrict_violation{Err, Query, code}; + if (equal(code,"23502")) throw not_null_violation{Err, Query, code}; + if (equal(code,"23503")) + throw foreign_key_violation{Err, Query, code}; + if (equal(code,"23505")) throw unique_violation{Err, Query, code}; + if (equal(code,"23514")) throw check_violation{Err, Query, code}; + throw integrity_constraint_violation{Err, Query, code}; case '4': - throw invalid_cursor_state(Err, Query, code); + throw invalid_cursor_state{Err, Query, code}; case '6': - throw invalid_sql_statement_name(Err, Query, code); + throw invalid_sql_statement_name{Err, Query, code}; } break; case '3': switch (code[1]) { case '4': - throw invalid_cursor_name(Err, Query, code); + throw invalid_cursor_name{Err, Query, code}; } break; case '4': switch (code[1]) { case '0': - if (strcmp(code, "40000")==0) throw transaction_rollback(Err); - if (strcmp(code, "40001")==0) throw serialization_failure(Err); - if (strcmp(code, "40001")==0) throw statement_completion_unknown(Err); - if (strcmp(code, "40P01")==0) throw deadlock_detected(Err); + if (equal(code, "40000")) throw transaction_rollback{Err}; + if (equal(code, "40001")) throw serialization_failure{Err}; + if (equal(code, "40001")) throw statement_completion_unknown{Err}; + if (equal(code, "40P01")) throw deadlock_detected{Err}; break; case '2': - if (strcmp(code,"42501")==0) throw insufficient_privilege(Err, Query); - if (strcmp(code,"42601")==0) - throw syntax_error(Err, Query, code, errorposition()); - if (strcmp(code,"42703")==0) throw undefined_column(Err, Query, code); - if (strcmp(code,"42883")==0) throw undefined_function(Err, Query, code); - if (strcmp(code,"42P01")==0) throw undefined_table(Err, Query, code); + if (equal(code,"42501")) throw insufficient_privilege{Err, Query}; + if (equal(code,"42601")) + throw syntax_error{Err, Query, code, errorposition()}; + if (equal(code,"42703")) throw undefined_column{Err, Query, code}; + if (equal(code,"42883")) throw undefined_function{Err, Query, code}; + if (equal(code,"42P01")) throw undefined_table{Err, Query, code}; } break; case '5': switch (code[1]) { case '3': - if (strcmp(code,"53100")==0) throw disk_full(Err, Query, code); - if (strcmp(code,"53200")==0) throw out_of_memory(Err, Query, code); - if (strcmp(code,"53300")==0) throw too_many_connections(Err); - throw insufficient_resources(Err, Query, code); + if (equal(code,"53100")) throw disk_full{Err, Query, code}; + if (equal(code,"53200")) throw out_of_memory{Err, Query, code}; + if (equal(code,"53300")) throw too_many_connections{Err}; + throw insufficient_resources{Err, Query, code}; } break; case 'P': - if (strcmp(code, "P0001")==0) throw plpgsql_raise(Err, Query, code); - if (strcmp(code, "P0002")==0) - throw plpgsql_no_data_found(Err, Query, code); - if (strcmp(code, "P0003")==0) - throw plpgsql_too_many_rows(Err, Query, code); - throw plpgsql_error(Err, Query, code); + if (equal(code, "P0001")) throw plpgsql_raise{Err, Query, code}; + if (equal(code, "P0002")) + throw plpgsql_no_data_found{Err, Query, code}; + if (equal(code, "P0003")) + throw plpgsql_too_many_rows{Err, Query, code}; + throw plpgsql_error{Err, Query, code}; } // Fallback: No error code. - throw sql_error(Err, Query, code); + throw sql_error{Err, Query, code}; } void pqxx::result::check_status() const @@ -224,7 +233,7 @@ void pqxx::result::check_status() const std::string pqxx::result::StatusError() const { - if (m_data.get() == nullptr) throw failure("No result set given"); + if (m_data.get() == nullptr) throw failure{"No result set given."}; std::string Err; @@ -246,9 +255,9 @@ std::string pqxx::result::StatusError() const break; default: - throw internal_error( + throw internal_error{ "pqxx::result: Unrecognized response code " + - to_string(int(PQresultStatus(m_data.get())))); + to_string(int(PQresultStatus(m_data.get())))}; } return Err; } @@ -269,8 +278,8 @@ const std::string &pqxx::result::query() const noexcept pqxx::oid pqxx::result::inserted_oid() const { if (m_data.get() == nullptr) - throw usage_error( - "Attempt to read oid of inserted row without an INSERT result"); + throw usage_error{ + "Attempt to read oid of inserted row without an INSERT result"}; return PQoidValue(const_cast(m_data.get())); } @@ -310,9 +319,9 @@ pqxx::oid pqxx::result::column_type(row::size_type ColNum) const { const oid T = PQftype(m_data.get(), int(ColNum)); if (T == oid_none) - throw argument_error( + throw argument_error{ "Attempt to retrieve type of nonexistent column " + - to_string(ColNum) + " of query result"); + to_string(ColNum) + " of query result."}; return T; } @@ -325,9 +334,9 @@ pqxx::oid pqxx::result::column_table(row::size_type ColNum) const * got an invalid row number. */ if (T == oid_none and ColNum >= columns()) - throw argument_error( + throw argument_error{ "Attempt to retrieve table ID for column " + to_string(ColNum) + - " out of " + to_string(columns())); + " out of " + to_string(columns())}; return T; } @@ -341,16 +350,16 @@ pqxx::row::size_type pqxx::result::table_column(row::size_type ColNum) const // Failed. Now find out why, so we can throw a sensible exception. const std::string col_num = to_string(ColNum); if (ColNum > columns()) - throw range_error("Invalid column index in table_column(): " + col_num); + throw range_error{"Invalid column index in table_column(): " + col_num}; if (m_data.get() == nullptr) - throw usage_error( + throw usage_error{ "Can't query origin of column " + col_num + ": " - "result is not initialized."); + "result is not initialized."}; - throw usage_error( + throw usage_error{ "Can't query origin of column " + col_num + ": " - "not derived from table column"); + "not derived from table column."}; } int pqxx::result::errorposition() const @@ -373,10 +382,10 @@ const char *pqxx::result::column_name(pqxx::row::size_type Number) const if (N == nullptr) { if (m_data.get() == nullptr) - throw usage_error("Queried column name on null result."); - throw range_error( + throw usage_error{"Queried column name on null result."}; + throw range_error{ "Invalid column number: " + to_string(Number) + - " (maximum is " + to_string(columns() - 1) + ")."); + " (maximum is " + to_string(columns() - 1) + ")."}; } return N; } @@ -393,7 +402,7 @@ pqxx::row::size_type pqxx::result::columns() const noexcept pqxx::const_result_iterator pqxx::const_result_iterator::operator++(int) { - const_result_iterator old(*this); + const_result_iterator old{*this}; m_index++; return old; } @@ -401,7 +410,7 @@ pqxx::const_result_iterator pqxx::const_result_iterator::operator++(int) pqxx::const_result_iterator pqxx::const_result_iterator::operator--(int) { - const_result_iterator old(*this); + const_result_iterator old{*this}; m_index--; return old; } @@ -410,7 +419,7 @@ pqxx::const_result_iterator pqxx::const_result_iterator::operator--(int) pqxx::result::const_iterator pqxx::result::const_reverse_iterator::base() const noexcept { - iterator_type tmp(*this); + iterator_type tmp{*this}; return ++tmp; } @@ -418,7 +427,7 @@ pqxx::result::const_reverse_iterator::base() const noexcept pqxx::const_reverse_result_iterator pqxx::const_reverse_result_iterator::operator++(int) { - const_reverse_result_iterator tmp(*this); + const_reverse_result_iterator tmp{*this}; iterator_type::operator--(); return tmp; } @@ -427,7 +436,7 @@ pqxx::const_reverse_result_iterator::operator++(int) pqxx::const_reverse_result_iterator pqxx::const_reverse_result_iterator::operator--(int) { - const_reverse_result_iterator tmp(*this); + const_reverse_result_iterator tmp{*this}; iterator_type::operator++(); return tmp; } @@ -436,5 +445,5 @@ pqxx::const_reverse_result_iterator::operator--(int) template<> std::string pqxx::to_string(const field &Obj) { - return std::string(Obj.c_str(), Obj.size()); + return std::string{Obj.c_str(), Obj.size()}; } diff --git a/src/robusttransaction.cxx b/src/robusttransaction.cxx index e22938aaf..12094cbc6 100644 --- a/src/robusttransaction.cxx +++ b/src/robusttransaction.cxx @@ -26,9 +26,9 @@ pqxx::internal::basic_robusttransaction::basic_robusttransaction( connection_base &C, const std::string &IsolationLevel, const std::string &table_name) : - namedclass("robusttransaction"), - dbtransaction(C, IsolationLevel), - m_log_table(table_name) + namedclass{"robusttransaction"}, + dbtransaction{C, IsolationLevel}, + m_log_table{table_name} { if (table_name.empty()) m_log_table = "pqxx_robusttransaction_log"; m_sequence = m_log_table + "_seq"; @@ -71,7 +71,7 @@ void pqxx::internal::basic_robusttransaction::do_begin() void pqxx::internal::basic_robusttransaction::do_commit() { if (m_record_id == 0) - throw internal_error("transaction '" + name() + "' has no ID"); + throw internal_error{"transaction '" + name() + "' has no ID."}; // Check constraints before sending the COMMIT to the database to reduce the // work being done inside our in-doubt window. @@ -142,9 +142,9 @@ void pqxx::internal::basic_robusttransaction::do_commit() process_notice( "Could not verify existence of transaction record because of the " "following error:\n"); - process_notice(std::string(f.what()) + "\n"); + process_notice(std::string{f.what()} + "\n"); - throw in_doubt_error(Msg); + throw in_doubt_error{Msg}; } // Transaction record is still there, so the transaction failed and all we @@ -152,7 +152,7 @@ void pqxx::internal::basic_robusttransaction::do_commit() if (exists) { do_abort(); - throw broken_connection("Connection lost while committing."); + throw broken_connection{"Connection lost while committing."}; } // Otherwise, the transaction succeeded. Forget there was ever an error. @@ -187,7 +187,7 @@ void pqxx::internal::basic_robusttransaction::CreateLogTable() catch (const std::exception &e) { conn().process_notice( - "Could not create transaction log table: " + std::string(e.what())); + "Could not create transaction log table: " + std::string{e.what()}); } try @@ -197,7 +197,7 @@ void pqxx::internal::basic_robusttransaction::CreateLogTable() catch (const std::exception &e) { conn().process_notice( - "Could not create transaction log sequence: " + std::string(e.what())); + "Could not create transaction log sequence: " + std::string{e.what()}); } } @@ -210,7 +210,7 @@ void pqxx::internal::basic_robusttransaction::CreateTransactionRecord() "WHERE date < CURRENT_TIMESTAMP - '30 days'::interval").c_str()); // Allocate id. - const std::string sql_get_id("SELECT nextval(" + quote(m_sequence) + ")"); + const std::string sql_get_id{"SELECT nextval(" + quote(m_sequence) + ")"}; direct_exec(sql_get_id.c_str())[0][0].to(m_record_id); direct_exec(( @@ -276,8 +276,8 @@ bool pqxx::internal::basic_robusttransaction::CheckTransactionRecord() { if (conn().server_version() > 80300) { - const std::string query( - "SELECT " + m_xid + " >= txid_snapshot_xmin(txid_current_snapshot())"); + const std::string query{ + "SELECT " + m_xid + " >= txid_snapshot_xmin(txid_current_snapshot())"}; direct_exec(query.c_str())[0][0].to(hold); } else @@ -294,17 +294,17 @@ bool pqxx::internal::basic_robusttransaction::CheckTransactionRecord() * relation exists but no such record is found, then the transaction is no * longer running. */ - const result R(direct_exec(( + const result R{direct_exec(( "SELECT current_query " "FROM pq_stat_activity " - "WHERE procpid = " + to_string(m_backendpid)).c_str())); + "WHERE procpid = " + to_string(m_backendpid)).c_str())}; hold = not R.empty(); } } if (hold) - throw in_doubt_error( - "Old backend process stays alive too long to wait for."); + throw in_doubt_error{ + "Old backend process stays alive too long to wait for."}; // Now look for our transaction record const std::string Find = diff --git a/src/row.cxx b/src/row.cxx index cae01ef00..4cdffb81b 100644 --- a/src/row.cxx +++ b/src/row.cxx @@ -22,16 +22,16 @@ pqxx::row::row(result r, size_t i) noexcept : - m_result(r), - m_index(long(i)), - m_end(internal::gate::result_row(r) ? r.columns() : 0) + m_result{r}, + m_index{long(i)}, + m_end{internal::gate::result_row(r) ? r.columns() : 0} { } pqxx::row::const_iterator pqxx::row::begin() const noexcept { - return const_iterator(*this, m_begin); + return const_iterator{*this, m_begin}; } @@ -43,7 +43,7 @@ pqxx::row::const_iterator pqxx::row::cbegin() const noexcept pqxx::row::const_iterator pqxx::row::end() const noexcept { - return const_iterator(*this, m_end); + return const_iterator{*this, m_end}; } @@ -55,19 +55,19 @@ pqxx::row::const_iterator pqxx::row::cend() const noexcept pqxx::row::reference pqxx::row::front() const noexcept { - return field(*this, m_begin); + return field{*this, m_begin}; } pqxx::row::reference pqxx::row::back() const noexcept { - return field(*this, m_end - 1); + return field{*this, m_end - 1}; } pqxx::row::const_reverse_iterator pqxx::row::rbegin() const { - return const_reverse_row_iterator(end()); + return const_reverse_row_iterator{end()}; } @@ -79,7 +79,7 @@ pqxx::row::const_reverse_iterator pqxx::row::crbegin() const pqxx::row::const_reverse_iterator pqxx::row::rend() const { - return const_reverse_row_iterator(begin()); + return const_reverse_row_iterator{begin()}; } @@ -102,7 +102,7 @@ bool pqxx::row::operator==(const row &rhs) const noexcept pqxx::row::reference pqxx::row::operator[](size_type i) const noexcept { - return field(*this, m_begin + i); + return field{*this, m_begin + i}; } @@ -153,14 +153,14 @@ void pqxx::row::swap(row &rhs) noexcept pqxx::field pqxx::row::at(const char f[]) const { - return field(*this, m_begin + column_number(f)); + return field{*this, m_begin + column_number(f)}; } pqxx::field pqxx::row::at(pqxx::row::size_type i) const { if (i >= size()) - throw range_error("Invalid field number"); + throw range_error{"Invalid field number."}; return operator[](i); } @@ -188,7 +188,7 @@ pqxx::row::size_type pqxx::row::column_number(const char ColName[]) const { const auto n = m_result.column_number(ColName); if (n >= m_end) - return result().column_number(ColName); + return result{}.column_number(ColName); if (n >= m_begin) return n - m_begin; @@ -197,7 +197,7 @@ pqxx::row::size_type pqxx::row::column_number(const char ColName[]) const if (strcmp(AdaptedColName, m_result.column_name(i)) == 0) return i - m_begin; - return result().column_number(ColName); + return result{}.column_number(ColName); } @@ -205,9 +205,9 @@ pqxx::row::size_type pqxx::result::column_number(const char ColName[]) const { const int N = PQfnumber( const_cast(m_data.get()), ColName); - // TODO: Should this be an out_of_range? if (N == -1) - throw argument_error("Unknown column name: '" + std::string(ColName) + "'"); + throw argument_error{ + "Unknown column name: '" + std::string{ColName} + "'."}; return row::size_type(N); } @@ -216,9 +216,9 @@ pqxx::row::size_type pqxx::result::column_number(const char ColName[]) const pqxx::row pqxx::row::slice(size_type Begin, size_type End) const { if (Begin > End or End > size()) - throw range_error("Invalid field range"); + throw range_error{"Invalid field range."}; - row result(*this); + row result{*this}; result.m_begin = m_begin + Begin; result.m_end = m_begin + End; return result; @@ -233,7 +233,7 @@ bool pqxx::row::empty() const noexcept pqxx::const_row_iterator pqxx::const_row_iterator::operator++(int) { - const_row_iterator old(*this); + const_row_iterator old{*this}; m_col++; return old; } @@ -241,7 +241,7 @@ pqxx::const_row_iterator pqxx::const_row_iterator::operator++(int) pqxx::const_row_iterator pqxx::const_row_iterator::operator--(int) { - const_row_iterator old(*this); + const_row_iterator old{*this}; m_col--; return old; } @@ -250,7 +250,7 @@ pqxx::const_row_iterator pqxx::const_row_iterator::operator--(int) pqxx::const_row_iterator pqxx::const_reverse_row_iterator::base() const noexcept { - iterator_type tmp(*this); + iterator_type tmp{*this}; return ++tmp; } @@ -258,7 +258,7 @@ pqxx::const_reverse_row_iterator::base() const noexcept pqxx::const_reverse_row_iterator pqxx::const_reverse_row_iterator::operator++(int) { - const_reverse_row_iterator tmp(*this); + const_reverse_row_iterator tmp{*this}; operator++(); return tmp; } @@ -267,7 +267,7 @@ pqxx::const_reverse_row_iterator::operator++(int) pqxx::const_reverse_row_iterator pqxx::const_reverse_row_iterator::operator--(int) { - const_reverse_row_iterator tmp(*this); + const_reverse_row_iterator tmp{*this}; operator--(); return tmp; } diff --git a/src/strconv.cxx b/src/strconv.cxx index b8fcea990..4f08fbe40 100644 --- a/src/strconv.cxx +++ b/src/strconv.cxx @@ -33,8 +33,8 @@ template inline void set_to_Inf(T &t, int sign=1) [[noreturn]] void report_overflow() { - throw pqxx::failure( - "Could not convert string to integer: value out of range."); + throw pqxx::failure{ + "Could not convert string to integer: value out of range."}; } @@ -51,7 +51,7 @@ template struct underflow_check { static void check_before_adding_digit(T n) { - const T ten(10); + constexpr T ten{10}; if (n < 0 and (std::numeric_limits::min() / ten) > n) report_overflow(); } }; @@ -69,7 +69,7 @@ template struct underflow_check template T safe_multiply_by_ten(T n) { using limits = std::numeric_limits; - const T ten(10); + constexpr T ten{10}; if (n > 0 and (limits::max() / n) < ten) report_overflow(); underflow_check::check_before_adding_digit(n); return T(n * ten); @@ -102,8 +102,8 @@ template void from_string_signed(const char Str[], T &Obj) if (not isdigit(Str[i])) { if (Str[i] != '-') - throw pqxx::failure( - "Could not convert string to integer: '" + std::string(Str) + "'"); + throw pqxx::failure{ + "Could not convert string to integer: '" + std::string{Str} + "'."}; for (++i; isdigit(Str[i]); ++i) result = absorb_digit(result, -digit_to_number(Str[i])); @@ -115,8 +115,8 @@ template void from_string_signed(const char Str[], T &Obj) } if (Str[i]) - throw pqxx::failure( - "Unexpected text after integer: '" + std::string(Str) + "'"); + throw pqxx::failure{ + "Unexpected text after integer: '" + std::string{Str} + "'."}; Obj = result; } @@ -127,28 +127,38 @@ template void from_string_unsigned(const char Str[], T &Obj) T result = 0; if (not isdigit(Str[i])) - throw pqxx::failure( + throw pqxx::failure{ "Could not convert string to unsigned integer: '" + - std::string(Str) + "'"); + std::string{Str} + "'."}; for (; isdigit(Str[i]); ++i) result = absorb_digit(result, digit_to_number(Str[i])); if (Str[i]) - throw pqxx::failure( - "Unexpected text after integer: '" + std::string(Str) + "'"); + throw pqxx::failure{ + "Unexpected text after integer: '" + std::string{Str} + "'."}; Obj = result; } +namespace +{ +/// C string comparison. +inline constexpr bool equal(const char lhs[], const char rhs[]) +{ + return strcmp(lhs, rhs) == 0; +} +} // namespace + + bool valid_infinity_string(const char str[]) noexcept { return - strcmp("infinity", str) == 0 or - strcmp("Infinity", str) == 0 or - strcmp("INFINITY", str) == 0 or - strcmp("inf", str) == 0; + equal("infinity", str) or + equal("Infinity", str) or + equal("INFINITY", str) or + equal("inf", str); } @@ -168,7 +178,7 @@ bool valid_infinity_string(const char str[]) noexcept template class dumb_stringstream : public std::stringstream { public: - dumb_stringstream() : std::stringstream() + dumb_stringstream() : std::stringstream{} { this->imbue(std::locale::classic()); @@ -228,9 +238,9 @@ template inline void from_string_float(const char Str[], T &Obj) } if (not ok) - throw pqxx::failure( + throw pqxx::failure{ "Could not convert string to numeric value: '" + - std::string(Str) + "'"); + std::string{Str} + "'."}; Obj = result; } @@ -296,7 +306,7 @@ namespace internal { void throw_null_conversion(const std::string &type) { - throw conversion_error("Attempt to convert null to " + type); + throw conversion_error{"Attempt to convert null to " + type + "."}; } } // namespace pqxx::internal @@ -317,8 +327,8 @@ void string_traits::from_string(const char Str[], bool &Obj) result = false; OK = not ( (Str[1] != '\0') and - (strcmp(Str+1, "alse") != 0) and - (strcmp(Str+1, "ALSE") != 0)); + (not equal(Str+1, "alse")) and + (not equal(Str+1, "ALSE"))); break; case '0': @@ -340,8 +350,8 @@ void string_traits::from_string(const char Str[], bool &Obj) result = true; OK = not ( (Str[1] != '\0') and - (strcmp(Str+1, "rue") != 0) and - (strcmp(Str+1, "RUE") != 0)); + (not equal(Str+1, "rue")) and + (not equal(Str+1, "RUE"))); break; default: @@ -349,8 +359,8 @@ void string_traits::from_string(const char Str[], bool &Obj) } if (not OK) - throw argument_error( - "Failed conversion to bool: '" + std::string(Str) + "'"); + throw argument_error{ + "Failed conversion to bool: '" + std::string{Str} + "'."}; Obj = result; } diff --git a/src/stream_base.cxx b/src/stream_base.cxx index fb11e98cb..8351ca26e 100644 --- a/src/stream_base.cxx +++ b/src/stream_base.cxx @@ -15,8 +15,8 @@ pqxx::stream_base::stream_base(transaction_base &tb) : - internal::namedclass("stream_base"), - internal::transactionfocus(tb), + internal::namedclass{"stream_base"}, + internal::transactionfocus{tb}, m_finished{false} {} diff --git a/src/stream_from.cxx b/src/stream_from.cxx index a9e0358d6..215cff9a0 100644 --- a/src/stream_from.cxx +++ b/src/stream_from.cxx @@ -43,8 +43,8 @@ pqxx::stream_from::stream_from( transaction_base &tb, const std::string &table_name ) : - namedclass("stream_from", table_name), - stream_base(tb), + namedclass{"stream_from", table_name}, + stream_base{tb}, m_retry_line{false} { setup(tb, table_name); diff --git a/src/stream_to.cxx b/src/stream_to.cxx index ae7716d15..68d71a573 100644 --- a/src/stream_to.cxx +++ b/src/stream_to.cxx @@ -19,8 +19,8 @@ pqxx::stream_to::stream_to( transaction_base &tb, const std::string &table_name ) : - namedclass("stream_to", table_name), - stream_base(tb) + namedclass{"stream_to", table_name}, + stream_base{tb} { setup(tb, table_name); } diff --git a/src/subtransaction.cxx b/src/subtransaction.cxx index c5b4176c3..fe574e97a 100644 --- a/src/subtransaction.cxx +++ b/src/subtransaction.cxx @@ -23,10 +23,10 @@ using namespace pqxx::internal; pqxx::subtransaction::subtransaction( dbtransaction &T, const std::string &Name) : - namedclass("subtransaction", T.conn().adorn_name(Name)), - transactionfocus(T), - dbtransaction(T.conn(), false), - m_parent(T) + namedclass{"subtransaction", T.conn().adorn_name(Name)}, + transactionfocus{T}, + dbtransaction{T.conn(), false}, + m_parent{T} { } @@ -40,7 +40,7 @@ using dbtransaction_ref = pqxx::dbtransaction &; pqxx::subtransaction::subtransaction( subtransaction &T, const std::string &Name) : - subtransaction(dbtransaction_ref(T), Name) + subtransaction{dbtransaction_ref(T), Name} { } @@ -63,7 +63,7 @@ void pqxx::subtransaction::do_commit() const int ra = m_reactivation_avoidance.get(); m_reactivation_avoidance.clear(); direct_exec(("RELEASE SAVEPOINT " + quote_name(name())).c_str()); - gate::transaction_subtransaction(m_parent).add_reactivation_avoidance_count( + gate::transaction_subtransaction{m_parent}.add_reactivation_avoidance_count( ra); } diff --git a/src/tablereader.cxx b/src/tablereader.cxx index dbadc3977..0a782a7af 100644 --- a/src/tablereader.cxx +++ b/src/tablereader.cxx @@ -22,9 +22,9 @@ pqxx::tablereader::tablereader( transaction_base &T, const std::string &Name, const std::string &Null) : - namedclass("tablereader", Name), - tablestream(T, Null), - m_done(true) + namedclass{"tablereader", Name}, + tablestream{T, Null}, + m_done{true} { setup(T, Name); } @@ -34,7 +34,7 @@ void pqxx::tablereader::setup( const std::string &Name, const std::string &Columns) { - gate::transaction_tablereader(T).BeginCopyRead(Name, Columns); + gate::transaction_tablereader{T}.BeginCopyRead(Name, Columns); register_me(); m_done = false; } @@ -56,7 +56,7 @@ bool pqxx::tablereader::get_raw_line(std::string &Line) { if (not m_done) try { - m_done = not gate::transaction_tablereader(m_trans).read_copy_line(Line); + m_done = not gate::transaction_tablereader{m_trans}.read_copy_line(Line); } catch (const std::exception &) { @@ -144,13 +144,13 @@ std::string pqxx::tablereader::extract_field( { const char n = Line[++i]; if (i >= Line.size()) - throw failure("Row ends in backslash"); + throw failure{"Row ends in backslash."}; switch (n) { case 'N': // Null value if (not R.empty()) - throw failure("Null sequence found in nonempty field"); + throw failure{"Null sequence found in nonempty field."}; R = NullStr(); isnull = true; break; @@ -165,11 +165,11 @@ std::string pqxx::tablereader::extract_field( case '7': { if ((i+2) >= Line.size()) - throw failure("Row ends in middle of octal value"); + throw failure{"Row ends in middle of octal value."}; const char n1 = Line[++i]; const char n2 = Line[++i]; if (not is_octalchar(n1) or not is_octalchar(n2)) - throw failure("Invalid octal in encoded table stream"); + throw failure{"Invalid octal in encoded table stream."}; R += char( (digit_to_number(n)<<6) | (digit_to_number(n1)<<3) | @@ -205,7 +205,7 @@ std::string pqxx::tablereader::extract_field( if (i == stop) { if ((i+1) >= Line.size()) - throw internal_error("COPY line ends in backslash"); + throw internal_error{"COPY line ends in backslash."}; stop = findtab(Line, i+1); } break; @@ -221,7 +221,7 @@ std::string pqxx::tablereader::extract_field( ++i; if (isnull and (R.size() != NullStr().size())) - throw failure("Field contains data behind null sequence"); + throw failure{"Field contains data behind null sequence."}; return R; } diff --git a/src/tablestream.cxx b/src/tablestream.cxx index 15c36da7e..a1d016f28 100644 --- a/src/tablestream.cxx +++ b/src/tablestream.cxx @@ -16,9 +16,9 @@ pqxx::tablestream::tablestream(transaction_base &STrans, const std::string &Null) : - internal::namedclass("tablestream"), - internal::transactionfocus(STrans), - m_null(Null) + internal::namedclass{"tablestream"}, + internal::transactionfocus{STrans}, + m_null{Null} { } diff --git a/src/tablewriter.cxx b/src/tablewriter.cxx index 00e9144d4..6ef7b7249 100644 --- a/src/tablewriter.cxx +++ b/src/tablewriter.cxx @@ -23,8 +23,8 @@ pqxx::tablewriter::tablewriter( transaction_base &T, const std::string &WName, const std::string &Null) : - namedclass("tablewriter", WName), - tablestream(T, Null) + namedclass{"tablewriter", WName}, + tablestream{T, Null} { setup(T, WName); } @@ -48,7 +48,7 @@ void pqxx::tablewriter::setup( const std::string &WName, const std::string &Columns) { - gate::transaction_tablewriter(T).BeginCopyWrite(WName, Columns); + gate::transaction_tablewriter{T}.BeginCopyWrite(WName, Columns); register_me(); } @@ -65,10 +65,10 @@ pqxx::tablewriter &pqxx::tablewriter::operator<<(pqxx::tablereader &R) void pqxx::tablewriter::write_raw_line(const std::string &Line) { const std::string::size_type len = Line.size(); - gate::transaction_tablewriter(m_trans).write_copy_line( + gate::transaction_tablewriter{m_trans}.write_copy_line( ((len == 0) or (Line[len-1] != '\n')) ? Line : - std::string(Line, 0, len-1)); + std::string{Line, 0, len-1}); } @@ -85,7 +85,7 @@ void pqxx::tablewriter::writer_close() base_close(); try { - gate::transaction_tablewriter(m_trans).end_copy_write(); + gate::transaction_tablewriter{m_trans}.end_copy_write(); } catch (const std::exception &) { diff --git a/src/transaction.cxx b/src/transaction.cxx index e79366fe8..625fe1f66 100644 --- a/src/transaction.cxx +++ b/src/transaction.cxx @@ -21,8 +21,8 @@ pqxx::internal::basic_transaction::basic_transaction( connection_base &C, const std::string &IsolationLevel, readwrite_policy rw) : - namedclass("transaction"), - dbtransaction(C, IsolationLevel, rw) + namedclass{"transaction"}, + dbtransaction{C, IsolationLevel, rw} { } @@ -37,13 +37,13 @@ void pqxx::internal::basic_transaction::do_commit() { // Outcome of "commit" is unknown. This is a disaster: we don't know the // resulting state of the database. - process_notice(e.what() + std::string("\n")); + process_notice(e.what() + std::string{"\n"}); const std::string msg = "WARNING: Commit of transaction '" + name() + "' is unknown. " "There is no way to tell whether the transaction succeeded " "or was aborted except to check manually."; process_notice(msg + "\n"); - throw in_doubt_error(msg); + throw in_doubt_error{msg}; } catch (const std::exception &e) { @@ -51,7 +51,7 @@ void pqxx::internal::basic_transaction::do_commit() { // We've lost the connection while committing. There is just no way of // telling what happened on the other end. >8-O - process_notice(e.what() + std::string("\n")); + process_notice(e.what() + std::string{"\n"}); const std::string Msg = "WARNING: Connection lost while committing transaction " @@ -60,7 +60,7 @@ void pqxx::internal::basic_transaction::do_commit() "or was aborted except to check manually."; process_notice(Msg + "\n"); - throw in_doubt_error(Msg); + throw in_doubt_error{Msg}; } else { diff --git a/src/transaction_base.cxx b/src/transaction_base.cxx index 83f50166c..d178d42f4 100644 --- a/src/transaction_base.cxx +++ b/src/transaction_base.cxx @@ -31,8 +31,8 @@ using namespace pqxx::internal; pqxx::internal::parameterized_invocation::parameterized_invocation( connection_base &c, const std::string &query) : - m_home(c), - m_query(query) + m_home{c}, + m_query{query} { } @@ -44,7 +44,7 @@ pqxx::result pqxx::internal::parameterized_invocation::exec() std::vector binaries; const int elements = marshall(values, lengths, binaries); - return gate::connection_parameterized_invocation(m_home).parameterized_exec( + return gate::connection_parameterized_invocation{m_home}.parameterized_exec( m_query, values.data(), lengths.data(), @@ -54,12 +54,12 @@ pqxx::result pqxx::internal::parameterized_invocation::exec() pqxx::transaction_base::transaction_base(connection_base &C, bool direct) : - namedclass("transaction_base"), - m_conn(C) + namedclass{"transaction_base"}, + m_conn{C} { if (direct) { - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.register_transaction(this); m_registered = true; } @@ -77,7 +77,7 @@ pqxx::transaction_base::~transaction_base() if (m_registered) { m_conn.process_notice(description() + " was never closed properly!\n"); - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.unregister_transaction(this); } } @@ -85,7 +85,7 @@ pqxx::transaction_base::~transaction_base() { try { - process_notice(std::string(e.what()) + "\n"); + process_notice(std::string{e.what()} + "\n"); } catch (const std::exception &) { @@ -110,7 +110,7 @@ void pqxx::transaction_base::commit() break; case st_aborted: - throw usage_error("Attempt to commit previously aborted " + description()); + throw usage_error{"Attempt to commit previously aborted " + description()}; case st_committed: // Transaction has been committed already. This is not exactly proper @@ -118,17 +118,17 @@ void pqxx::transaction_base::commit() // that an abort is needed--which would only confuse things further at this // stage. // Therefore, multiple commits are accepted, though under protest. - m_conn.process_notice(description() + " committed more than once\n"); + m_conn.process_notice(description() + " committed more than once.\n"); return; case st_in_doubt: // Transaction may or may not have been committed. The only thing we can // really do is keep telling the caller that the transaction is in doubt. - throw in_doubt_error( - description() + " committed again while in an indeterminate state"); + throw in_doubt_error{ + description() + " committed again while in an indeterminate state."}; default: - throw internal_error("pqxx::transaction: invalid status code"); + throw internal_error{"pqxx::transaction: invalid status code."}; } // Tricky one. If stream is nested in transaction but inside the same scope, @@ -136,17 +136,17 @@ void pqxx::transaction_base::commit() // commit is premature. Punish this swiftly and without fail to discourage // the habit from forming. if (m_focus.get()) - throw failure( + throw failure{ "Attempt to commit " + description() + " with " + - m_focus.get()->description() + " still open"); + m_focus.get()->description() + " still open."}; // Check that we're still connected (as far as we know--this is not an // absolute thing!) before trying to commit. If the connection was broken // already, the commit would fail anyway but this way at least we don't remain // in-doubt as to whether the backend got the commit order at all. if (not m_conn.is_open()) - throw broken_connection( - "Broken connection to backend; cannot complete transaction"); + throw broken_connection{ + "Broken connection to backend; cannot complete transaction."}; try { @@ -164,7 +164,7 @@ void pqxx::transaction_base::commit() throw; } - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.add_variables(m_vars); End(); @@ -188,7 +188,7 @@ void pqxx::transaction_base::abort() return; case st_committed: - throw usage_error("Attempt to abort previously committed " + description()); + throw usage_error{"Attempt to abort previously committed " + description()}; case st_in_doubt: // Aborting an in-doubt transaction is probably a reasonably sane response @@ -199,7 +199,7 @@ void pqxx::transaction_base::abort() return; default: - throw internal_error("invalid transaction status"); + throw internal_error{"Invalid transaction status."}; } m_status = st_aborted; @@ -236,12 +236,12 @@ void pqxx::transaction_base::activate() case st_committed: case st_aborted: case st_in_doubt: - throw usage_error( + throw usage_error{ "Attempt to activate " + description() + " " - "which is already closed"); + "which is already closed."}; default: - throw internal_error("pqxx::transaction: invalid status code"); + throw internal_error{"pqxx::transaction: invalid status code."}; } } @@ -255,10 +255,10 @@ pqxx::result pqxx::transaction_base::exec( const std::string N = (Desc.empty() ? "" : "'" + Desc + "' "); if (m_focus.get()) - throw usage_error( + throw usage_error{ "Attempt to execute query " + N + "on " + description() + " " - "with " + m_focus.get()->description() + " still open"); + "with " + m_focus.get()->description() + " still open."}; try { @@ -266,7 +266,7 @@ pqxx::result pqxx::transaction_base::exec( } catch (const usage_error &e) { - throw usage_error("Error executing query " + N + ". " + e.what()); + throw usage_error{"Error executing query " + N + ". " + e.what()}; } // TODO: Pass Desc to do_exec(), and from there on down @@ -283,9 +283,9 @@ pqxx::result pqxx::transaction_base::exec_n( if (r.size() != rows) { const std::string N = (Desc.empty() ? "" : "'" + Desc + "'"); - throw unexpected_rows( + throw unexpected_rows{ "Expected " + to_string(rows) + " row(s) of data " - "from query " + N + ", got " + to_string(r.size()) + "."); + "from query " + N + ", got " + to_string(r.size()) + "."}; } return r; } @@ -298,10 +298,10 @@ void pqxx::transaction_base::check_rowcount_prepared( { if (actual_rows != expected_rows) { - throw unexpected_rows( + throw unexpected_rows{ "Expected " + to_string(expected_rows) + " row(s) of data " "from prepared statement '" + statement + "', got " + - to_string(actual_rows) + "."); + to_string(actual_rows) + "."}; } } @@ -312,9 +312,9 @@ void pqxx::transaction_base::check_rowcount_params( { if (actual_rows != expected_rows) { - throw unexpected_rows( + throw unexpected_rows{ "Expected " + to_string(expected_rows) + " row(s) of data " - "from parameterised query, got " + to_string(actual_rows) + "."); + "from parameterised query, got " + to_string(actual_rows) + "."}; } } @@ -323,7 +323,7 @@ pqxx::internal::parameterized_invocation pqxx::transaction_base::parameterized(const std::string &query) { #include "pqxx/internal/ignore-deprecated-pre.hxx" - return internal::parameterized_invocation(conn(), query); + return internal::parameterized_invocation{conn(), query}; #include "pqxx/internal/ignore-deprecated-post.hxx" } @@ -337,11 +337,11 @@ pqxx::transaction_base::prepared(const std::string &statement) } catch (const usage_error &e) { - throw usage_error( - "Error executing prepared statement " + statement + ". " + e.what()); + throw usage_error{ + "Error executing prepared statement " + statement + ". " + e.what()}; } #include "pqxx/internal/ignore-deprecated-pre.hxx" - return prepare::invocation(*this, statement); + return prepare::invocation{*this, statement}; #include "pqxx/internal/ignore-deprecated-post.hxx" } @@ -350,7 +350,7 @@ pqxx::result pqxx::transaction_base::internal_exec_prepared( const std::string &statement, const internal::params &args) { - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; return gate.exec_prepared(statement, args); } @@ -359,7 +359,7 @@ pqxx::result pqxx::transaction_base::internal_exec_params( const std::string &query, const internal::params &args) { - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; return gate.exec_params(query, args); } @@ -369,7 +369,7 @@ void pqxx::transaction_base::set_variable( const std::string &Value) { // Before committing to this new value, see what the backend thinks about it - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.raw_set_var(Var, Value); m_vars[Var] = Value; } @@ -379,15 +379,15 @@ std::string pqxx::transaction_base::get_variable(const std::string &Var) { const std::map::const_iterator i = m_vars.find(Var); if (i != m_vars.end()) return i->second; - return gate::connection_transaction(conn()).raw_get_var(Var); + return gate::connection_transaction{conn()}.raw_get_var(Var); } void pqxx::transaction_base::Begin() { if (m_status != st_nascent) - throw internal_error( - "pqxx::transaction: Begin() called while not in nascent state"); + throw internal_error{ + "pqxx::transaction: Begin() called while not in nascent state."}; try { @@ -415,7 +415,7 @@ void pqxx::transaction_base::End() noexcept if (m_registered) { m_registered = false; - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.unregister_transaction(this); } @@ -424,12 +424,12 @@ void pqxx::transaction_base::End() noexcept if (m_focus.get()) m_conn.process_notice( "Closing " + description() + " with " + - m_focus.get()->description() + " still open\n"); + m_focus.get()->description() + " still open.\n"); try { abort(); } catch (const std::exception &e) { m_conn.process_notice(e.what()); } - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.take_reactivation_avoidance(m_reactivation_avoidance.get()); m_reactivation_avoidance.clear(); } @@ -455,7 +455,7 @@ void pqxx::transaction_base::unregister_focus(internal::transactionfocus *S) } catch (const std::exception &e) { - m_conn.process_notice(std::string(e.what()) + "\n"); + m_conn.process_notice(std::string{e.what()} + "\n"); } } @@ -463,7 +463,7 @@ void pqxx::transaction_base::unregister_focus(internal::transactionfocus *S) pqxx::result pqxx::transaction_base::direct_exec(const char C[], int Retries) { CheckPendingError(); - return gate::connection_transaction(conn()).exec(C, Retries); + return gate::connection_transaction{conn()}.exec(C, Retries); } @@ -497,9 +497,9 @@ void pqxx::transaction_base::CheckPendingError() { if (not m_pending_error.empty()) { - const std::string Err(m_pending_error); + const std::string Err{m_pending_error}; m_pending_error.clear(); - throw failure(Err); + throw failure{Err}; } } @@ -535,20 +535,20 @@ void pqxx::transaction_base::BeginCopyWrite( bool pqxx::transaction_base::read_copy_line(std::string &line) { - return gate::connection_transaction(conn()).read_copy_line(line); + return gate::connection_transaction{conn()}.read_copy_line(line); } void pqxx::transaction_base::write_copy_line(const std::string &line) { - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.write_copy_line(line); } void pqxx::transaction_base::end_copy_write() { - gate::connection_transaction gate(conn()); + gate::connection_transaction gate{conn()}; gate.end_copy_write(); } @@ -561,7 +561,7 @@ encoding_group pqxx::transaction_base::current_encoding() void pqxx::internal::transactionfocus::register_me() { - gate::transaction_transactionfocus gate(m_trans); + gate::transaction_transactionfocus gate{m_trans}; gate.register_focus(this); m_registered = true; } @@ -569,7 +569,7 @@ void pqxx::internal::transactionfocus::register_me() void pqxx::internal::transactionfocus::unregister_me() noexcept { - gate::transaction_transactionfocus gate(m_trans); + gate::transaction_transactionfocus gate{m_trans}; gate.unregister_focus(this); m_registered = false; } @@ -578,6 +578,6 @@ void pqxx::internal::transactionfocus::reg_pending_error(const std::string &err) noexcept { - gate::transaction_transactionfocus gate(m_trans); + gate::transaction_transactionfocus gate{m_trans}; gate.register_pending_error(err); } diff --git a/src/util.cxx b/src/util.cxx index d32eca67b..84610b59a 100644 --- a/src/util.cxx +++ b/src/util.cxx @@ -70,14 +70,14 @@ void pqxx::internal::CheckUniqueRegistration(const namedclass *New, const namedclass *Old) { if (New == nullptr) - throw internal_error("null pointer registered"); + throw internal_error{"null pointer registered."}; if (Old) { if (Old == New) - throw usage_error("Started twice: " + New->description()); - throw usage_error( + throw usage_error{"Started twice: " + New->description()}; + throw usage_error{ "Started " + New->description() + " while " + Old->description() + - " still active"); + " still active."}; } } @@ -88,14 +88,14 @@ void pqxx::internal::CheckUniqueUnregistration(const namedclass *New, if (New != Old) { if (New == nullptr) - throw usage_error( + throw usage_error{ "Expected to close " + Old->description() + ", " - "but got null pointer instead"); + "but got null pointer instead."}; if (Old == nullptr) - throw usage_error("Closed while not open: " + New->description()); - throw usage_error( + throw usage_error{"Closed while not open: " + New->description()}; + throw usage_error{ "Closed " + New->description() + "; " - "expected to close " + Old->description()); + "expected to close " + Old->description()}; } } diff --git a/test/test00.cxx b/test/test00.cxx index 5942241e8..60f6e5632 100644 --- a/test/test00.cxx +++ b/test/test00.cxx @@ -99,7 +99,7 @@ void test_000(transaction_base &) strconv("long", long_min, lminstr.str()); strconv("long", long_max, lmaxstr.str()); strconv("double", not_a_number, "nan"); - strconv("string", string(), ""); + strconv("string", string{}, ""); strconv("string", weirdstr, weirdstr); strconv("long long", 0LL, "0"); strconv("long long", llong_min, llminstr.str()); diff --git a/test/test01.cxx b/test/test01.cxx index a9b388cc3..d93ae4073 100644 --- a/test/test01.cxx +++ b/test/test01.cxx @@ -36,7 +36,7 @@ void test_001(transaction_base &trans) // Dump row number and column 0 value to cout. Read the value using // as(), which converts the field to the same type as the default value // you give it (or returns the default value if the field is null). - cout << '\t' << to_string(c.num()) << '\t' << c[0].as(string()) << endl; + cout << '\t' << to_string(c.num()) << '\t' << c[0].as(string{}) << endl; } T.commit(); diff --git a/test/test11.cxx b/test/test11.cxx index 57347e059..a535773ad 100644 --- a/test/test11.cxx +++ b/test/test11.cxx @@ -52,12 +52,12 @@ void test_011(transaction_base &T) string N = R.column_name(c); PQXX_CHECK_EQUAL( - string(R[0].at(c).c_str()), + string{R[0].at(c).c_str()}, R[0].at(N).c_str(), "Field by name != field by number."); PQXX_CHECK_EQUAL( - string(R[0][c].c_str()), + string{R[0][c].c_str()}, R[0][N].c_str(), "at() is inconsistent with operator[]."); diff --git a/test/test12.cxx b/test/test12.cxx index 5764d7144..de8dad89d 100644 --- a/test/test12.cxx +++ b/test/test12.cxx @@ -55,7 +55,7 @@ void test_012(transaction_base &orgT) string A, B; PQXX_CHECK_EQUAL( i[f].to(A), - i[f].to(B, string("")), + i[f].to(B, string{""}), "Variants of to() disagree on nullness."); PQXX_CHECK_EQUAL(A, B, "Inconsistent field contents."); @@ -107,8 +107,8 @@ void test_012(transaction_base &orgT) U = SortedUp[f], D = SortedDown[f]; - SortedUp[f] = U & (string(j[f].c_str()) <= string(i[f].c_str())); - SortedDown[f] = D & (string(j[f].c_str()) >= string(i[f].c_str())); + SortedUp[f] = U & (string{j[f].c_str()} <= string{i[f].c_str()}); + SortedDown[f] = D & (string{j[f].c_str()} >= string{i[f].c_str()}); } } } diff --git a/test/test14.cxx b/test/test14.cxx index d7927ee8f..7ee8a631b 100644 --- a/test/test14.cxx +++ b/test/test14.cxx @@ -25,7 +25,7 @@ void test_014(transaction_base &orgT) // These simply pass the notice through to their connection, but this may // be more convenient in some cases. All ProcessNotice() functions accept // C++ strings as well as C strings. - T.process_notice(string("Started nontransaction\n")); + T.process_notice(string{"Started nontransaction\n"}); result R( T.exec("SELECT * FROM pg_tables") ); diff --git a/test/test21.cxx b/test/test21.cxx index 85c5168f0..907596a3b 100644 --- a/test/test21.cxx +++ b/test/test21.cxx @@ -15,7 +15,7 @@ void test_021(transaction_base &) lazyconnection C; C.process_notice("Printing details on deferred connection\n"); const string HostName = (C.hostname() ? C.hostname() : ""); - C.process_notice(string() + + C.process_notice(string{} + "database=" + C.dbname() + ", " "username=" + C.username() + ", " "hostname=" + HostName + ", " @@ -27,7 +27,7 @@ void test_021(transaction_base &) // By now our connection should really have been created C.process_notice("Printing details on actual connection\n"); - C.process_notice(string() + + C.process_notice(string{} + "database=" + C.dbname() + ", " "username=" + C.username() + ", " "hostname=" + HostName + ", " diff --git a/test/test30.cxx b/test/test30.cxx index 2db3be56a..12482d7e3 100644 --- a/test/test30.cxx +++ b/test/test30.cxx @@ -58,12 +58,12 @@ void test_030(transaction_base &) string N = R.column_name(c); PQXX_CHECK_EQUAL( - string(R[0].at(c).c_str()), + string{R[0].at(c).c_str()}, R[0].at(N).c_str(), "Different field values by name and by number."); PQXX_CHECK_EQUAL( - string(R[0][c].c_str()), + string{R[0][c].c_str()}, R[0][N].c_str(), "at() is inconsistent with operator[]."); diff --git a/test/test31.cxx b/test/test31.cxx index a72465ad7..b63e3a459 100644 --- a/test/test31.cxx +++ b/test/test31.cxx @@ -68,7 +68,7 @@ void test_031(transaction_base &orgT) string A, B; PQXX_CHECK_EQUAL( i[f].to(A), - i[f].to(B, string("")), + i[f].to(B, string{""}), "Variants of to() disagree on nullness."); PQXX_CHECK_EQUAL(A, B, "Variants of to() produce different values."); @@ -119,8 +119,8 @@ void test_031(transaction_base &orgT) const bool U = SortedUp[f], D = SortedDown[f]; - SortedUp[f] = U & (string(j[f].c_str()) <= string(i[f].c_str())); - SortedDown[f] = D & (string(j[f].c_str()) >= string(i[f].c_str())); + SortedUp[f] = U & (string{j[f].c_str()} <= string{i[f].c_str()}); + SortedDown[f] = D & (string{j[f].c_str()} >= string{i[f].c_str()}); } } } diff --git a/test/test46.cxx b/test/test46.cxx index 6dfb69ab3..18d1d9a57 100644 --- a/test/test46.cxx +++ b/test/test46.cxx @@ -52,7 +52,7 @@ void test_046(transaction_base &T) string S, S2, S3; from_string(R[0].c_str(), S); - from_string(string(R[0].c_str()), S2); + from_string(string{R[0].c_str()}, S2); from_string(R[0], S3); PQXX_CHECK_EQUAL( diff --git a/test/test49.cxx b/test/test49.cxx index cac0245fe..ecdfc7c72 100644 --- a/test/test49.cxx +++ b/test/test49.cxx @@ -11,7 +11,7 @@ using namespace pqxx; // Test program for libpqxx. Run a query and try various standard C++ -// algorithms on it. +// algorithms on its result. namespace { @@ -49,7 +49,7 @@ struct Cmp bool operator()(const pqxx::row &L, const pqxx::row &R) const { - return string(L[Key].c_str()) < string(R[Key].c_str()); + return string{L[Key].c_str()} < string{R[Key].c_str()}; } }; diff --git a/test/test51.cxx b/test/test51.cxx index 9827e9600..c5c957dc4 100644 --- a/test/test51.cxx +++ b/test/test51.cxx @@ -38,7 +38,7 @@ void test_051(transaction_base &orgT) "Unexpected read() result."); PQXX_CHECK_EQUAL( - string(Buf, Contents.size()), + std::string(Buf, Contents.size()), Contents, "Large object contents were mutilated."); @@ -57,7 +57,7 @@ void test_051(transaction_base &orgT) "Bad length for rewritten large object."); PQXX_CHECK_EQUAL( - string(Buf, Contents.size()), + std::string(Buf, Contents.size()), Contents, "Rewritten large object was mangled."); diff --git a/test/test53.cxx b/test/test53.cxx index b09686e70..5bd7026a0 100644 --- a/test/test53.cxx +++ b/test/test53.cxx @@ -32,7 +32,7 @@ void test_053(transaction_base &orgT) { char Buf[200]; work tx{C}; - largeobjectaccess O(tx, Obj, ios::in); + largeobjectaccess O{tx, Obj, ios::in}; const auto len = O.read(Buf, sizeof(Buf)-1); PQXX_CHECK_EQUAL( string(Buf, string::size_type(len)), diff --git a/test/test55.cxx b/test/test55.cxx index 4400586f9..0ddbc5e68 100644 --- a/test/test55.cxx +++ b/test/test55.cxx @@ -23,7 +23,7 @@ void test_055(transaction_base &orgT) { char Buf[200]; work tx{C}; - largeobjectaccess A(tx, "pqxxlo.txt", ios::in); + largeobjectaccess A{tx, "pqxxlo.txt", ios::in}; auto new_obj = largeobject(A); const auto len = A.read(Buf, sizeof(Buf)-1); PQXX_CHECK_EQUAL( diff --git a/test/test63.cxx b/test/test63.cxx index 03d505362..27bd6da4f 100644 --- a/test/test63.cxx +++ b/test/test63.cxx @@ -17,7 +17,7 @@ void test_063(transaction_base &T) PQXX_CHECK(not R.empty(), "No tables found. Cannot test."); for (const auto &c: R) - cout << '\t' << to_string(c.num()) << '\t' << c[0].as(string()) << endl; + cout << '\t' << to_string(c.num()) << '\t' << c[0].as(string{}) << endl; T.commit(); } diff --git a/test/test67.cxx b/test/test67.cxx index ff9bdd8d5..db301126f 100644 --- a/test/test67.cxx +++ b/test/test67.cxx @@ -66,7 +66,7 @@ void test_067(transaction_base &orgT) string A, B; PQXX_CHECK_EQUAL( i[f].to(A), - i[f].to(B, string("")), + i[f].to(B, string{""}), "Variants of to() disagree on nullness."); PQXX_CHECK_EQUAL(A, B, "to() variants return different values."); diff --git a/test/test92.cxx b/test/test92.cxx index 01bb05c07..ac1fc329c 100644 --- a/test/test92.cxx +++ b/test/test92.cxx @@ -37,7 +37,7 @@ void test_092(transaction_base &T) const binarystring roundtrip(R[0][0]); - PQXX_CHECK_EQUAL(string(roundtrip.str()), data, "Data came back different."); + PQXX_CHECK_EQUAL(string{roundtrip.str()}, data, "Data came back different."); PQXX_CHECK_EQUAL(roundtrip.size(), data.size(), diff --git a/test/test_helpers.hxx b/test/test_helpers.hxx index b56abb1a2..9f36585e5 100644 --- a/test/test_helpers.hxx +++ b/test/test_helpers.hxx @@ -237,13 +237,13 @@ inline void end_of_statement() catch (const pqxx::test::failure_to_fail &) \ { \ PQXX_CHECK_NOTREACHED( \ - std::string(desc) + " (\"" #action "\" did not throw)"); \ + std::string{desc} + " (\"" #action "\" did not throw)"); \ } \ catch (const std::exception &) {} \ catch (...) \ { \ PQXX_CHECK_NOTREACHED( \ - std::string(desc) + \ + std::string{desc} + \ " (\"" #action "\" threw non-exception type)"); \ } \ } \ @@ -260,14 +260,14 @@ inline void end_of_statement() catch (const pqxx::test::failure_to_fail &) \ { \ PQXX_CHECK_NOTREACHED( \ - std::string(desc) + \ + std::string{desc} + \ " (\"" #action "\" did not throw " #exception_type ")"); \ } \ catch (const exception_type &) {} \ catch (const std::exception &e) \ { \ PQXX_CHECK_NOTREACHED( \ - std::string(desc) + \ + std::string{desc} + \ " (\"" #action "\" " \ "threw exception other than " #exception_type ": " + \ e.what() + ")"); \ @@ -275,7 +275,7 @@ inline void end_of_statement() catch (...) \ { \ PQXX_CHECK_NOTREACHED( \ - std::string(desc) + \ + std::string{desc} + \ " (\"" #action "\" threw non-exception type)"); \ } \ } \ @@ -305,9 +305,9 @@ inline void check_bounds( const std::string &desc) { const std::string - range_check = std::string(lower_text) + " < " + upper_text, - lower_check = std::string("!(") + text + " < " + lower_text + ")", - upper_check = std::string(text) + " < " + upper_text; + range_check = std::string{lower_text} + " < " + upper_text, + lower_check = std::string{"!("} + text + " < " + lower_text + ")", + upper_check = std::string{text} + " < " + upper_text; pqxx::test::check( file, diff --git a/test/unit/test_errorhandler.cxx b/test/unit/test_errorhandler.cxx index 5dbf39bd7..4e5691d8f 100644 --- a/test/unit/test_errorhandler.cxx +++ b/test/unit/test_errorhandler.cxx @@ -22,7 +22,7 @@ class TestErrorHandler final : public errorhandler virtual bool operator()(const char msg[]) noexcept override { - message = string(msg); + message = string{msg}; handler_list.push_back(this); return return_value; } diff --git a/test/unit/test_escape.cxx b/test/unit/test_escape.cxx index 10d61b1c6..511e24983 100644 --- a/test/unit/test_escape.cxx +++ b/test/unit/test_escape.cxx @@ -9,7 +9,7 @@ namespace { void compare_esc(connection_base &c, transaction_base &t, const char str[]) { - const size_t len = string(str).size(); + const size_t len = string{str}.size(); PQXX_CHECK_EQUAL(c.esc(str, len), t.esc(str, len), "Connection & transaction escape differently."); @@ -18,7 +18,7 @@ void compare_esc(connection_base &c, transaction_base &t, const char str[]) t.esc(str), "Length argument to esc() changes result."); - PQXX_CHECK_EQUAL(t.esc(string(str)), + PQXX_CHECK_EQUAL(t.esc(string{str}), t.esc(str), "esc(std::string()) differs from esc(const char[])."); @@ -53,7 +53,7 @@ void test_quote(connection_base &c, transaction_base &t) PQXX_CHECK_EQUAL(t.quote(0), "'0'", "Quoting zero is a problem."); const char *const null_ptr = nullptr; PQXX_CHECK_EQUAL(t.quote(null_ptr), "NULL", "Not quoting NULL correctly."); - PQXX_CHECK_EQUAL(t.quote(string("'")), "''''", "Escaping quotes goes wrong."); + PQXX_CHECK_EQUAL(t.quote(string{"'"}), "''''", "Escaping quotes goes wrong."); PQXX_CHECK_EQUAL(t.quote("x"), c.quote("x"), @@ -90,7 +90,7 @@ void test_quote_name(transaction_base &t) t.quote_name("A b"), "Escaped identifier is not as expected."); PQXX_CHECK_EQUAL( - string("A b"), + string{"A b"}, t.exec("SELECT 1 AS " + t.quote_name("A b")).column_name(0), "Escaped identifier does not work in SQL."); } diff --git a/test/unit/test_prepared_statement.cxx b/test/unit/test_prepared_statement.cxx index 3e3452bad..77258e933 100644 --- a/test/unit/test_prepared_statement.cxx +++ b/test/unit/test_prepared_statement.cxx @@ -153,7 +153,7 @@ void test_legacy_prepared_statement(transaction_base &T) // Test prepared statement with a binary parameter. C.prepare("GimmeBinary", "SELECT $1::bytea"); - const binarystring bin_data(string("x \x01 \x02 \xff y")); + const binarystring bin_data{string{"x \x01 \x02 \xff y"}}; PQXX_CHECK_EQUAL( binarystring(T.prepared("GimmeBinary")(bin_data).exec()[0][0]).str(), @@ -292,7 +292,7 @@ void test_strings(transaction_base &T) string(nasty_string), "Prepared statement did not quote/escape correctly."); - rw = T.exec_prepared1("EchoStr", string(nasty_string)); + rw = T.exec_prepared1("EchoStr", string{nasty_string}); PQXX_CHECK_EQUAL( rw.front().as(), string(nasty_string), diff --git a/test/unit/test_stream_from.cxx b/test/unit/test_stream_from.cxx index 728885ee9..2c97569d1 100644 --- a/test/unit/test_stream_from.cxx +++ b/test/unit/test_stream_from.cxx @@ -61,7 +61,7 @@ void test_nonoptionals(pqxx::connection_base& connection) catch (const pqxx::conversion_error &e) { std::string what{e.what()}; - if (what != "Attempt to convert null to int") throw; + if (what != "Attempt to convert null to int.") throw; pqxx::test::expected_exception("Could not extract row: " + what); }