Hello,
Here is a patch for bug 36594. It deletes the comments from the SQL
query and puts them beck for saving and execution. Please review it,and
push it to git.
Gabor
From 73ff25834cca39cd8d4c08210556aa532b48fb77 Mon Sep 17 00:00:00 2001
From: Gabor Jenei <jengab@elte.hu>
Date: Sun, 21 Aug 2011 14:51:15 +0200
Subject: [PATCH] Comment bug
---
connectivity/source/parse/sqlbison.y | 22 ++++++++-
dbaccess/source/ui/querydesign/querycontroller.cxx | 49 +++++++++++++++++++-
2 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index d7e7c67..8f97d17 100755
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -4570,6 +4570,24 @@ void OSQLParser::setParseTree(OSQLParseNode * pNewParseTree)
m_pParseTree = pNewParseTree;
}
//-----------------------------------------------------------------------------
+::rtl::OUString delComment(const ::rtl::OUString& sQuery){
+ const sal_Unicode* sCopy=sQuery.getStr();
+ int nQueryLen=sQuery.getLength();
+ bool bIsText1=false;
+ bool bIsText2=false;
+ bool bComment=false;
+ ::rtl::OUStringBuffer sTemp;
+ for(int i=0;i<nQueryLen;i++){
+ if(sCopy[i]=='\"' && !bIsText2 && !bComment) bIsText1=!bIsText1;
+ if(sCopy[i]=='\'' && !bIsText1 && !bComment) bIsText2=!bIsText2;
+ if(sCopy[i]=='\n' && bComment) bComment=false;
+ if(!bIsText1 && !bIsText2 && (i+1)<nQueryLen && sCopy[i]=='-' && sCopy[i+1]=='-')
bComment=true;
+ if(!bIsText1 && !bIsText2 && (i+1)<nQueryLen && sCopy[i]=='/' && sCopy[i+1]=='/')
bComment=true;
+ if(!bComment) sTemp.append(&sCopy[i],1);
+ }
+ return (::rtl::OUString)sTemp;
+}
+//-----------------------------------------------------------------------------
OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
const ::rtl::OUString&
rStatement,
sal_Bool bInternational)
@@ -4580,10 +4598,12 @@ OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
::osl::MutexGuard aGuard(getMutex());
// must be reset
setParser(this);
+ //delete comments before parsing
+ ::rtl::OUString sTemp=delComment(rStatement);
// defines how to scan
s_pScanner->SetRule(s_pScanner->GetSQLRule()); // initial
- s_pScanner->prepareScan(rStatement, m_pContext, bInternational);
+ s_pScanner->prepareScan(sTemp, m_pContext, bInternational);
SQLyylval.pParseNode = NULL;
// SQLyypvt = NULL;
diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx
b/dbaccess/source/ui/querydesign/querycontroller.cxx
index 054c854..e7c35b3 100644
--- a/dbaccess/source/ui/querydesign/querycontroller.cxx
+++ b/dbaccess/source/ui/querydesign/querycontroller.cxx
@@ -94,6 +94,8 @@
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <osl/mutex.hxx>
+#include <rtl/strbuf.hxx>
+#include <vector>
extern "C" void SAL_CALL createRegistryInfo_OQueryControl()
{
@@ -1272,7 +1274,49 @@ Reference<XNameAccess> OQueryController::getObjectContainer() const
OSL_ENSURE( xElements.is(), "OQueryController::getObjectContainer: unable to obtain the
container!" );
return xElements;
}
-
+//-----------------------------------------------------------------------------
+std::vector< ::rtl::OUStringBuffer > getComment(const ::rtl::OUString& sQuery){
+ const sal_Unicode* sCopy=sQuery.getStr();
+ int nQueryLen=sQuery.getLength();
+ bool bIsText1=false;
+ bool bIsText2=false;
+ bool bComment=false;
+ std::vector< ::rtl::OUStringBuffer > sRet;
+ ::rtl::OUStringBuffer sTemp;
+ for(int i=0;i<nQueryLen;i++){
+ if(sCopy[i]=='\"' && !bIsText2 && !bComment) bIsText1=!bIsText1;
+ if(sCopy[i]=='\'' && !bIsText1 && !bComment) bIsText2=!bIsText2;
+ if(sCopy[i]=='\n' || i==nQueryLen-1){
+ if(bComment) bComment=false;
+ sTemp.append((sal_Unicode)'\n');
+ sRet.push_back(sTemp);
+ sTemp=::rtl::OUString();
+ }
+ if(!bIsText1 && !bIsText2 && (i+1)<nQueryLen && sCopy[i]=='-' && sCopy[i+1]=='-')
bComment=true;
+ if(!bIsText1 && !bIsText2 && (i+1)<nQueryLen && sCopy[i]=='/' && sCopy[i+1]=='/')
bComment=true;
+ if(bComment) sTemp.append(&sCopy[i],1);
+ }
+ sTemp=::rtl::OUString();
+ return sRet;
+}
+//------------------------------------------------------------------------------
+::rtl::OUString ConcatComment(const ::rtl::OUString& sQuery,std::vector< ::rtl::OUStringBuffer >
sComments){
+ ::rtl::OUStringBuffer sRet;
+ int nIndLF=0;
+ int nIndBeg=0;
+ for(unsigned int i=0;i<sComments.size();i++){
+ nIndBeg=nIndLF;
+ if(sQuery.indexOf('\n')==-1){
+ nIndLF=sQuery.getLength();
+ }
+ else{
+ nIndLF=sQuery.indexOf('\n',nIndLF);
+ }
+ sRet.append(sQuery.copy(nIndBeg,nIndLF-nIndBeg));
+ sRet.append(sComments[i]);
+ }
+ return (::rtl::OUString)sRet;
+}
// -----------------------------------------------------------------------------
void OQueryController::executeQuery()
{
@@ -1600,7 +1644,7 @@ bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs)
try
{
::rtl::OUString aErrorMsg;
-
+ std::vector< ::rtl::OUStringBuffer > sComments=getComment(m_sStatement);
::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree( aErrorMsg,
m_sStatement, m_bGraphicalDesign );
if(pNode)
{
@@ -1610,6 +1654,7 @@ bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs)
m_xComposer->setQuery(sTranslatedStmt);
sTranslatedStmt = m_xComposer->getComposedQuery();
+ sTranslatedStmt=ConcatComment(sTranslatedStmt,sComments);
}
catch(const SQLException& e)
{
--
1.7.2.5
Context
- [Libreoffice] [PATCH] BUG 36594 · Jenei Gábor
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.