summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2018-04-08 13:34:27 +0200
committerTamás Bunth <btomi96@gmail.com>2018-04-14 14:15:26 +0200
commitf5a2fedaebcf71824ecef9b5e7683237646175b4 (patch)
treef415818996128d26cbd960c541f87bf3682b4d8f /connectivity
parent5bf410957994ec2acfec1fddb822934ed0965820 (diff)
tdf#105075 Firebird: Support Limit of query_GUI
Firebird uses "SELECT FIRST <num> ..." format to limit the number of result row numbers instead of "SELECT ... LIMIT <num>" My first approach was to improve OSQLParser and make it understand the Firebird dialect. But it is hard because the parser has hard-coded getChild(int) calls all over the code and all the indexes should be updated. Instead of this, we recognise the LIMIT keyword with the parser, remove it and push the FIRST <num> part manually right after SELECT. All of this should happen in case of Firebird and only when using the query-GUI. Change-Id: I53f3f977f77cf98b91b25a7eaa6ebb2ee8ac0951 Reviewed-on: https://gerrit.libreoffice.org/52591 Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/parse/sqlnode.cxx20
1 files changed, 20 insertions, 0 deletions
diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx
index eb4a02ca36e9..adc48a446a2e 100644
--- a/connectivity/source/parse/sqlnode.cxx
+++ b/connectivity/source/parse/sqlnode.cxx
@@ -347,6 +347,18 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons
aParseParam.pParser = &_rParser;
+ // LIMIT keyword differs in Firebird
+ OSQLParseNode* pTableExp = getChild(3);
+ Reference< XDatabaseMetaData > xMeta( _rxConnection->getMetaData() );
+ OUString sLimitValue;
+ if( pTableExp->getChild(6)->count() >= 2 && pTableExp->getChild(6)->getChild(1)
+ && (xMeta->getURL().equalsIgnoreAsciiCase("sdbc:embedded:firebird")
+ || xMeta->getURL().startsWithIgnoreAsciiCase("sdbc:firebird:")))
+ {
+ sLimitValue = pTableExp->getChild(6)->getChild(1)->getTokenValue();
+ pTableExp->removeAt(6);
+ }
+
_out_rString.clear();
OUStringBuffer sBuffer;
bool bSuccess = false;
@@ -360,6 +372,14 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons
if ( _pErrorHolder )
*_pErrorHolder = e;
}
+
+ if(sLimitValue.getLength() > 0)
+ {
+ constexpr char SELECT_KEYWORD[] = "SELECT";
+ sBuffer.insert(sBuffer.indexOf(SELECT_KEYWORD) + strlen(SELECT_KEYWORD),
+ " FIRST " + sLimitValue);
+ }
+
_out_rString = sBuffer.makeStringAndClear();
return bSuccess;
}