File indexing completed on 2024-12-08 04:17:08

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003, 2006 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 SQLTYPES_H
0021 #define SQLTYPES_H
0022 
0023 #include <QVariant>
0024 #include <QList>
0025 
0026 #include "KDbExpression.h"
0027 #include "KDbOrderByColumn.h"
0028 
0029 struct dateType {
0030     int year;
0031     int month;
0032     int day;
0033 };
0034 
0035 struct realType {
0036     int integer;
0037     int fractional;
0038 };
0039 
0040 //! @internal
0041 struct OrderByColumnInternal
0042 {
0043     OrderByColumnInternal()
0044             : columnNumber(-1)
0045             , order(KDbOrderByColumn::SortOrder::Ascending) {
0046     }
0047 
0048     void setColumnByNameOrNumber(const QVariant& nameOrNumber) {
0049         if (nameOrNumber.type() == QVariant::String) {
0050             aliasOrName = nameOrNumber.toString();
0051             columnNumber = -1;
0052         } else {
0053             columnNumber = nameOrNumber.toInt();
0054             aliasOrName.clear();
0055         }
0056     }
0057 
0058     //! Can include a "tablename." prefix
0059     QString aliasOrName;
0060     //! Optional, used instead of aliasOrName to refer to column
0061     //! by its number rather than name.
0062     int columnNumber;
0063     KDbOrderByColumn::SortOrder order;
0064 };
0065 
0066 //! @internal
0067 struct SelectOptionsInternal {
0068     SelectOptionsInternal() : orderByColumns(nullptr) {}
0069     ~SelectOptionsInternal() {
0070         delete orderByColumns; // delete because this is internal temp. structure
0071     }
0072     KDbExpression whereExpr;
0073     QList<OrderByColumnInternal>* orderByColumns;
0074 };
0075 
0076 class KDbExpressionPtr
0077 {
0078 public:
0079     inline explicit KDbExpressionPtr(KDbExpression *exp) : e(exp) {}
0080     inline KDbExpression toExpr() {
0081         KDbExpression exp(*e);
0082         delete e;
0083         e = nullptr;
0084         return exp;
0085     }
0086     inline KDbNArgExpression toNArg() {
0087         KDbNArgExpression exp(e->toNArg());
0088         delete e;
0089         e = nullptr;
0090         return exp;
0091     }
0092 //private:
0093     KDbExpression *e;
0094 private:
0095     Q_DISABLE_COPY(KDbExpressionPtr)
0096 };
0097 
0098 QDebug operator<<(QDebug dbg, const KDbExpressionPtr& expr);
0099 
0100 #endif