QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgssqliteutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssqliteutils.h
3 -------------------
4 begin : Nov, 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSQLITEUTILS_H
19#define QGSSQLITEUTILS_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23
24#include <memory>
25#include <QString>
26
27struct sqlite3;
28struct sqlite3_stmt;
29class QVariant;
30
31#ifndef SIP_RUN
32
39struct CORE_EXPORT QgsSqlite3Closer
40{
41
45 void operator()( sqlite3 *database ) const;
46};
47
52{
53
57 void operator()( sqlite3_stmt *statement ) const;
58};
59
67class CORE_EXPORT sqlite3_statement_unique_ptr : public std::unique_ptr< sqlite3_stmt, QgsSqlite3StatementFinalizer>
68{
69 public:
70
74 int step();
75
79 QString columnName( int column ) const;
80
84 QString columnAsText( int column ) const;
85
89 QByteArray columnAsBlob( int column ) const;
90
94 qlonglong columnAsInt64( int column ) const;
95
99 double columnAsDouble( int column ) const;
100
104 int columnCount() const;
105};
106
107
115class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3, QgsSqlite3Closer>
116{
117 public:
118
124 int open( const QString &path );
125
131 int open_v2( const QString &path, int flags, const char *zVfs );
132
136 QString errorMessage() const;
137
142 sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode SIP_OUT ) const;
143
152 int exec( const QString &sql, QString &errorMessage SIP_OUT ) const;
153
154};
155
161QString CORE_EXPORT qgs_sqlite3_mprintf( const char *format, ... );
162
163#endif
164
170class CORE_EXPORT QgsSqliteUtils
171{
172 public:
173
178 static QString quotedString( const QString &value );
179
185 static QString quotedIdentifier( const QString &identifier );
186
193 static QString quotedValue( const QVariant &value );
194
200 static QStringList systemTables();
201
211 static QSet<QString> uniqueFields( sqlite3 *connection, const QString &tableName, QString &errorMessage ) SIP_SKIP;
212
222 static long long nextSequenceValue( sqlite3 *connection, const QString &tableName, QString errorMessage ) SIP_SKIP;
223
224};
225
226#endif // QGSSQLITEUTILS_H
Contains utilities for working with Sqlite data sources.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58
struct sqlite3 sqlite3
QString CORE_EXPORT qgs_sqlite3_mprintf(const char *format,...)
Wraps sqlite3_mprintf() by automatically freeing the memory.
Closes a sqlite3 database.
Finalizes an sqlite3 statement.