QGIS API Documentation 4.1.0-Master (60fea48833c)
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{
45 void operator()( sqlite3 *database ) const;
46};
47
52{
56 void operator()( sqlite3_stmt *statement ) const;
57};
58
66class CORE_EXPORT sqlite3_statement_unique_ptr : public std::unique_ptr< sqlite3_stmt, QgsSqlite3StatementFinalizer>
67{
68 public:
72 int step();
73
77 QString columnName( int column ) const;
78
82 QString columnAsText( int column ) const;
83
87 QByteArray columnAsBlob( int column ) const;
88
92 qlonglong columnAsInt64( int column ) const;
93
97 double columnAsDouble( int column ) const;
98
102 int columnCount() const;
103};
104
105
113class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3, QgsSqlite3Closer>
114{
115 public:
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
157QString CORE_EXPORT qgs_sqlite3_mprintf( const char *format, ... );
158
159#endif
160
166class CORE_EXPORT QgsSqliteUtils
167{
168 public:
173 static QString quotedString( const QString &value );
174
180 static QString quotedIdentifier( const QString &identifier );
181
188 static QString quotedValue( const QVariant &value );
189
195 static QStringList systemTables();
196
206 static QSet<QString> uniqueFields( sqlite3 *connection, const QString &tableName, QString &errorMessage ) SIP_SKIP;
207
217 static long long nextSequenceValue( sqlite3 *connection, const QString &tableName, QString errorMessage ) SIP_SKIP;
218};
219
220#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:133
#define SIP_OUT
Definition qgis_sip.h:57
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.