File indexing completed on 2024-06-16 07:34:20

0001 /* This file is part of the KDE project
0002    Copyright (C) 2008-2010 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDB_PREPAREDSTATEMENT_IFACE_H
0021 #define KDB_PREPAREDSTATEMENT_IFACE_H
0022 
0023 #include <QSharedData>
0024 
0025 #include "KDbResult.h"
0026 #include "KDbPreparedStatement.h"
0027 
0028 class KDbSqlResult;
0029 
0030 //! Prepared statement interface for backend-dependent implementations.
0031 class KDB_EXPORT KDbPreparedStatementInterface : public KDbResultable
0032 {
0033 protected:
0034     KDbPreparedStatementInterface() {}
0035     ~KDbPreparedStatementInterface() override {}
0036 
0037     /*! For implementation. Initializes the prepared statement in a backend-dependent way
0038         using recently generated @a sql statement.
0039         It should be guaranteed that @a sql is valid and not empty.
0040         For example sqlite3_prepare() is used for SQLite.
0041         This is called only when d->dirty == true is encountered on execute(),
0042         i.e. when attributes of the object (like WHERE field names) change. */
0043     virtual bool prepare(const KDbEscapedString& sql) = 0;
0044 
0045     //! For implementation, executes the prepared statement
0046     //! Type of statement is specified by the @a type parameter.
0047     //! @a selectFieldList specifies fields for SELECT statement.
0048     //! @a insertFieldList is set to list of fields in INSERT statement.
0049     //! Parameters @a parameters are passed to the statement, usually using binding.
0050     virtual QSharedPointer<KDbSqlResult> execute(
0051         KDbPreparedStatement::Type type,
0052         const KDbField::List& selectFieldList,
0053         KDbFieldList* insertFieldList,
0054         const KDbPreparedStatementParameters& parameters) /*Q_REQUIRED_RESULT*/ = 0;
0055 
0056     friend class KDbConnection;
0057     friend class KDbPreparedStatement;
0058 private:
0059     Q_DISABLE_COPY(KDbPreparedStatementInterface)
0060 };
0061 
0062 #endif