void toStorageExtent::setTablespace(const QString &tablespace)
{
    fileView = false;
    try
    {
        if (Tablespace == tablespace)
            return ;
        Tablespace = tablespace;
        toBusy busy;
        Extents.clear();
        FileOffset.clear();
        toQuery query(toCurrentConnection(this), SQLObjectsTablespace, tablespace);

        // It's used to keep UI "non-freezed".
        // OK, there are better query classes for it but it's enough for now.
        // TODO: rewrite data fetching for this tool
        int progressMax = 1000;
        int progressCurr = 1;
        QProgressDialog progress("Reading Objects...", "Abort", 0, progressMax, this);

        extent cur;
        while (!query.eof())
        {
            if (progressCurr > (progressMax-1))
                progressCurr = 0;
            if (progressCurr % 200 == 0)
            {
                progress.setValue(progressCurr);
                QCoreApplication::processEvents();
            }
            if (progress.wasCanceled())
            {
                Extents.clear();
                break;
            }
            ++progressCurr;

            cur.Owner = query.readValueNull();
            cur.Table = query.readValueNull();
            cur.Partition = query.readValueNull();
            cur.File = query.readValueNull().toInt();
            cur.Block = query.readValueNull().toInt();
            cur.Size = query.readValueNull().toInt();
            toPush(Extents, cur);
        }
        toQuery blocks(toCurrentConnection(this), SQLTablespaceBlocks, tablespace);
        Total = 0;
        while (!blocks.eof())
        {
            int id = blocks.readValueNull().toInt();
            FileOffset[id] = Total;
            Total += blocks.readValueNull().toInt();
        }
    }
    TOCATCH
    Extents.sort();
    update();
}
void toStorageExtent::setFile(const QString &tablespace, int file)
{
    fileView = true;
    try
    {
        toBusy busy;
        Extents.clear();
        FileOffset.clear();
        toQuery query(toCurrentConnection(this), SQLObjectsFile, tablespace, QString::number(file));
        extent cur;

        int progressMax = 1000;
        int progressCurr = 1;
        QProgressDialog progress("Reading Objects...", "Abort", 0, progressMax, this);

        while (!query.eof())
        {
            if (progressCurr > (progressMax-1))
                progressCurr = 0;
            if (progressCurr % 200 == 0)
            {
                progress.setValue(progressCurr);
                QCoreApplication::processEvents();
            }
            if (progress.wasCanceled())
            {
                Extents.clear();
                break;
            }
            ++progressCurr;

            cur.Owner = query.readValueNull();
            cur.Table = query.readValueNull();
            cur.Partition = query.readValueNull();
            cur.File = query.readValueNull().toInt();
            cur.Block = query.readValueNull().toInt();
            cur.Size = query.readValueNull().toInt();
            toPush(Extents, cur);
        }
        toQuery blocks(toCurrentConnection(this), SQLFileBlocks, tablespace, QString::number(file));
        Total = 0;
        while (!blocks.eof())
        {
            int id = blocks.readValueNull().toInt();
            FileOffset[id] = Total;
            Total += blocks.readValueNull().toInt();
        }
    }
    TOCATCH
    Extents.sort();
    update();
}
void toBrowserViewWidget::changeConnection()
{
    toBrowserBaseWidget::changeConnection();

    toConnection & c = toCurrentConnection(this);

    addTab(columnsWidget, "&Columns");

    if (toIsOracle(c) || toIsSapDB(c) || toIsPostgreSQL(c))
        addTab(resultField, "SQL");
    else
        resultField->hide();

    if (toIsOracle(c))
    {
        addTab(triggersView, "&Triggers");
    }

    addTab(resultData, "&Data");

    if (toIsOracle(c))
    {
        addTab(grantsView, "&Grants");
        addTab(resultDependencies, "De&pendencies");
        addTab(extractView, "Script");
    }
    else
    {
        grantsView->hide();
        resultDependencies->hide();
        extractView->hide();
        triggersView->hide();
    }
}
Beispiel #4
0
void toEditExtensions::autoIndentBuffer(void)
{
    if (Current)
    {
        QString text = Current->text();
        int pos = 0;
        while (pos < text.length() && text.at(pos).isSpace())
        {
            pos++;
        }
        Current->selectAll();
        try
        {
            try
            {
                Current->insert(toSQLParse::indent(text.mid(pos), toCurrentConnection(Current)));
            }
            catch (...)
            {
                TLOG(1, toDecorator, __HERE__) << "	Ignored exception." << std::endl;
                Current->insert(toSQLParse::indent(text.mid(pos)));
            }
        }
        TOCATCH;
    }
}
Beispiel #5
0
void toEditExtensions::autoIndentBlock(void)
{
    if (Current)
    {
        try
        {
            int line1, col1, line2, col2;
            if (Current->getSelection(&line1, &col1, &line2, &col2))
            {
                QString t = Current->text(line1).mid(0, col1);
                t += QString::fromLatin1("a");
                int chars = 0;
                QString ind = toSQLParse::indentString(toSQLParse::countIndent(t, chars));
                QString mrk = Current->selectedText();
                QString res;
                try
                {
                    res = toSQLParse::indent(ind + mrk, toCurrentConnection(Current));
                }
                catch (...)
                {
                    TLOG(1, toDecorator, __HERE__) << "	Ignored exception." << std::endl;
                    res = toSQLParse::indent(ind + mrk);
                }
                t = Current->text(line2);
                unsigned int l = res.length() - ind.length();
                if (col2 == int(t.length()) && t.length() > 0) // Strip last newline if on last col of line
                    l--;
                res = res.mid(ind.length(), l); // Strip indent.
                Current->insert(res, true);
            }
        }
        TOCATCH;
    }
}
void toBrowserAccessWidget::flushPrivs(void)
{
    try
    {
        toCurrentConnection(this).execute("FLUSH PRIVILEGES");
    }
    TOCATCH
}
void toBrowserAccessWidget::changeConnection()
{
    toBrowserBaseWidget::changeConnection();

    if (toIsMySQL(toCurrentConnection(this)))
        addTab(accessContent, "&Data");
    else
        accessContent->setVisible(false);
}
void toBrowserDBLinksWidget::changeConnection()
{
    toBrowserBaseWidget::changeConnection();
    toConnection & c = toCurrentConnection(this);
    if (toIsOracle(c))
    {
        addTab(resultDBLink, "Info");
        addTab(synonymsView, "&Synonyms");
    }
    else
    {
        resultDBLink->setVisible(false);
        synonymsView->setVisible(false);
    }
}
void toBrowserDBLinksWidget::testDBLink()
{
    if (object().isEmpty())
    {
        TOMessageBox::information(this, "Database link", "No selected database link to test.");
        return;
    }

    toQList resultset;
    try
    {
        resultset = toQuery::readQueryNull(toCurrentConnection(this),
                                           "SELECT * FROM dual@" + object());
    }
    TOCATCH;

    QString status(resultset.empty() ? tr("status: FAILED") : tr("status: OK"));
    TOMessageBox::information(this, "Database link", object() + " " + status);
}
void toBrowserSequenceWidget::changeConnection()
{
    toBrowserBaseWidget::changeConnection();

    toConnection & c = toCurrentConnection(this);

    if (toIsOracle(c) || toIsPostgreSQL(c))
        addTab(resultInfo, "Info");
    else
        resultInfo->hide();

    if (toIsOracle(c))
    {
        addTab(grantsView, "&Grants");
        addTab(extractView, "Script");
    }
    else
    {
        grantsView->hide();
        extractView->hide();
    }
}
void toChangeConnection::popupMenu(void)
{
    try
    {
        menu()->clear();
        toConnection &conn = toCurrentConnection(this);
        std::list<QString> cons = toMainWidget()->connections();
        for (std::list<QString>::iterator i = cons.begin(); i != cons.end(); i++)
        {
            if (toCurrentTool(this)->canHandle(toMainWidget()->connection(*i)))
            {
                QAction *act = menu()->addAction(*i);
                act->setCheckable(true);
                if (conn.description() == *i)
                    act->setChecked(true);
                else
                    act->setChecked(false);
            }
        }
    }
    TOCATCH;
}
void toListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
{
#if 0                           // todo
    QPoint p = e->pos();
    int col = headerItem()->sectionAt(p.x());
    toTreeWidgetItem *item = itemAt(contentsToViewport(p));
    toResultViewItem *resItem = dynamic_cast<toResultViewItem *>(item);
    toResultViewCheck *chkItem = dynamic_cast<toResultViewCheck *>(item);
    QClipboard *clip = qApp->clipboard();
    if (resItem)
        clip->setText(resItem->allText(col));
    else if (chkItem)
        clip->setText(chkItem->allText(col));
    else if (item)
        clip->setText(item->text(col));

    Q3Header *head = header();
    for (int i = 0; i < columns(); i++)
    {
        QString str;
        if (resItem)
            str = resItem->allText(i);
        else if (chkItem)
            str = chkItem->allText(col);
        else if (item)
            str = item->text(i);

        try
        {
            toParamGet::setDefault(toCurrentConnection(this),
                                   head->label(i).lower(), toUnnull(str));
        }
        catch (...) {}
    }
    toTreeWidget::contentsMouseDoubleClickEvent(e);
#endif
}