PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/src/KDbTableOrQuerySchema.h

https://gitlab.com/LongAiR/KDb
C Header | 130 lines | 42 code | 26 blank | 62 comment | 0 complexity | 2cf3b89b37faa817a99690f8b0fa05f9 MD5 | raw file
  1. /* This file is part of the KDE project
  2. Copyright (C) 2004-2015 Jarosław Staniek <staniek@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef KDBTABLEORQUERYSCHEMA_H
  17. #define KDBTABLEORQUERYSCHEMA_H
  18. #include <QByteArray>
  19. #include "KDbQueryColumnInfo.h"
  20. class KDbConnection;
  21. class KDbFieldList;
  22. class KDbTableSchema;
  23. class KDbQuerySchema;
  24. /*! Variant class providing a pointer to table or query. */
  25. class KDB_EXPORT KDbTableOrQuerySchema
  26. {
  27. public:
  28. //! Type of object: table or query
  29. //! @since 3.1
  30. enum class Type {
  31. Table,
  32. Query
  33. };
  34. /*! Creates a new KDbTableOrQuerySchema variant object, retrieving table or query schema
  35. using @a conn connection and @a name. If both table and query exists for @a name,
  36. table has priority over query.
  37. Check whether a query or table has been found by testing (query() || table()) expression. */
  38. KDbTableOrQuerySchema(KDbConnection *conn, const QByteArray& name);
  39. /*! Creates a new KDbTableOrQuerySchema variant object, retrieving table or query schema
  40. using @a conn connection and @a name. If @a type is Table, @a name is assumed
  41. to be a table name, otherwise @a name is assumed to be a query name.
  42. Check whether a query or table has been found by testing (query() || table()) expression.
  43. @since 3.1 */
  44. KDbTableOrQuerySchema(KDbConnection *conn, const QByteArray &name, Type type);
  45. /*! Creates a new KDbTableOrQuerySchema variant object. @a tableOrQuery should be of
  46. class KDbTableSchema or KDbQuerySchema.
  47. Check whether a query or table has been found by testing (query() || table()) expression. */
  48. explicit KDbTableOrQuerySchema(KDbFieldList *tableOrQuery);
  49. /*! Creates a new KDbTableOrQuerySchema variant object, retrieving table or query schema
  50. using @a conn connection and @a id.
  51. Check whether a query or table has been found by testing (query() || table()) expression. */
  52. KDbTableOrQuerySchema(KDbConnection *conn, int id);
  53. /*! Creates a new KDbTableOrQuerySchema variant object, keeping a pointer to @a table
  54. object. */
  55. explicit KDbTableOrQuerySchema(KDbTableSchema* table);
  56. /*! Creates a new KDbTableOrQuerySchema variant object, keeping a pointer to @a query
  57. object. */
  58. explicit KDbTableOrQuerySchema(KDbQuerySchema* query);
  59. ~KDbTableOrQuerySchema();
  60. //! @return a pointer to the query if it's provided
  61. KDbQuerySchema* query() const;
  62. //! @return a pointer to the table if it's provided
  63. KDbTableSchema* table() const;
  64. //! @return name of a query or table
  65. QByteArray name() const;
  66. //! @return caption (if present) or name of the table/query
  67. QString captionOrName() const;
  68. /**
  69. * @brief Returns number of columns within record set returned from specified table or query
  70. *
  71. * In case of query expanded fields list is counted.
  72. * For tables @a conn is not required.
  73. * Returns -1 if the object has neither table or query assigned.
  74. * Returns -1 if the object has query assigned but @a conn is @c nullptr.
  75. */
  76. int fieldCount(KDbConnection *conn) const;
  77. /*! Mode for columns(). */
  78. enum class ColumnsMode {
  79. NonUnique, //!< Non-unique columns are returned
  80. Unique //!< Unique columns are returned
  81. };
  82. //! @return all columns for the table or the query
  83. const KDbQueryColumnInfo::Vector columns(KDbConnection *conn, ColumnsMode mode = ColumnsMode::NonUnique);
  84. /*! @return a field of the table or the query schema for name @a name
  85. or 0 if there is no such field. */
  86. KDbField* field(const QString& name);
  87. /*! Like KDbField* field(const QString& name);
  88. but returns all information associated with field/column @a name. */
  89. KDbQueryColumnInfo* columnInfo(KDbConnection *conn, const QString& name);
  90. private:
  91. class Private;
  92. Private * const d;
  93. Q_DISABLE_COPY(KDbTableOrQuerySchema)
  94. };
  95. //! A pair (connection, table-or-schema) for QDebug operator<<
  96. //! @since 3.1
  97. typedef std::tuple<KDbConnection*, const KDbTableOrQuerySchema&> KDbConnectionAndSchema;
  98. //! Sends information about table or query schema and connection @a connectionAndSchema to debug output @a dbg.
  99. //! @since 3.1
  100. KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbConnectionAndSchema &connectionAndSchema);
  101. #endif