QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #define SIP_NO_FILE
22 
23 #include "qgis_core.h"
24 #include "qgis_sip.h"
25 
26 #include <memory>
27 #include <QString>
28 
29 struct sqlite3;
30 struct sqlite3_stmt;
31 
39 struct CORE_EXPORT QgsSqlite3Closer
40 {
41 
45  void operator()( sqlite3 *database );
46 };
47 
51 struct CORE_EXPORT QgsSqlite3StatementFinalizer
52 {
53 
57  void operator()( sqlite3_stmt *statement );
58 };
59 
68 class CORE_EXPORT sqlite3_statement_unique_ptr : public std::unique_ptr< sqlite3_stmt, QgsSqlite3StatementFinalizer>
69 {
70  public:
71 
75  int step();
76 
80  QString columnName( int column ) const;
81 
85  QString columnAsText( int column ) const;
86 
90  qlonglong columnAsInt64( int column ) const;
91 
95  double columnAsDouble( int column ) const;
96 
100  int columnCount() const;
101 };
102 
103 
112 class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3, QgsSqlite3Closer>
113 {
114  public:
115 
121  int open( const QString &path );
122 
128  int open_v2( const QString &path, int flags, const char *zVfs );
129 
133  QString errorMessage() const;
134 
139  sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode SIP_OUT ) const;
140 
149  int exec( const QString &sql, QString &errorMessage SIP_OUT ) const;
150 };
151 
158 class CORE_EXPORT QgsSqliteUtils
159 {
160  public:
161 
166  static QString quotedString( const QString &value );
167 };
168 
174 QString CORE_EXPORT QgsSqlite3Mprintf( const char *format, ... );
175 
176 
177 #endif // QGSSQLITEUTILS_H
Closes a sqlite3 database.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
Contains utilities for working with Sqlite data sources.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QString CORE_EXPORT QgsSqlite3Mprintf(const char *format,...)
Wraps sqlite3_mprintf() by automatically freeing the memory.
struct sqlite3 sqlite3
Finalizes an sqlite3 statement.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
#define SIP_OUT
Definition: qgis_sip.h:51