aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/sqlitestudiocli/commands/clicommandsql.h
blob: 192106321329e646cb510789b629016f49247397 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef CLICOMMANDSQL_H
#define CLICOMMANDSQL_H

#include "clicommand.h"
#include "db/sqlquery.h"

class QueryExecutor;

class CliCommandSql : public CliCommand
{
        Q_OBJECT

    public:
        void execute();
        QString shortHelp() const;
        QString fullHelp() const;
        bool isAsyncExecution() const;
        void defineSyntax();

    private:
        class SortedColumnWidth
        {
            public:
                SortedColumnWidth();

                bool operator<(const SortedColumnWidth& other);

                int getHeaderWidth() const;
                void setHeaderWidth(int value);
                void setMaxHeaderWidth(int value);
                void incrHeaderWidth(int value = 1);
                void decrHeaderWidth(int value = 1);

                int getDataWidth() const;
                void setDataWidth(int value);
                void setMinDataWidth(int value);
                void incrDataWidth(int value = 1);
                void decrDataWidth(int value = 1);

                void incrWidth(int value = 0);
                int getWidth() const;
                bool isHeaderLonger() const;

            private:
                void updateWidth();

                int width;
                int headerWidth;
                int dataWidth;
        };

        void printResultsClassic(QueryExecutor *executor, SqlQueryPtr results);
        void printResultsFixed(QueryExecutor *executor, SqlQueryPtr results);
        void printResultsColumns(QueryExecutor *executor, SqlQueryPtr results);
        void printResultsRowByRow(QueryExecutor *executor, SqlQueryPtr results);
        void shrinkColumns(QList<SortedColumnWidth*>& columnWidths, int termCols, int resultColumnsCount, int totalWidth);
        void printColumnHeader(const QList<int>& widths, const QStringList& columns);
        void printColumnDataRow(const QList<int>& widths, const SqlResultsRowPtr& row, int rowIdCount);

        QString getValueString(const QVariant& value);

    private slots:
        void executionFailed(int code, const QString& msg);
};

#endif // CLICOMMANDSQL_H