123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- #ifndef MYSQLX_RESULT_H
- #define MYSQLX_RESULT_H
- #include "common.h"
- #include "document.h"
- #include "row.h"
- #include "collations.h"
- #include "detail/result.h"
- namespace mysqlx {
- using std::ostream;
- class Session;
- class Schema;
- class Collection;
- class Result;
- class Row;
- class RowResult;
- class SqlResult;
- class DbDoc;
- class DocResult;
- template <class Res, class Op> class Executable;
- namespace internal {
- template <class Base>
- class Result_common
- : protected Base
- {
- using WarningList = internal::Result_detail::WarningList;
- public:
-
- unsigned getWarningsCount() const
- {
- try {
- return Base::get_warning_count();
- }
- CATCH_AND_WRAP
- }
-
- WarningList getWarnings()
- {
- try {
- return Base::get_warnings();
- }
- CATCH_AND_WRAP
- }
-
-
- Warning getWarning(unsigned pos)
- {
- try {
- return Base::get_warning(pos);
- }
- CATCH_AND_WRAP
- }
-
-
-
- uint64_t getAffectedItemsCount() const
- {
- try {
- return Result_detail::get_affected_rows();
- } CATCH_AND_WRAP
- }
- protected:
-
- Result_common()
- try
- : Base()
- {}
- CATCH_AND_WRAP
- Result_common(Result_common &&other)
- try
- : Base(std::move(other))
- {}
- CATCH_AND_WRAP
- Result_common& operator=(Result_common &&other)
- try
- {
- Base::operator=(std::move(other));
- return *this;
- }
- CATCH_AND_WRAP
- Result_common(common::Result_init &init)
- try
- : Base(init)
- {}
- CATCH_AND_WRAP
- };
- }
- class Result
- : public internal::Result_common<internal::Result_detail>
- {
- public:
- Result() = default;
-
- uint64_t getAutoIncrementValue() const
- {
- try {
- return Result_detail::get_auto_increment();
- } CATCH_AND_WRAP
- }
-
- DocIdList getGeneratedIds() const
- {
- try {
- return Result_detail::get_generated_ids();
- } CATCH_AND_WRAP
- }
- private:
- Result(common::Result_init &init)
- : Result_common(init)
- {}
- template <class Res, class Op>
- friend class Executable;
- friend Collection;
- };
- enum class Type : unsigned short
- {
- #undef TYPE_ENUM
- #define TYPE_ENUM(X,N) X=N,
- RESULT_TYPE_LIST(TYPE_ENUM)
- };
- inline
- const char* typeName(Type t)
- {
- #define TYPE_NAME(T,X) case Type::T: return #T;
- switch (t)
- {
- RESULT_TYPE_LIST(TYPE_NAME)
- default:
- THROW("Unknown type");
- }
- }
- inline
- std::ostream& operator<<(std::ostream &out, Type t)
- {
- return out << typeName(t);
- }
- class Column
- : public virtual common::Printable
- , private internal::Column_detail
- {
- public:
- string getSchemaName() const
- {
- try {
- return Column_detail::get_schema_name();
- }
- CATCH_AND_WRAP
- }
- string getTableName() const
- {
- try {
- return Column_detail::get_table_name();
- }
- CATCH_AND_WRAP
- }
- string getTableLabel() const
- {
- try {
- return Column_detail::get_table_label();
- }
- CATCH_AND_WRAP
- }
- string getColumnName() const
- {
- try {
- return Column_detail::get_name();
- }
- CATCH_AND_WRAP
- }
- string getColumnLabel() const
- {
- try {
- return Column_detail::get_label();
- }
- CATCH_AND_WRAP
- }
- Type getType() const
- {
- try {
- return Type(Column_detail::get_type());
- }
- CATCH_AND_WRAP
- }
-
- unsigned long getLength() const
- {
- try {
- return Column_detail::get_length();
- }
- CATCH_AND_WRAP
- }
- unsigned short getFractionalDigits() const
- {
- try {
- return Column_detail::get_decimals();
- }
- CATCH_AND_WRAP
- }
- bool isNumberSigned() const
- {
- try {
- return Column_detail::is_signed();
- }
- CATCH_AND_WRAP
- }
- CharacterSet getCharacterSet() const
- {
- try {
- return Column_detail::get_charset();
- }
- CATCH_AND_WRAP
- }
-
- std::string getCharacterSetName() const
- {
- try {
- return characterSetName(getCharacterSet());
- }
- CATCH_AND_WRAP
- }
- const CollationInfo& getCollation() const
- {
- try {
- return Column_detail::get_collation();
- }
- CATCH_AND_WRAP
- }
-
- std::string getCollationName() const
- {
- try {
- return getCollation().getName();
- }
- CATCH_AND_WRAP
- }
-
- bool isPadded() const
- {
- try {
- return Column_detail::is_padded();
- }
- CATCH_AND_WRAP
- }
- protected:
- using Column_detail::Impl;
- Column(const Impl &impl)
- try
- : Column_detail(impl)
- {}
- CATCH_AND_WRAP
- Column() = default;
- Column(const Column&) = default;
- Column(Column&&) = default;
- Column& operator=(const Column&) = default;
- void print(std::ostream &out) const
- {
-
- try {
- Column_detail::print(out);
- }
- CATCH_AND_WRAP
- }
- public:
- friend RowResult;
- struct INTERNAL Access;
- friend Access;
- };
- namespace internal {
- template<> PUBLIC_API
- void Columns_detail<Column>::init(const Result_detail::Impl&);
- }
- extern template PUBLIC_API
- void internal::Columns_detail<Column>::init(
- const internal::Result_detail::Impl &impl
- );
- class Columns
- : private internal::Columns_detail<Column>
- {
- public:
- using Columns_detail::operator[];
- using Columns_detail::iterator;
- using Columns_detail::begin;
- using Columns_detail::end;
- private:
- using Columns_detail::init;
-
- Columns() = default;
- Columns(Columns&&) = default;
- Columns& operator=(Columns&&) = default;
-
- friend internal::Row_result_detail<Columns>;
-
- };
- namespace internal {
- template<> PUBLIC_API
- bool Row_result_detail<Columns>::iterator_next();
- template<> PUBLIC_API
- col_count_t Row_result_detail<Columns>::col_count() const;
- template<> PUBLIC_API
- Row_result_detail<Columns>::Row_result_detail(
- common::Result_init &init
- );
- template<> PUBLIC_API
- auto Row_result_detail<Columns>::get_column(col_count_t pos) const
- -> const Column&;
- template<> PUBLIC_API
- auto internal::Row_result_detail<Columns>::get_columns() const
- -> const Columns&;
- template<> PUBLIC_API
- row_count_t internal::Row_result_detail<Columns>::row_count();
- }
- class RowResult
- : public internal::Result_common<internal::Row_result_detail<Columns>>
- {
- public:
- using Columns = mysqlx::Columns;
- RowResult() = default;
-
- col_count_t getColumnCount() const
- {
- try {
- return Row_result_detail::col_count();
- }
- CATCH_AND_WRAP
- }
-
- const Column& getColumn(col_count_t pos) const
- {
- try {
- return Row_result_detail::get_column(pos);
- }
- CATCH_AND_WRAP
- }
-
- const Columns& getColumns() const
- {
- try {
- return Row_result_detail::get_columns();
- }
- CATCH_AND_WRAP
- }
-
- Row fetchOne()
- {
- try {
- return Row_result_detail::get_row();
- }
- CATCH_AND_WRAP
- }
- using iterator = RowList::iterator;
-
- RowList fetchAll()
- {
- try {
- return Row_result_detail::get_rows();
- }
- CATCH_AND_WRAP
- }
-
- row_count_t count()
- {
- try {
- return Row_result_detail::row_count();
- }
- CATCH_AND_WRAP
- }
-
- iterator begin()
- {
- try {
- return Row_result_detail::begin();
- }
- CATCH_AND_WRAP
- }
- iterator end() const
- {
- try {
- return Row_result_detail::end();
- }
- CATCH_AND_WRAP
- }
- private:
- RowResult(common::Result_init &init)
- : Result_common(init)
- {}
- public:
- template <class Res, class Op> friend class Executable;
- friend SqlResult;
- friend DocResult;
- };
- class SqlResult
- : public RowResult
- {
- public:
- SqlResult() = default;
-
- bool hasData() const
- {
- try {
- return Result_detail::has_data();
- }
- CATCH_AND_WRAP
- }
-
- bool nextResult()
- {
- try {
- return Row_result_detail::next_result();
- }
- CATCH_AND_WRAP
- }
-
- uint64_t getAutoIncrementValue()
- {
- try {
- return Result_detail::get_auto_increment();
- }
- CATCH_AND_WRAP
- }
- private:
- SqlResult(common::Result_init &init)
- : RowResult(init)
- {}
- template <class Res, class Op>
- friend class Executable;
- };
- class DocResult
- : public internal::Result_common<internal::Doc_result_detail>
- {
- public:
- DocResult() = default;
-
- DbDoc fetchOne()
- {
- try {
- return Doc_result_detail::get_doc();
- }
- CATCH_AND_WRAP
- }
-
- DocList fetchAll()
- {
- try {
- return Doc_result_detail::get_docs();
- }
- CATCH_AND_WRAP
- }
-
- uint64_t count()
- {
- try {
- return Doc_result_detail::count();
- }
- CATCH_AND_WRAP
- }
-
- using iterator = Doc_result_detail::iterator;
- iterator begin()
- {
- try {
- return Doc_result_detail::begin();
- }
- CATCH_AND_WRAP
- }
- iterator end() const
- {
- try {
- return Doc_result_detail::end();
- }
- CATCH_AND_WRAP
- }
- private:
- DocResult(common::Result_init &init)
- : Result_common(init)
- {}
- friend DbDoc;
- template <class Res,class Op>
- friend class Executable;
- };
- }
- #endif
|