[PATCH] Comment bug
Gabor Jenei
jengab at elte.hu
Sun Aug 21 05:51:15 PDT 2011
---
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
--------------080103070305010907080204--
More information about the LibreOffice
mailing list