From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- SQLiteStudio3/coreSQLiteStudio/db/sqlresultsrow.h | 102 ++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 SQLiteStudio3/coreSQLiteStudio/db/sqlresultsrow.h (limited to 'SQLiteStudio3/coreSQLiteStudio/db/sqlresultsrow.h') diff --git a/SQLiteStudio3/coreSQLiteStudio/db/sqlresultsrow.h b/SQLiteStudio3/coreSQLiteStudio/db/sqlresultsrow.h new file mode 100644 index 0000000..2a5e17c --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/db/sqlresultsrow.h @@ -0,0 +1,102 @@ +#ifndef SQLRESULTSROW_H +#define SQLRESULTSROW_H + +#include "coreSQLiteStudio_global.h" +#include +#include +#include +#include + +/** @file */ + +/** + * @brief SQL query results row. + * + * Single row of data from SQL query results. It already has all columns stored in memory, + * so it doesn't matter if you read only one column, or all columns available in the row. + * + * You will never encounter object of exactly this class, as it has protected constructor + * and has no methods to populate internal data members. Instead of creating objects of this class, + * other class inherits it and handles populating internal data members, then this class + * is just an interface to read data from it. + * + * In other words, it's kind of an abstract class. + */ +class API_EXPORT SqlResultsRow +{ + public: + /** + * @brief Releases resources. + */ + virtual ~SqlResultsRow(); + + /** + * @brief Gets value for given column. + * @param key Column name. + * @return Value from requested column. If column name is invalid, the invalid QVariant is returned. + */ + const QVariant value(const QString& key) const; + + /** + * @brief Gets value for given column. + * @param idx 0-based index of column. + * @return Value from requested column. If index was invalid, the invalid QVariant is returned. + */ + const QVariant value(int idx) const; + + /** + * @brief Gets table of column->value entries. + * @return Hash table with column names as keys and QVariants as their values. + * + * Note, that QHash doesn't guarantee order of entries. If you want to iterate through columns + * in order they were returned from the database, use valueList(), or iterate through SqlResults::getColumnNames() + * and use it to call value(). + */ + const QHash& valueMap() const; + + /** + * @brief Gets list of values in this row. + * @return Ordered list of values in the row. + * + * Note, that this method returns values in order they were returned from database. + */ + const QList& valueList() const; + + /** + * @brief Tests if the row contains given column name. + * @param key Column name. Case sensitive. + * @return true if column exists in the row, or false otherwise. + */ + bool contains(const QString& key) const; + + /** + * @brief Tests if the row has column indexed with given number. + * @param idx 0-based index to test. + * @return true if index is in range of existing columns, or false if it's greater than "number of columns - 1", or if it's less than 0. + */ + bool contains(int idx) const; + + protected: + SqlResultsRow(); + + /** + * @brief Columns and their values in the row. + */ + QHash valuesMap; + /** + * @brief Ordered list of values in the row. + * + * Technical note: + * We keep list of values next to valuesMap, so we have it in the same order as column names when asked by valueList(). + * This looks like having redundant data storage, but Qt container classes (such as QVariant) + * use smart pointers to keep their data internally, so here we actually keep only reference objects. + */ + QList values; +}; + +/** + * @brief Shared pointer to SQL query results row. + */ +typedef QSharedPointer SqlResultsRowPtr; + +#endif // SQLRESULTSROW_H -- cgit v1.2.3