QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsprovidersqlquerybuilder.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprovidersqlquerybuilder.cpp
3begin : August 2022
4copyright : (C) 2022 by Nyall Dawson
5email : nyall dot dawson at gmail dot com
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18
19#include "qgssqliteutils.h"
20
21#include <QString>
22
23using namespace Qt::StringLiterals;
24
26
27QString QgsProviderSqlQueryBuilder::createLimitQueryForTable( const QString &schema, const QString &name, int limit ) const
28{
29 if ( schema.isEmpty() )
30 return u"SELECT * FROM %1 LIMIT %2"_s.arg( quoteIdentifier( name ) ).arg( limit );
31 else
32 return u"SELECT * FROM %1.%2 LIMIT %3"_s.arg( quoteIdentifier( schema ), quoteIdentifier( name ) ).arg( limit );
33}
34
35QString QgsProviderSqlQueryBuilder::quoteIdentifier( const QString &identifier ) const
36{
37 // TODO: handle backend-specific identifier quoting...
38 return QgsSqliteUtils::quotedIdentifier( identifier );
39}
virtual ~QgsProviderSqlQueryBuilder()
virtual QString quoteIdentifier(const QString &identifier) const
Returns a properly quoted version of a table/schema identifier.
virtual QString createLimitQueryForTable(const QString &schema, const QString &name, int limit=10) const
Returns a result size limited SQL query string generated for the given schema and table name,...
static QString quotedIdentifier(const QString &identifier)
Returns a properly quoted version of identifier.