summaryrefslogtreecommitdiffstats
path: root/dbaccess/source/ui/dlg/directsql.cxx
diff options
context:
space:
mode:
authorPhil Hart <html.wallah@gmail.com>2012-06-29 11:00:59 +0800
committerAndras Timar <atimar@suse.com>2012-07-01 12:53:10 +0200
commit10a7bcdf97c7634922626a2d858539a2f8bb0f7b (patch)
treed678d08bbfc814203de5646df8c15adfea6852bf /dbaccess/source/ui/dlg/directsql.cxx
parentdon't build oox::drawingml::TextListStyle::dump by default (diff)
downloadcore-10a7bcdf97c7634922626a2d858539a2f8bb0f7b.tar.gz
core-10a7bcdf97c7634922626a2d858539a2f8bb0f7b.zip
fdo#51497 Show output from SELECT statements in Execute SQL dialog.
These changes allow the user to optionally display the output from SQL SELECT statements in the "Execute SQL Statement" dialog. Change-Id: I9209a9e3b5ed100a88fa467078deb9f38c571d42
Diffstat (limited to 'dbaccess/source/ui/dlg/directsql.cxx')
-rw-r--r--dbaccess/source/ui/dlg/directsql.cxx55
1 files changed, 53 insertions, 2 deletions
diff --git a/dbaccess/source/ui/dlg/directsql.cxx b/dbaccess/source/ui/dlg/directsql.cxx
index 9fbce8060d68..6fdbc0567a84 100644
--- a/dbaccess/source/ui/dlg/directsql.cxx
+++ b/dbaccess/source/ui/dlg/directsql.cxx
@@ -27,6 +27,7 @@
#include <osl/mutex.hxx>
#include <tools/diagnose_ex.h>
#include <rtl/strbuf.hxx>
+#include <com/sun/star/sdbc/XRow.hpp>
//........................................................................
namespace dbaui
@@ -82,6 +83,9 @@ DBG_NAME(DirectSQLDialog)
,m_pSQLHistory(new LargeEntryListBox(this, ModuleRes(LB_HISTORY)))
,m_aStatusFrame (this, ModuleRes(FL_STATUS))
,m_aStatus (this, ModuleRes(ME_STATUS))
+ ,m_pShowOutput(new CheckBox(this, ModuleRes(CB_SHOWOUTPUT)))
+ ,m_aOutputFrame (this, ModuleRes(FL_OUTPUT))
+ ,m_aOutput (this, ModuleRes(ME_OUTPUT))
,m_aButtonSeparator (this, ModuleRes(FL_BUTTONS))
,m_aHelp (this, ModuleRes(PB_HELP))
,m_aClose (this, ModuleRes(PB_CLOSE))
@@ -214,15 +218,51 @@ DBG_NAME(DirectSQLDialog)
::osl::MutexGuard aGuard(m_aMutex);
String sStatus;
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > xResultSet;
try
{
// create a statement
Reference< XStatement > xStatement = m_xConnection->createStatement();
OSL_ENSURE(xStatement.is(), "DirectSQLDialog::implExecuteStatement: no statement returned by the connection!");
- // execute it
+ // clear the output box
+ m_aOutput.SetText(String::CreateFromAscii(""));
if (xStatement.is())
- xStatement->execute(_rStatement);
+ {
+ if (::rtl::OUString(_rStatement).toAsciiUpperCase().compareTo(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT")),6)==0 && m_pShowOutput->IsChecked())
+ {
+ // execute it as a query
+ xResultSet = xStatement->executeQuery(_rStatement);
+ // get a handle for the rows
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > xRow( xResultSet, ::com::sun::star::uno::UNO_QUERY );
+ // work through each of the rows
+ while (xResultSet->next())
+ {
+ // initialise the output line for each row
+ String out = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(""));
+ // work along the columns until that are none left
+ int i = 1;
+ try
+ {
+ for (;;)
+ {
+ // be dumb, treat everything as a string
+ out += xRow->getString(i) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
+ i++;
+ }
+ }
+ // trap for when we fall off the end of the row
+ catch (const SQLException& e)
+ {
+ }
+ // report the output
+ addOutputText(::rtl::OUString(out));
+ }
+ } else {
+ // execute it
+ xStatement->execute(_rStatement);
+ }
+ }
// successfull
sStatus = String(ModuleRes(STR_COMMAND_EXECUTED_SUCCESSFULLY));
@@ -259,6 +299,17 @@ DBG_NAME(DirectSQLDialog)
}
//--------------------------------------------------------------------
+ void DirectSQLDialog::addOutputText(const String& _rMessage)
+ {
+ String sAppendMessage = _rMessage;
+ sAppendMessage += String::CreateFromAscii("\n");
+
+ String sCompleteMessage = m_aOutput.GetText();
+ sCompleteMessage += sAppendMessage;
+ m_aOutput.SetText(sCompleteMessage);
+ }
+
+ //--------------------------------------------------------------------
void DirectSQLDialog::executeCurrent()
{
CHECK_INVARIANTS("DirectSQLDialog::executeCurrent");