20#include <core_resource.hxx>
26#include <osl/mutex.hxx>
27#include <rtl/ustrbuf.hxx>
31#include <com/sun/star/sdbc/SQLException.hpp>
32#include <com/sun/star/sdbc/XRow.hpp>
33#include <com/sun/star/beans/XPropertySet.hpp>
34#include <com/sun/star/sdbc/XMultipleResults.hpp>
46 : GenericDialogController(_pParent,
"dbaccess/ui/directsqldialog.ui",
"DirectSQLDialog")
47 , m_xExecute(m_xBuilder->weld_button(
"execute"))
48 , m_xSQLHistory(m_xBuilder->weld_combo_box(
"sqlhistory"))
49 , m_xStatus(m_xBuilder->weld_text_view(
"status"))
50 , m_xDirectSQL(m_xBuilder->weld_check_button(
"directsql"))
51 , m_xShowOutput(m_xBuilder->weld_check_button(
"showoutput"))
52 ,
m_xOutput(m_xBuilder->weld_text_view(
"output"))
53 , m_xClose(m_xBuilder->weld_button(
"close"))
54 , m_xSQL(new
SQLEditView(m_xBuilder->weld_scrolled_window(
"scrolledwindow", true)))
55 , m_xSQLEd(new
weld::CustomWeld(*m_xBuilder,
"sql", *m_xSQL))
58 , m_pClosingEvent(nullptr)
60 int nWidth =
m_xStatus->get_approximate_digit_width() * 60;
61 int nHeight =
m_xStatus->get_height_rows(7);
63 m_xSQLEd->set_size_request(nWidth, nHeight);
75 OSL_ENSURE(xConnComp.is(),
"DirectSQLDialog::DirectSQLDialog: invalid connection!");
80 OnStatementModified(
nullptr);
99 "DirectSQLDialog::_disposing: where does this come from?");
104 VclMessageType::Warning, VclButtonsType::Ok,
118 SAL_WARN(
"dbaccess.ui",
"DirectSQLDialog::getHistorySize: " << pError);
130 SAL_WARN(
"dbaccess.ui",
"DirectSQLDialog::implEnsureHistoryLimit: " << pError);
139 while (nRemoveEntries--)
153 SAL_WARN(
"dbaccess.ui",
"DirectSQLDialog::implAddToStatementHistor: " << pError);
161 OUString sNormalized = _rStatement.replaceAll(
"\n",
" ");
175 return "statement history is inconsistent!";
178 return "invalid listbox!";
181 return "invalid listbox entry count!";
184 return "have no connection!";
196 SAL_WARN(
"dbaccess.ui",
"DirectSQLDialog::implExecuteStatement: " << pError);
225 css::uno::Reference< css::sdbc::XMultipleResults > xMR ( xStatement, UNO_QUERY );
227 if (xMeta.is() && xMeta->supportsMultipleResultSets() && xMR.is())
229 bool hasRS = xStatement->execute(_rStatement);
232 css::uno::Reference< css::sdbc::XResultSet > xRS (xMR->getResultSet());
238 Concat2View(OUString::number(xMR->getUpdateCount()) +
" rows updated\n"));
241 hasRS = xMR->getMoreResults();
242 if (!hasRS && xMR->getUpdateCount() == -1)
246 css::uno::Reference< css::sdbc::XResultSet > xRS (xMR->getResultSet());
254 const OUString upperStatement = _rStatement.toAsciiUpperCase();
255 if (upperStatement.startsWith(
"UPDATE"))
257 sal_Int32 resultCount = xStatement->executeUpdate(_rStatement);
258 addOutputText(Concat2View(OUString::number(resultCount) +
" rows updated\n"));
260 else if (upperStatement.startsWith(
"INSERT"))
262 sal_Int32 resultCount = xStatement->executeUpdate(_rStatement);
263 addOutputText(Concat2View(OUString::number(resultCount) +
" rows inserted\n"));
265 else if (upperStatement.startsWith(
"DELETE"))
267 sal_Int32 resultCount = xStatement->executeUpdate(_rStatement);
268 addOutputText(Concat2View(OUString::number(resultCount) +
" rows deleted\n"));
270 else if (upperStatement.startsWith(
"CREATE"))
272 xStatement->executeUpdate(_rStatement);
275 else if (upperStatement.startsWith(
"SELECT") ||
m_xShowOutput->get_active())
277 css::uno::Reference< css::sdbc::XResultSet > xRS = xStatement->executeQuery(_rStatement);
283 sal_Int32 resultCount = xStatement->executeUpdate(_rStatement);
284 addOutputText(Concat2View(OUString::number(resultCount) +
" rows updated\n"));
288 sStatus =
DBA_RES(STR_COMMAND_EXECUTED_SUCCESSFULLY);
291 ::comphelper::disposeComponent(xStatement);
293 catch(
const SQLException& e)
309 css::uno::Reference< css::sdbc::XRow > xRow( xRS, css::uno::UNO_QUERY );
327 auto seq = xRow->getBytes(
i);
328 if ((seq.getLength() == 1) && (seq[0] >= 0) && (seq[0] <= 1))
330 out.append(OUString::number(
static_cast<int>(seq[0])) +
",");
334 out.append(xRow->getString(
i) +
",");
340 catch (
const SQLException&)
350 OUString sAppendMessage = OUString::number(
m_nStatusCount++) +
": " + _rMessage +
"\n\n";
352 OUString sCompleteMessage =
m_xStatus->get_text() + sAppendMessage;
355 m_xStatus->select_region(sCompleteMessage.getLength(), sCompleteMessage.getLength());
360 OUString sAppendMessage = OUString::Concat(_rMessage) +
"\n";
362 OUString sCompleteMessage =
m_xOutput->get_text() + sAppendMessage;
372 SAL_WARN(
"dbaccess.ui",
"DirectSQLDialog::executeCurrent: " << pError);
376 OUString sStatement =
m_xSQL->GetText();
393 SAL_WARN(
"dbaccess.ui",
"DirectSQLDialog::switchToHistory: " << pError);
401 m_xSQL->SetTextAndUpdate(sStatement);
402 OnStatementModified(
nullptr);
407 OSL_FAIL(
"DirectSQLDialog::switchToHistory: invalid position!");
412 m_xExecute->set_sensitive(!m_xSQL->GetText().isEmpty());
422 assert(m_pClosingEvent);
424 m_pClosingEvent =
nullptr;
436 const sal_Int32 nSelected = m_xSQLHistory->get_active();
438 switchToHistory(nSelected);
Reference< XExecutableDialog > m_xDialog
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::TextView > m_xStatus
virtual void _disposing(const css::lang::EventObject &_rSource) override
void addStatusText(std::u16string_view _rMessage)
adds a status text to the status list
void implAddToStatementHistory(const OUString &_rStatement)
adds a statement to the statement history
StringQueue m_aStatementHistory
ImplSVEvent * m_pClosingEvent
StringQueue m_aNormalizedHistory
std::unique_ptr< weld::Button > m_xClose
const char * impl_CheckInvariants() const
void implEnsureHistoryLimit()
ensures that our history has at most m_nHistoryLimit entries
std::unique_ptr< weld::CheckButton > m_xDirectSQL
std::unique_ptr< SQLEditView > m_xSQL
std::unique_ptr< weld::Button > m_xExecute
void display(const css::uno::Reference< css::sdbc::XResultSet > &xRS)
displays resultset
css::uno::Reference< css::sdbc::XConnection > m_xConnection
std::unique_ptr< weld::CustomWeld > m_xSQLEd
void addOutputText(std::u16string_view _rMessage)
adds a status text to the output list
void switchToHistory(sal_Int32 _nHistoryPos)
void implExecuteStatement(const OUString &_rStatement)
executes the statement given, adds the status to the status list
std::unique_ptr< weld::TextView > m_xOutput
virtual ~DirectSQLDialog() override
std::unique_ptr< weld::CheckButton > m_xShowOutput
DirectSQLDialog(weld::Window *_pParent, const css::uno::Reference< css::sdbc::XConnection > &_rxConn)
std::unique_ptr< weld::ComboBox > m_xSQLHistory
sal_Int32 getHistorySize() const
number of history entries
void stopAllComponentListening()
void startComponentListening(const css::uno::Reference< css::lang::XComponent > &_rxComp)
std::shared_ptr< weld::Dialog > m_xDialog
#define DBG_UNHANDLED_EXCEPTION(...)
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
constexpr sal_Int32 g_nHistoryLimit
Reference< XConnection > m_xConnection
uno::Reference< io::XOutputStream > m_xOutput
constexpr OUStringLiteral PROPERTY_ESCAPE_PROCESSING(u"EscapeProcessing")