AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ASqlQueryResult.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14
   15#include <AUI/Data.h>
   16#include "AUI/Common/SharedPtrTypes.h"
   17#include "ISqlDriverRow.h"
   18#include "ISqlDriverResult.h"
   19#include "AUI/Common/AVariant.h"
   20
   21class API_AUI_DATA ASqlQueryResult
   22{
   23    friend class ASqlDatabase;
   24private:
   25    _<ISqlDriverResult> mDriverInterface;
   26
   27
   28    explicit ASqlQueryResult(const _<ISqlDriverResult>& sql_driver_result)
   29        : mDriverInterface(sql_driver_result)
   30    {
   31    }
   32
   33public:
   34
   35    class Iterator
   36    {
   37        friend class ASqlQueryResult;
   38    private:
   39        _<ISqlDriverResult> mResult;
   40        _<ISqlDriverRow> mRow;
   41
   42    public:
   43        explicit Iterator(const _<ISqlDriverResult>& sql);
   44
   45        Iterator& operator++()
   46        {
   47            mRow = mResult->next(mRow);
   48            return *this;
   49        }
   50
   51        bool operator!=(const Iterator& other) const
   52        {
   53            return mRow != other.mRow;
   54        }
   55        bool operator==(const Iterator& other) const
   56        {
   57            return mRow == other.mRow;
   58        }
   59
   60        Iterator& operator*()
   61        {
   62            return *this;
   63        }
   64        const Iterator& operator*() const
   65        {
   66            return *this;
   67        }
   68        Iterator* operator->()
   69        {
   70            return this;
   71        }
   72
   73        AVariant getValue(size_t index) const
   74        {
   75            return mRow->getValue(index);
   76        }
   77
   78        AVector<AVariant> range(size_t count) const {
   79            AVector<AVariant> v;
   80            for (size_t i = 0; i < count; ++i) {
   81                v << getValue(i);
   82            }
   83            return v;
   84        }
   85    };
   86
   87    Iterator begin() const;
   88    Iterator end() const;
   89
   90    size_t getRowCount() const;
   91    const AVector<SqlColumn>& getColumns() const;
   92};
Definition ASqlQueryResult.h:36
A std::vector with AUI extensions.
Definition AVector.h:39
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179