/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// tdf#140298 - remember user settings within the current session // memp is filled in dtor and restored after initialization namespace
{ struct memParam {
std::vector<OUString> SQLHistory; bool DirectSQL; bool ShowOutput;
};
memParam memp;
}
for (size_t i = 0; i < memp.SQLHistory.size(); i++)
{
implAddToStatementHistory(memp.SQLHistory[i], true);
m_xDirectSQL->set_active(memp.DirectSQL);
m_xShowOutput->set_active(memp.ShowOutput);
}
// add a dispose listener to the connection
Reference< XComponent > xConnComp(m_xConnection, UNO_QUERY);
OSL_ENSURE(xConnComp.is(), "DirectSQLDialog::DirectSQLDialog: invalid connection!"); if (xConnComp.is())
startComponentListening(xConnComp);
OSL_ENSURE(Reference< XConnection >(_rSource.Source, UNO_QUERY).get() == m_xConnection.get(), "DirectSQLDialog::_disposing: where does this come from?");
// add the statement to the history
m_aStatementHistory.push_back(_rStatement); if (!bFromMemory)
memp.SQLHistory.push_back(_rStatement);
// normalize the statement, and remember the normalized form, too
OUString sNormalized = _rStatement.replaceAll("\n", " ");
m_aNormalizedHistory.push_back(sNormalized);
// add the normalized version to the list box
m_xSQLHistory->append_text(sNormalized);
// ensure that we don't exceed the history limit
implEnsureHistoryLimit();
}
#ifdef DBG_UTIL constchar* DirectSQLDialog::impl_CheckInvariants() const
{ if (m_aStatementHistory.size() != m_aNormalizedHistory.size()) return"statement history is inconsistent!";
if (!m_xSQLHistory) return"invalid listbox!";
if (m_aStatementHistory.size() != static_cast<size_t>(m_xSQLHistory->get_count())) return"invalid listbox entry count!";
if (!m_xConnection.is()) return"have no connection!";
const Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRS,UNO_QUERY_THROW)->getMetaData(); const sal_Int32 nColumnsCount = xResultSetMetaData->getColumnCount();
sal_Int32 nRowCount = 0; // get a handle for the rows
css::uno::Reference< css::sdbc::XRow > xRow( xRS, css::uno::UNO_QUERY ); // work through each of the rows while (xRS->next())
{ // initialise the output line for each row
OUStringBuffer out; // work along the columns until that are none left try
{ for (sal_Int32 i = 1; i <= nColumnsCount; ++i)
{ switch (xResultSetMetaData->getColumnType(i))
{ // tdf#153317, at least "Bit" type in Mysql/MariaDB gives: "\000" or "\001" // so retrieve Sequence from getBytes, test if it has a length of 1 (so we avoid BLOB/CLOB or other complex types) // and test if the value of first byte is one of those. // In this case, there's a good chance it's a "Bit" field case css::sdbc::DataType::BIT:
{ auto seq = xRow->getBytes(i); if ((seq.getLength() == 1) && (seq[0] >= 0) && (seq[0] <= 1))
{
out.append(OUString::number(static_cast<int>(seq[0])) + ",");
} else
{
out.append(xRow->getString(i) + ",");
} break;
} // for the rest, be dumb, treat everything as a string default:
out.append(xRow->getString(i) + ",");
}
}
nRowCount++;
} // trap for when we fall off the end of the row catch (const SQLException&)
{
} // report the output
addOutputText(out);
}
addOutputText(DBA_RES_PLURAL(STR_COMMAND_NROWS, nRowCount).replaceAll("%1", OUString::number(nRowCount)));
}
if ((_nHistoryPos >= 0) && (_nHistoryPos < getHistorySize()))
{ // set the text in the statement editor
OUString sStatement = m_aStatementHistory[_nHistoryPos];
m_xSQL->SetTextAndUpdate(sStatement);
OnStatementModified(nullptr);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.