KDb

KDbSqlResult.h
1/* This file is part of the KDE project
2 Copyright (C) 2016 Jarosław Staniek <staniek@kde.org>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KDB_SQLRESULT_H
21#define KDB_SQLRESULT_H
22
23#include "kdb_export.h"
24#include <QSharedPointer>
25#include <QString>
26
27class KDbConnection;
28class KDbField;
29class KDbRecordData;
30class KDbResult;
31class KDbSqlField;
32class KDbSqlRecord;
33
34/**
35 * The KDbSqlResult class abstracts result of a raw SQL query preparation by KDbConnection::prepareSql()
36 *
37 * The KDbSqlResult object provides low-level access to information about fields of the result and
38 * can fetch records by actual execution of the prepared query.
39 *
40 * @note the KDbSqlResult object should be deleted before closing the database connection that
41 * created it. This is needed because the connection is used by the object to retrieve data or to
42 * obtain status information.
43 */
44class KDB_EXPORT KDbSqlResult
45{
46public:
48
49 virtual ~KDbSqlResult();
50
51 //! @return connection for this result
52 virtual KDbConnection *connection() const { return nullptr; }
53
54 //! @return number of fields in this result
55 virtual int fieldsCount() = 0;
56
57 //! @return field @a index from this result
58 virtual KDbSqlField *field(int index) /*Q_REQUIRED_RESULT*/ = 0;
59
60 //! Creates a KDb field for field @a index and returns it
61 //! On failure returns @c nullptr.
62 //! @a tableName is the table name and may be used to retrieve information but may
63 //! be ignored as well if the KDbSqlResult already has field metadata available.
64 virtual KDbField* createField(const QString &tableName, int index) /*Q_REQUIRED_RESULT*/ = 0;
65
66 /**
67 * Fetches one record.
68 *
69 * @return a shared pointer to the record or a null pointer if there is no record to fetch or
70 * on error.
71 * Check lastResult() for detailed result. Ownership is transferred to the caller.
72 */
73 virtual QSharedPointer<KDbSqlRecord> fetchRecord() /*Q_REQUIRED_RESULT*/ = 0;
74
75 //! Convenience method. Fetches one record and all values into @a data.
76 //! @return record data object and passes its ownership
77 //! @c nullptr is returned on error or when there is no record to fetch.
78 //! Check lastResult() for errors.
79 Q_REQUIRED_RESULT KDbRecordData *fetchRecordData();
80
81 //! @return result of last operation on this SQL result
82 virtual KDbResult lastResult() = 0;
83
84 /*! @return unique identifier of the most recently inserted record.
85 Typically this is just primary key value. This identifier could be reused when we want
86 to reference just inserted record. If there was no insertion recently performed for
87 the result, std::numeric_limits<quint64>::max() is returned. */
88 virtual quint64 lastInsertRecordId() { return std::numeric_limits<quint64>::max(); }
89private:
90 Q_DISABLE_COPY(KDbSqlResult)
91};
92
93#endif
Provides database connection, allowing queries and data modification.
Meta-data for a field.
Definition KDbField.h:72
Structure for storing single record with type information.
The KDbSqlField class abstracts low-level information about a single field for KDbSqlResult.
Definition KDbSqlField.h:28
The KDbSqlRecord class abstracts a single record obtained from a KDbSqlResult object.
The KDbSqlResult class abstracts result of a raw SQL query preparation by KDbConnection::prepareSql()
virtual KDbResult lastResult()=0
virtual KDbField * createField(const QString &tableName, int index)=0
Creates a KDb field for field index and returns it On failure returns nullptr.
virtual quint64 lastInsertRecordId()
virtual QSharedPointer< KDbSqlRecord > fetchRecord()=0
Fetches one record.
virtual KDbSqlField * field(int index)=0
virtual int fieldsCount()=0
virtual KDbConnection * connection() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:01:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.