[PATCH] comment bug fix
Gabor
jengab at elte.hu
Wed Aug 31 03:53:26 PDT 2011
---
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
--------------000405070806010704030306--
More information about the LibreOffice
mailing list