QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <memory>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
25
26#include <QString>
27
28struct sqlite3;
29struct sqlite3_stmt;
30class QVariant;
31
32#ifndef SIP_RUN
33
40struct CORE_EXPORT QgsSqlite3Closer
41{
42
46 void operator()( sqlite3 *database ) const;
47};
48
53{
54
58 void operator()( sqlite3_stmt *statement ) const;
59};
60
68class 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 QByteArray columnAsBlob( int column ) const;
91
95 qlonglong columnAsInt64( int column ) const;
96
100 double columnAsDouble( int column ) const;
101
105 int columnCount() const;
106};
107
108
116class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3, QgsSqlite3Closer>
117{
118 public:
119
125 int open( const QString &path );
126
132 int open_v2( const QString &path, int flags, const char *zVfs );
133
137 QString errorMessage() const;
138
143 sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode SIP_OUT ) const;
144
153 int exec( const QString &sql, QString &errorMessage SIP_OUT ) const;
154
155};
156
162QString CORE_EXPORT qgs_sqlite3_mprintf( const char *format, ... );
163
164#endif
165
171class CORE_EXPORT QgsSqliteUtils
172{
173 public:
174
179 static QString quotedString( const QString &value );
180
186 static QString quotedIdentifier( const QString &identifier );
187
194 static QString quotedValue( const QVariant &value );
195
201 static QStringList systemTables();
202
212 static QSet<QString> uniqueFields( sqlite3 *connection, const QString &tableName, QString &errorMessage ) SIP_SKIP;
213
223 static long long nextSequenceValue( sqlite3 *connection, const QString &tableName, QString errorMessage ) SIP_SKIP;
224
225};
226
227#endif // QGSSQLITEUTILS_H
Contains utilities for working with Sqlite data sources.
static QString quotedString(const QString &value)
Returns a quoted string value, surround by ' characters and with special characters correctly escaped...
static QStringList systemTables()
Returns a string list of SQLite (and spatialite) system tables.
static QString quotedIdentifier(const QString &identifier)
Returns a properly quoted version of identifier.
static QSet< QString > uniqueFields(sqlite3 *connection, const QString &tableName, QString &errorMessage)
Returns a list of field names for connection and tableName having a UNIQUE constraint,...
static long long nextSequenceValue(sqlite3 *connection, const QString &tableName, QString errorMessage)
Increments and returns an SQLITE sequence of the table "sqlite_sequence" for tableName and returns it...
static QString quotedValue(const QVariant &value)
Returns a properly quoted and escaped version of value for use in SQL strings.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
QString errorMessage() const
Returns the most recent error message encountered by the database.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
int exec(const QString &sql, QString &errorMessage) const
Executes the sql command in the database.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
QString columnName(int column) const
Returns the name of column.
double columnAsDouble(int column) const
Gets column value from the current statement row as a double.
int step()
Steps to the next record in the statement, returning the sqlite3 result code.
qlonglong columnAsInt64(int column) const
Gets column value from the current statement row as a long long integer (64 bits).
int columnCount() const
Gets the number of columns that this statement returns.
QByteArray columnAsBlob(int column) const
Returns the column value from the current statement row as raw byte array.
#define SIP_SKIP
Definition qgis_sip.h:134
#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.
void operator()(sqlite3 *database) const
Closes an sqlite database.
Finalizes an sqlite3 statement.
void operator()(sqlite3_stmt *statement) const
Finalizes an sqlite3 statement.