[go: up one dir, main page]

File: totableselect.cpp

package info (click to toggle)
tora 1.3.21-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 14,252 kB
  • ctags: 10,397
  • sloc: cpp: 108,822; sh: 10,861; makefile: 766; xml: 69; perl: 6
file content (87 lines) | stat: -rw-r--r-- 2,429 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "utils.h"

#include "toconnection.h"
#include "toresultcombo.h"
#include "totableselect.h"

#include <qlabel.h>

#include "totableselect.moc"

void toTableSelect::setup()
{
    setTitle(tr("Table selection"));
    setColumnLayout(1, Vertical);
    bool mysql = false;
    try
    {
        mysql = toIsMySQL(toCurrentConnection(this));
    }
    catch (...)
    {}
    QLabel *label = new QLabel(mysql ? tr("Database") : tr("Schema"), this);
    label->show();
    Schema = new toResultCombo(this);
    Schema->show();
    Schema->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    label = new QLabel(tr("Table"), this);
    label->show();
    Table = new toResultCombo(this);
    Table->show();
    Table->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));

    Schema->additionalItem(mysql ? tr("Select database") : tr("Select schema"));
    Schema->query(toSQL::sql(toSQL::TOSQL_USERLIST));
    Table->additionalItem(tr("Select table"));
    Table->setSQL(toSQL::sql("toBrowser:ListTables"));

    Schema->refresh();
    if (!SelectedTable.isNull())
        setTable(SelectedTable);
    connect(Schema, SIGNAL(activated(int)), this, SLOT(changeSchema()));
    connect(Table, SIGNAL(activated(int)), this, SLOT(changeTable()));
}

toTableSelect::toTableSelect(QWidget *parent, const char *name)
        : QGroupBox(parent, name)
{
    Schema = Table = NULL;
    QTimer::singleShot(1, this, SLOT(setup()));
}

void toTableSelect::setTable(const QString &table)
{
    if (!Table || !Schema)
        SelectedTable = table;
    else
    {
        QStringList parts = QStringList::split(".", table);
        toConnection &conn = toCurrentConnection(this);
        if (parts.size() > 1)
        {
            Schema->setSelected(conn.unQuote(parts[0]));
            Table->setSelected(conn.unQuote(parts[1]));
        }
        else
            Schema->setSelected(conn.unQuote(table));
        Table->changeParams(Schema->selected());
    }
}

void toTableSelect::changeSchema(void)
{
    if (Schema->currentItem() != 0)
        Table->changeParams(Schema->selected());
}

void toTableSelect::changeTable(void)
{
    if (Table->currentItem() != 0)
    {
        toConnection &conn = toCurrentConnection(this);
        QString table = conn.quote(Schema->selected());
        table += ".";
        table += conn.quote(Table->selected());
        emit selectTable(table);
    }
}