71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
#ifndef MARIADBCLIENT_H
|
|
#define MARIADBCLIENT_H
|
|
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QVector>
|
|
#include <memory>
|
|
|
|
class MariaDbClient
|
|
{
|
|
public:
|
|
using Row = QStringList;
|
|
using ResultSet = QVector<Row>;
|
|
|
|
MariaDbClient();
|
|
~MariaDbClient();
|
|
|
|
MariaDbClient(const MariaDbClient&) = delete;
|
|
MariaDbClient& operator=(const MariaDbClient&) = delete;
|
|
|
|
bool IsLibraryAvailable() const;
|
|
bool IsConnected() const;
|
|
QString LastError() const;
|
|
|
|
bool Connect(const QString& host,
|
|
int port,
|
|
const QString& user,
|
|
const QString& password,
|
|
const QString& database);
|
|
void Close();
|
|
|
|
bool Exec(const QString& sql);
|
|
bool Query(const QString& sql, ResultSet& rows);
|
|
unsigned long long LastInsertId() const;
|
|
|
|
static QString Escape(const QString& value);
|
|
|
|
private:
|
|
bool LoadClientLibrary();
|
|
bool BindSymbols();
|
|
void SetError(const QString& message);
|
|
QString ConnectionError() const;
|
|
|
|
void* m_library = nullptr;
|
|
void* m_mysql = nullptr;
|
|
bool m_connected = false;
|
|
QString m_lastError;
|
|
|
|
void* (*m_init)(void*) = nullptr;
|
|
void* (*m_realConnect)(void*,
|
|
const char*,
|
|
const char*,
|
|
const char*,
|
|
const char*,
|
|
unsigned int,
|
|
const char*,
|
|
unsigned long) = nullptr;
|
|
int (*m_query)(void*, const char*) = nullptr;
|
|
void* (*m_storeResult)(void*) = nullptr;
|
|
void (*m_freeResult)(void*) = nullptr;
|
|
char** (*m_fetchRow)(void*) = nullptr;
|
|
unsigned int (*m_numFields)(void*) = nullptr;
|
|
const char* (*m_error)(void*) = nullptr;
|
|
void (*m_close)(void*) = nullptr;
|
|
unsigned long long (*m_insertId)(void*) = nullptr;
|
|
unsigned int (*m_fieldCount)(void*) = nullptr;
|
|
int (*m_setCharacterSet)(void*, const char*) = nullptr;
|
|
};
|
|
|
|
#endif // MARIADBCLIENT_H
|