Hello Eike,
I made the changes you said, and I resolved the no linefeed issue also,
I hope it is ok now, and can be pushed, actually for me worked fine with
all types of comments. Also I tried to follow the principals you said.
So, push it if you think there is no need to correct something.
Gabor
From 2615b372f0168673b7074f20b41a9301d1acc18e Mon Sep 17 00:00:00 2001
From: Gabor <jengab@elte.hu>
Date: Wed, 31 Aug 2011 12:53:26 +0200
Subject: [PATCH] comment bug fix
---
connectivity/source/parse/sqlbison.y | 23 +++++++-
dbaccess/source/ui/querydesign/querycontroller.cxx | 61 +++++++++++++++++++-
2 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index d7e7c67..b348d72 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();
+ sal_Int32 nQueryLen=sQuery.getLength();
+ bool bIsText1=false;
+ bool bIsText2=false;
+ bool bComment=false;
+ ::rtl::OUStringBuffer sTemp(nQueryLen);
+ for(size_t 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 sTemp.makeStringAndClear();
+}
+//-----------------------------------------------------------------------------
OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
const ::rtl::OUString&
rStatement,
sal_Bool bInternational)
@@ -4581,9 +4599,12 @@ OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
// 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..18a6d10 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,61 @@ Reference<XNameAccess> OQueryController::getObjectContainer() const
OSL_ENSURE( xElements.is(), "OQueryController::getObjectContainer: unable to obtain the
container!" );
return xElements;
}
-
+//-----------------------------------------------------------------------------
+//this struct is for the following functions
+struct QueryComment{
+ sal_Int32 nPos;
+ ::rtl::OUString sComment;
+};
+//-----------------------------------------------------------------------------
+std::vector<QueryComment> getComment(const ::rtl::OUString& sQuery){
+ const sal_Unicode* sCopy=sQuery.getStr();
+ const sal_uInt32 nQueryLen=sQuery.getLength();
+ bool bIsText1=false;
+ bool bIsText2=false;
+ bool bComment=false;
+ std::vector<QueryComment> sRet;
+ ::rtl::OUStringBuffer sTemp;
+ QueryComment TempComment;
+ sal_Int32 nCommentLen=0;
+ for(size_t 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){
+ nCommentLen++;
+ if(i==nQueryLen-1)sTemp.append(&sCopy[i],1);
+ if(bComment) bComment=false;
+ sTemp.append((sal_Unicode)'\n');
+ TempComment.sComment=sTemp.makeStringAndClear();
+ sRet.push_back(TempComment);
+ }
+ if(!bIsText1 && !bIsText2 && (i+1)<nQueryLen && sCopy[i]=='-' && sCopy[i+1]=='-'){
+ bComment=true;
+ TempComment.nPos=i-nCommentLen;
+ }
+ if(!bIsText1 && !bIsText2 && (i+1)<nQueryLen && sCopy[i]=='/' && sCopy[i+1]=='/'){
+ bComment=true;
+ TempComment.nPos=i-nCommentLen;
+ }
+ if(bComment){
+ sTemp.append(&sCopy[i],1);
+ nCommentLen++;
+ }
+ }
+ return sRet;
+}
+//------------------------------------------------------------------------------
+::rtl::OUString ConcatComment(const ::rtl::OUString& sQuery,const std::vector<QueryComment>&
sComments){
+ ::rtl::OUStringBuffer sRet;
+ const sal_Unicode* pBeg=sQuery.getStr();
+ sal_Int32 nCurrPos=0;
+ for(size_t i=0;i < sComments.size();++i){
+ sRet.append(pBeg + nCurrPos , sComments[i].nPos - nCurrPos);
+ sRet.append(sComments[i].sComment);
+ nCurrPos=sComments[i].nPos;
+ }
+ return sRet.makeStringAndClear();
+}
// -----------------------------------------------------------------------------
void OQueryController::executeQuery()
{
@@ -1601,15 +1657,16 @@ bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs)
{
::rtl::OUString aErrorMsg;
+ std::vector<QueryComment> sComments=getComment(m_sStatement);
::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree( aErrorMsg,
m_sStatement, m_bGraphicalDesign );
if(pNode)
{
pNode->parseNodeToStr( sTranslatedStmt, getConnection() );
delete pNode;
}
-
m_xComposer->setQuery(sTranslatedStmt);
sTranslatedStmt = m_xComposer->getComposedQuery();
+ sTranslatedStmt = ConcatComment(sTranslatedStmt,sComments);
}
catch(const SQLException& e)
{
--
1.7.2.5
Context
- [Libreoffice] [PATCH] new 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.