File indexing completed on 2024-05-05 16:47:14

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005 Adam Pigg <adam@piggz.co.uk>
0003    Copyright (C) 2010-2012 Jarosław Staniek <staniek@kde.org>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This program is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this program; see the file COPYING.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "PostgresqlPreparedStatement.h"
0022 #include "KDbConnection.h"
0023 
0024 PostgresqlPreparedStatement::PostgresqlPreparedStatement(PostgresqlConnectionInternal* conn)
0025         : KDbPreparedStatementInterface()
0026         , PostgresqlConnectionInternal(conn->connection)
0027 {
0028 }
0029 
0030 
0031 PostgresqlPreparedStatement::~PostgresqlPreparedStatement()
0032 {
0033 }
0034 
0035 bool PostgresqlPreparedStatement::prepare(const KDbEscapedString& sql)
0036 {
0037     Q_UNUSED(sql);
0038     return true;
0039 }
0040 
0041 QSharedPointer<KDbSqlResult> PostgresqlPreparedStatement::execute(
0042     KDbPreparedStatement::Type type, const KDbField::List &selectFieldList,
0043     KDbFieldList *insertFieldList, const KDbPreparedStatementParameters &parameters)
0044 {
0045     Q_UNUSED(selectFieldList);
0046     QSharedPointer<KDbSqlResult> result;
0047     if (type == KDbPreparedStatement::InsertStatement) {
0048         const int missingValues = insertFieldList->fieldCount() - parameters.count();
0049         KDbPreparedStatementParameters myParameters(parameters);
0050         if (missingValues > 0) {
0051     //! @todo can be more efficient
0052             for (int i = 0; i < missingValues; i++) {
0053                 myParameters.append(QVariant());
0054             }
0055         }
0056         result = connection->insertRecord(insertFieldList, myParameters);
0057     }
0058 //! @todo support select
0059     return result;
0060 }