Compare commits
4 commits
main
...
table-inhe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1ae89dce8 | ||
|
|
7728417392 | ||
|
|
abc0dd892f | ||
|
|
39dbab4d36 |
90 changed files with 745 additions and 277806 deletions
|
|
@ -1,4 +1,4 @@
|
|||
The program is build with Qt 6.8 using QtCreator and the Visual Studio 2022 C++ compiler.
|
||||
The program is build with Qt 6.3 using QtCreator and the Visual Studio 2019 C++ compiler.
|
||||
Only 64-bits builds are actively maintained.
|
||||
|
||||
[Documentation](https://eelke.gitlab.io/pgLab/) is generated automatically when a commit is tagged. It also includes releasenotes.
|
||||
|
|
@ -8,6 +8,7 @@ The release notes use collected from git using [reno](https://docs.openstack.org
|
|||
|
||||
- boost
|
||||
- botan
|
||||
- fmt
|
||||
- googletest
|
||||
- libpq
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#define CSVWRITER_H
|
||||
|
||||
#include <ostream>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
class CsvWriter {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
#include "KeyStrengthener.h"
|
||||
#include <botan/scrypt.h>
|
||||
#include <botan/base64.h>
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QVariant>
|
||||
#include <stdexcept>
|
||||
|
||||
KeyStrengthener::KeyStrengthener(std::unique_ptr<Botan::PasswordHash> hasher, Botan::secure_vector<uint8_t> salt, size_t keysize)
|
||||
: m_hasher (std::move(hasher))
|
||||
|
|
@ -31,23 +36,27 @@ Botan::secure_vector<uint8_t> KeyStrengthener::derive(const std::string &passphr
|
|||
return master_key;
|
||||
}
|
||||
|
||||
void KeyStrengthener::saveParams(SQLiteConnection &db, const QString &table_name)
|
||||
void KeyStrengthener::saveParams(QSqlDatabase &db, const QString &table_name)
|
||||
{
|
||||
size_t i1 = m_hasher->memory_param();
|
||||
size_t i2 = m_hasher->iterations();
|
||||
size_t i3 = m_hasher->parallelism();
|
||||
auto sc = dynamic_cast<Botan::Scrypt*>(m_hasher.get());
|
||||
size_t i1 = sc->N();
|
||||
size_t i2 = sc->r();
|
||||
size_t i3 = sc->p();
|
||||
|
||||
auto salt_str = QString::fromUtf8(Botan::base64_encode(m_salt).c_str());
|
||||
// SAVE parameters in database
|
||||
|
||||
auto stmt = db.Prepare("INSERT OR REPLACE INTO " + table_name + "(id, algo, i1, i2, i3, ks, salt) "
|
||||
+ "VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7)");
|
||||
stmt.Bind(1, 1);
|
||||
stmt.Bind(2, "Scrypt");
|
||||
stmt.Bind(3, (int)i1);
|
||||
stmt.Bind(4, (int)i2);
|
||||
stmt.Bind(5, (int)i3);
|
||||
stmt.Bind(6, (int)m_keySize);
|
||||
stmt.Bind(7, salt_str);
|
||||
stmt.Step();
|
||||
QSqlQuery insert_statement(db);
|
||||
insert_statement.prepare("INSERT OR REPLACE INTO " + table_name + "(id, algo, i1, i2, i3, ks, salt) "
|
||||
+ "VALUES(:id, :algo, :i1, :i2, :i3, :ks, :salt)");
|
||||
insert_statement.bindValue(":id", 1);
|
||||
insert_statement.bindValue(":algo", "Scrypt");
|
||||
insert_statement.bindValue(":i1", i1);
|
||||
insert_statement.bindValue(":i2", i2);
|
||||
insert_statement.bindValue(":i3", i3);
|
||||
insert_statement.bindValue(":ks", m_keySize);
|
||||
insert_statement.bindValue(":salt", salt_str);
|
||||
if (!insert_statement.exec()) {
|
||||
throw std::runtime_error("PasswordManager::KeyStrengthener::saveParams failed");
|
||||
// auto err = insert_statement.lastError();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef KEYSTRENGTHENER_H
|
||||
#define KEYSTRENGTHENER_H
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <botan/pwdhash.h>
|
||||
#include <botan/secmem.h>
|
||||
#include <memory>
|
||||
#include "sqlite/SQLiteConnection.h"
|
||||
|
||||
class KeyStrengthener {
|
||||
public:
|
||||
|
|
@ -19,7 +19,7 @@ public:
|
|||
KeyStrengthener& operator=(KeyStrengthener &&rhs);
|
||||
|
||||
Botan::secure_vector<uint8_t> derive(const std::string &passphrase);
|
||||
void saveParams(SQLiteConnection &db, const QString &table_name);
|
||||
void saveParams(QSqlDatabase &db, const QString &table_name);
|
||||
private:
|
||||
std::unique_ptr<Botan::PasswordHash> m_hasher;
|
||||
Botan::secure_vector<uint8_t> m_salt;
|
||||
|
|
@ -1,16 +1,33 @@
|
|||
#include "PasswordManager.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
#include <botan/hash.h>
|
||||
#include <botan/auto_rng.h>
|
||||
#include <botan/base64.h>
|
||||
#include <botan/scrypt.h>
|
||||
#include <botan/nist_keywrap.h>
|
||||
#include <botan/base64.h>
|
||||
#include <botan/mac.h>
|
||||
#include <botan/block_cipher.h>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
class SqlException : public std::runtime_error {
|
||||
public:
|
||||
QSqlError error;
|
||||
SqlException(const QSqlError &err)
|
||||
: std::runtime_error(err.text().toUtf8().data())
|
||||
, error(err)
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using namespace Botan;
|
||||
|
||||
class PasswordCryptoEngine {
|
||||
|
|
@ -69,7 +86,7 @@ PasswordManager::PasswordManager() = default;
|
|||
PasswordManager::~PasswordManager() = default;
|
||||
|
||||
|
||||
bool PasswordManager::initialized(SQLiteConnection& db)
|
||||
bool PasswordManager::initialized(QSqlDatabase& db)
|
||||
{
|
||||
return isPskStoreInitialized(db);
|
||||
}
|
||||
|
|
@ -85,7 +102,7 @@ PasswordManager::deriveKey(KeyStrengthener &ks, QString passphrase)
|
|||
return { master_key, mkh };
|
||||
}
|
||||
|
||||
bool PasswordManager::createDatabase(SQLiteConnection &db, QString passphrase)
|
||||
bool PasswordManager::createDatabase(QSqlDatabase &db, QString passphrase)
|
||||
{
|
||||
m_cryptoEngine.reset();
|
||||
if (!isPskStoreInitialized(db)) {
|
||||
|
|
@ -96,11 +113,15 @@ bool PasswordManager::createDatabase(SQLiteConnection &db, QString passphrase)
|
|||
auto [master_key, mkh_bin] = deriveKey(ks, passphrase);
|
||||
auto mkh = QString::fromUtf8(Botan::base64_encode(mkh_bin).c_str());
|
||||
|
||||
auto q_ins_hash = db.Prepare(
|
||||
"INSERT INTO " + m_secretHashTableName + "(id, hash) VALUES(?1, ?2)");
|
||||
q_ins_hash.Bind(1, 1);
|
||||
q_ins_hash.Bind(2, mkh);
|
||||
q_ins_hash.Step();
|
||||
QSqlQuery q_ins_hash(db);
|
||||
q_ins_hash.prepare("INSERT INTO " + m_secretHashTableName + "(id, hash) VALUES(:id, :hash)");
|
||||
q_ins_hash.bindValue(":id", 1);
|
||||
q_ins_hash.bindValue(":hash", mkh);
|
||||
if (!q_ins_hash.exec()) {
|
||||
auto err = q_ins_hash.lastError();
|
||||
qDebug() << err.text();
|
||||
throw SqlException(err);
|
||||
}
|
||||
|
||||
m_cryptoEngine = std::make_unique<PasswordCryptoEngine>(master_key);
|
||||
return true;
|
||||
|
|
@ -108,16 +129,16 @@ bool PasswordManager::createDatabase(SQLiteConnection &db, QString passphrase)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool PasswordManager::openDatabase(SQLiteConnection &db, QString passphrase)
|
||||
bool PasswordManager::openDatabase(QSqlDatabase &db, QString passphrase)
|
||||
{
|
||||
m_cryptoEngine.reset();
|
||||
if (isPskStoreInitialized(db)) {
|
||||
auto ks = getKeyStrengthener(db);
|
||||
auto [master_key, mkh_bin] = deriveKey(ks, passphrase);
|
||||
|
||||
auto q = db.Prepare("SELECT hash FROM " + m_secretHashTableName + " WHERE id=1");
|
||||
if (q.Step()) {
|
||||
QByteArray hash_b64 = q.ColumnCharPtr(0);
|
||||
QSqlQuery q("SELECT hash FROM " + m_secretHashTableName + " WHERE id=1", db);
|
||||
if (q.next()) {
|
||||
auto hash_b64 = q.value(0).toString().toUtf8();
|
||||
auto hash_bin = Botan::base64_decode(hash_b64.data(), static_cast<size_t>(hash_b64.size()));
|
||||
if (hash_bin == mkh_bin) {
|
||||
m_cryptoEngine = std::make_unique<PasswordCryptoEngine>(master_key);
|
||||
|
|
@ -138,16 +159,16 @@ bool PasswordManager::locked() const
|
|||
return m_cryptoEngine == nullptr;
|
||||
}
|
||||
|
||||
void PasswordManager::resetMasterPassword(SQLiteConnection &db)
|
||||
void PasswordManager::resetMasterPassword(QSqlDatabase &db)
|
||||
{
|
||||
if (!isPskStoreInitialized(db))
|
||||
return;
|
||||
|
||||
closeDatabase();
|
||||
auto del_algo = db.Prepare("DELETE FROM " + m_secretAlgoTableName + " WHERE id=1");
|
||||
del_algo.Step();
|
||||
auto del_hash = db.Prepare("DELETE FROM " + m_secretHashTableName + " WHERE id=1");
|
||||
del_hash.Step();
|
||||
QSqlQuery del_algo("DELETE FROM " + m_secretAlgoTableName + " WHERE id=1", db);
|
||||
del_algo.exec();
|
||||
QSqlQuery del_hash("DELETE FROM " + m_secretHashTableName + " WHERE id=1", db);
|
||||
del_hash.exec();
|
||||
}
|
||||
|
||||
std::string PasswordManager::encrypt(const std::string &name, const std::string &passwd)
|
||||
|
|
@ -179,13 +200,14 @@ std::string PasswordManager::decrypt(const std::string &id, const std::string_vi
|
|||
}
|
||||
}
|
||||
|
||||
void PasswordManager::initializeNewPskStore(SQLiteConnection &db)
|
||||
void PasswordManager::initializeNewPskStore(QSqlDatabase &db)
|
||||
{
|
||||
// // Create tables
|
||||
// // - psk_masterkey_algo
|
||||
// // - psk_passwd
|
||||
{
|
||||
auto create_tbl = db.Prepare(
|
||||
QSqlQuery create_tbl(db);
|
||||
create_tbl.prepare(
|
||||
"CREATE TABLE IF NOT EXISTS " + m_secretAlgoTableName + "( \n"
|
||||
" id INTEGER PRIMARY KEY, \n"
|
||||
" algo TEXT, \n"
|
||||
|
|
@ -195,55 +217,70 @@ void PasswordManager::initializeNewPskStore(SQLiteConnection &db)
|
|||
" ks INTEGER, \n"
|
||||
" salt TEXT \n"
|
||||
");");
|
||||
create_tbl.Step();
|
||||
if (!create_tbl.exec()) {
|
||||
auto err = create_tbl.lastError();
|
||||
throw SqlException(err);
|
||||
}
|
||||
}
|
||||
|
||||
auto create_tbl = db.Prepare(
|
||||
QSqlQuery create_tbl(db);
|
||||
create_tbl.prepare(
|
||||
"CREATE TABLE IF NOT EXISTS " + m_secretHashTableName + "( \n"
|
||||
" id INTEGER PRIMARY KEY, \n"
|
||||
" hash TEXT \n"
|
||||
");");
|
||||
create_tbl.Step();
|
||||
if (!create_tbl.exec()) {
|
||||
auto err = create_tbl.lastError();
|
||||
throw SqlException(err);
|
||||
}
|
||||
}
|
||||
|
||||
bool PasswordManager::isPskStoreInitialized(SQLiteConnection& db)
|
||||
bool PasswordManager::isPskStoreInitialized(QSqlDatabase& db)
|
||||
{
|
||||
// Is the table with the secret data present and filled?
|
||||
auto query = db.Prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?1");
|
||||
query.Bind(1, m_secretAlgoTableName);
|
||||
if (!query.Step()) {
|
||||
QSqlQuery query(db);
|
||||
query.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=:name");
|
||||
query.bindValue(":name", m_secretAlgoTableName);
|
||||
if (!query.exec()) {
|
||||
auto err = query.lastError();
|
||||
throw SqlException(err);
|
||||
}
|
||||
if (!query.next()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query.Reset();
|
||||
query.Bind(1, m_secretHashTableName);
|
||||
if (!query.Step()) {
|
||||
query.bindValue(":name", m_secretHashTableName);
|
||||
if (!query.exec()) {
|
||||
auto err = query.lastError();
|
||||
throw SqlException(err);
|
||||
}
|
||||
if (!query.next()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto sel_algo = db.Prepare("SELECT algo FROM " + m_secretAlgoTableName + " WHERE id=1");
|
||||
if (!sel_algo.Step()) {
|
||||
QSqlQuery sel_algo("SELECT algo FROM " + m_secretAlgoTableName + " WHERE id=1", db);
|
||||
if (!sel_algo.next()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto sel_hash = db.Prepare("SELECT hash FROM " + m_secretHashTableName + " WHERE id=1");
|
||||
if (!sel_hash.Step()) {
|
||||
QSqlQuery sel_hash("SELECT hash FROM " + m_secretHashTableName + " WHERE id=1", db);
|
||||
if (!sel_hash.next()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
KeyStrengthener PasswordManager::getKeyStrengthener(SQLiteConnection &db)
|
||||
KeyStrengthener PasswordManager::getKeyStrengthener(QSqlDatabase &db)
|
||||
{
|
||||
auto query = db.Prepare("SELECT algo, i1, i2, i3, ks, salt FROM " + m_secretAlgoTableName + " WHERE id=1");
|
||||
if (query.Step()) {
|
||||
std::string algo = query.ColumnCharPtr(0);
|
||||
size_t i1 = query.ColumnInteger(1);
|
||||
size_t i2 = query.ColumnInteger(2);
|
||||
size_t i3 = query.ColumnInteger(3);
|
||||
size_t ks = query.ColumnInteger(4);
|
||||
QByteArray salt = query.ColumnCharPtr(5);
|
||||
QSqlQuery query("SELECT algo, i1, i2, i3, ks, salt FROM " + m_secretAlgoTableName + " WHERE id=1", db);
|
||||
if (query.next()) {
|
||||
std::string algo = query.value(0).toString().toUtf8().data();
|
||||
size_t i1 = query.value(1).toUInt();
|
||||
size_t i2 = query.value(2).toUInt();
|
||||
size_t i3 = query.value(3).toUInt();
|
||||
size_t ks = query.value(4).toUInt();
|
||||
auto salt = query.value(5).toString().toUtf8();
|
||||
|
||||
auto pwh_fam = Botan::PasswordHashFamily::create(algo);
|
||||
return KeyStrengthener(
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef PASSWORDMANAGER_H
|
||||
#define PASSWORDMANAGER_H
|
||||
|
||||
#include "utils/KeyStrengthener.h"
|
||||
#include "KeyStrengthener.h"
|
||||
#include <QSqlDatabase>
|
||||
#include <botan/secmem.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
|
@ -9,6 +10,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include <botan/pwdhash.h>
|
||||
#include <map>
|
||||
|
||||
namespace Botan {
|
||||
|
||||
|
|
@ -45,13 +47,13 @@ public:
|
|||
* If returns false then use createDatabase to set it up
|
||||
* else use openDatabase to get access.
|
||||
*/
|
||||
bool initialized(SQLiteConnection &db);
|
||||
bool createDatabase(SQLiteConnection &db, QString passphrase);
|
||||
bool initialized(QSqlDatabase &db);
|
||||
bool createDatabase(QSqlDatabase &db, QString passphrase);
|
||||
/// Opens the PSK database
|
||||
bool openDatabase(SQLiteConnection &db, QString passphrase);
|
||||
bool openDatabase(QSqlDatabase &db, QString passphrase);
|
||||
void closeDatabase();
|
||||
bool locked() const;
|
||||
void resetMasterPassword(SQLiteConnection &db);
|
||||
void resetMasterPassword(QSqlDatabase &db);
|
||||
|
||||
|
||||
std::string encrypt(const std::string &id, const std::string &passwd);
|
||||
|
|
@ -63,11 +65,11 @@ private:
|
|||
QString m_secretHashTableName = "psk_masterkey_hash";
|
||||
std::unique_ptr<PasswordCryptoEngine> m_cryptoEngine;
|
||||
|
||||
bool isPskStoreInitialized(SQLiteConnection& db);
|
||||
void initializeNewPskStore(SQLiteConnection &db);
|
||||
bool isPskStoreInitialized(QSqlDatabase& db);
|
||||
void initializeNewPskStore(QSqlDatabase &db);
|
||||
|
||||
/// Get PasswordHash from parameters in database
|
||||
KeyStrengthener getKeyStrengthener(SQLiteConnection &db);
|
||||
KeyStrengthener getKeyStrengthener(QSqlDatabase &db);
|
||||
KeyStrengthener createKeyStrengthener();
|
||||
|
||||
std::tuple<Botan::secure_vector<uint8_t>, Botan::secure_vector<uint8_t>>
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
#-------------------------------------------------
|
||||
|
||||
QT -= gui
|
||||
QT += sql
|
||||
|
||||
TARGET = core
|
||||
TEMPLATE = lib
|
||||
|
|
@ -20,13 +21,16 @@ error( "Couldn't find the common.pri file!" )
|
|||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += my_boost_assert_handler.cpp \
|
||||
KeyStrengthener.cpp \
|
||||
SqlLexer.cpp \
|
||||
PasswordManager.cpp \
|
||||
CsvWriter.cpp \
|
||||
BackupFormatModel.cpp \
|
||||
ExplainTreeModelItem.cpp \
|
||||
jsoncpp.cpp
|
||||
|
||||
HEADERS += \
|
||||
HEADERS += PasswordManager.h \
|
||||
KeyStrengthener.h \
|
||||
SqlLexer.h \
|
||||
ScopeGuard.h \
|
||||
CsvWriter.h \
|
||||
|
|
|
|||
|
|
@ -120,7 +120,6 @@ ConnectionConfigurationWidget::ConnectionConfigurationWidget(
|
|||
cmbbxSsl->setModelColumn(0);
|
||||
auto ssl_model = new SslModeModel(this);
|
||||
cmbbxSsl->setModel(ssl_model);
|
||||
cmbbxSsl->setEditable(true);
|
||||
lblSsl->setBuddy(cmbbxSsl);
|
||||
|
||||
lblCert = new QLabel;
|
||||
|
|
@ -207,13 +206,12 @@ void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
|
|||
edtPassword->setText("");
|
||||
|
||||
cmbDbname->setCurrentText(cfg.dbname());
|
||||
cmbbxSsl->setCurrentText(cfg.getParameter("sslmode"));
|
||||
cmbbxSsl->setCurrentIndex(static_cast<int>(cfg.sslMode()));
|
||||
edtCert->setText(cfg.sslCert());
|
||||
edtKey->setText(cfg.sslKey());
|
||||
edtRootCert->setText(cfg.sslRootCert());
|
||||
edtCrl->setText(cfg.sslCrl());
|
||||
|
||||
edtPassword->setText(cfg.password());
|
||||
encodedPassword = cfg.encodedPassword();
|
||||
cbSavePassword->setCheckState(
|
||||
encodedPassword.isEmpty()
|
||||
|
|
@ -234,7 +232,7 @@ ConnectionConfig ConnectionConfigurationWidget::data() const
|
|||
cfg.setUser(edtUser->text());
|
||||
cfg.setPassword(edtPassword->text());
|
||||
cfg.setDbname(cmbDbname->currentText());
|
||||
cfg.setParameter("sslmode", cmbbxSsl->currentText());
|
||||
cfg.setSslMode(static_cast<SslMode>(cmbbxSsl->currentIndex()));
|
||||
cfg.setSslCert(edtCert->text());
|
||||
cfg.setSslKey(edtKey->text());
|
||||
cfg.setSslRootCert(edtRootCert->text());
|
||||
|
|
@ -248,14 +246,14 @@ QString ConnectionConfigurationWidget::group() const
|
|||
return cmbbxGroup->currentText();
|
||||
}
|
||||
|
||||
bool ConnectionConfigurationWidget::savePasswordEnabled() const
|
||||
bool ConnectionConfigurationWidget::savePassword() const
|
||||
{
|
||||
return cbSavePassword->isChecked();
|
||||
return cbSavePassword->isChecked() && !edtPassword->text().isEmpty() && passwordChanged;
|
||||
}
|
||||
|
||||
bool ConnectionConfigurationWidget::passwordIsChanged() const
|
||||
bool ConnectionConfigurationWidget::clearPassword() const
|
||||
{
|
||||
return passwordChanged;
|
||||
return !cbSavePassword->isChecked();
|
||||
}
|
||||
|
||||
void ConnectionConfigurationWidget::testConnection()
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public:
|
|||
ConnectionConfig data() const;
|
||||
QString group() const;
|
||||
|
||||
bool savePasswordEnabled() const;
|
||||
bool passwordIsChanged() const;
|
||||
bool savePassword() const;
|
||||
bool clearPassword() const;
|
||||
|
||||
public slots:
|
||||
void testConnection();
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
#include "MasterController.h"
|
||||
#include "ConnectionManagerWindow.h"
|
||||
#include "ConnectionListModel.h"
|
||||
#include "utils/PasswordManager.h"
|
||||
#include "PasswordManager.h"
|
||||
#include "DatabaseWindow.h"
|
||||
#include "BackupDialog.h"
|
||||
#include "PasswordPromptDialog.h"
|
||||
#include "ScopeGuard.h"
|
||||
#include "ConnectionConfigurationWidget.h"
|
||||
#include <QSqlQuery>
|
||||
#include <QInputDialog>
|
||||
|
|
@ -39,6 +40,7 @@ void ConnectionController::init()
|
|||
m_connectionTreeModel->load();
|
||||
|
||||
m_connectionManagerWindow = new ConnectionManagerWindow(m_masterController, nullptr);
|
||||
m_connectionManagerWindow->show();
|
||||
}
|
||||
|
||||
void ConnectionController::showConnectionManager()
|
||||
|
|
@ -53,21 +55,16 @@ void ConnectionController::openSqlWindowForConnection(QModelIndex index)
|
|||
|
||||
if (retrieveConnectionPassword(*config)) {
|
||||
m_connectionTreeModel->save(*config);
|
||||
|
||||
openSqlWindowForConnection(*config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionController::openSqlWindowForConnection(const ConnectionConfig &config)
|
||||
{
|
||||
// TODO instead of directly openening the mainwindow
|
||||
// do async connect and only open window when we have
|
||||
// working connection
|
||||
auto w = new DatabaseWindow(m_masterController, nullptr);
|
||||
w->setAttribute( Qt::WA_DeleteOnClose );
|
||||
w->setConfig(config);
|
||||
w->setConfig(*config);
|
||||
w->showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ConnectionController::openBackupDlgForConnection(QModelIndex index)
|
||||
|
|
@ -84,14 +81,10 @@ void ConnectionController::openBackupDlgForConnection(QModelIndex index)
|
|||
}
|
||||
}
|
||||
|
||||
void ConnectionController::createConnection(ConnectionConfig *init)
|
||||
void ConnectionController::createConnection()
|
||||
{
|
||||
ConnectionConfig cc;
|
||||
if (init)
|
||||
{
|
||||
cc = *init;
|
||||
cc.setUuid(QUuid());
|
||||
}
|
||||
cc.setUuid(QUuid::createUuid());
|
||||
editConfig(cc);
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +101,7 @@ void ConnectionController::editCopy(QModelIndex index)
|
|||
auto config = ConnectionTreeModel::getConfigFromModelIndex(index);
|
||||
if (config) {
|
||||
auto cc = *config;
|
||||
cc.setUuid(QUuid());
|
||||
cc.setUuid(QUuid::createUuid());
|
||||
cc.setEncodedPassword({}); // maybe we should decode en reencode?
|
||||
editConfig(cc);
|
||||
}
|
||||
|
|
@ -124,20 +117,10 @@ void ConnectionController::saveConnection(ConnectionConfigurationWidget &w)
|
|||
{
|
||||
auto cc = w.data();
|
||||
auto grp = w.group();
|
||||
bool isNew = cc.uuid().isNull();
|
||||
if (isNew)
|
||||
{
|
||||
cc.setUuid(QUuid::createUuid());
|
||||
}
|
||||
if (w.savePasswordEnabled())
|
||||
{
|
||||
if (isNew || w.passwordIsChanged())
|
||||
if (w.savePassword())
|
||||
encryptPassword(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (w.clearPassword())
|
||||
cc.setEncodedPassword({});
|
||||
}
|
||||
m_connectionTreeModel->save(grp, cc);
|
||||
}
|
||||
|
||||
|
|
@ -146,14 +129,11 @@ void ConnectionController::addGroup()
|
|||
auto result = QInputDialog::getText(nullptr, tr("Add new connection group"),
|
||||
tr("Group name"));
|
||||
if (!result.isEmpty()) {
|
||||
try
|
||||
{
|
||||
m_connectionTreeModel->addGroup(result);
|
||||
}
|
||||
catch (const SQLiteException &ex) {
|
||||
auto res = m_connectionTreeModel->addGroup(result);
|
||||
if (std::holds_alternative<QSqlError>(res)) {
|
||||
QMessageBox::critical(nullptr, tr("Add group failed"),
|
||||
tr("Failed to add group.\n") +
|
||||
QString(ex.what()));
|
||||
std::get<QSqlError>(res).text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -221,7 +201,7 @@ bool ConnectionController::retrieveFromPasswordManager(const std::string &passwo
|
|||
password = m_passwordManager->decrypt(password_id, enc_password);
|
||||
return true;
|
||||
}
|
||||
catch (const PasswordManagerException &)
|
||||
catch (const PasswordManagerException &ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -252,11 +232,19 @@ bool ConnectionController::decodeConnectionPassword(QUuid id, QByteArray encoded
|
|||
|
||||
void ConnectionController::resetPasswordManager()
|
||||
{
|
||||
SQLiteConnection& user_cfg_db = m_masterController->userConfigDatabase();
|
||||
SQLiteTransaction tx(user_cfg_db);
|
||||
auto&& user_cfg_db = m_masterController->userConfigDatabase();
|
||||
user_cfg_db.transaction();
|
||||
try
|
||||
{
|
||||
m_passwordManager->resetMasterPassword(user_cfg_db);
|
||||
m_connectionTreeModel->clearAllPasswords();
|
||||
tx.Commit();
|
||||
user_cfg_db.commit();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
user_cfg_db.rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool ConnectionController::UnlockPasswordManagerIfNeeded()
|
||||
|
|
@ -337,7 +325,7 @@ bool ConnectionController::InitializePasswordManager()
|
|||
std::string ConnectionController::getPskId(QUuid connectionid)
|
||||
{
|
||||
std::string id = "dbpw/";
|
||||
id += connectionid.toString(QUuid::WithBraces).toUtf8().data();
|
||||
id += connectionid.toString().toUtf8().data();
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,11 @@ public:
|
|||
|
||||
void showConnectionManager();
|
||||
void openSqlWindowForConnection(QModelIndex index);
|
||||
void openSqlWindowForConnection(const ConnectionConfig &cfg);
|
||||
void openBackupDlgForConnection(QModelIndex index);
|
||||
|
||||
/// Starts the form for creating a new conncetion.
|
||||
/// This function returns immidiatly!
|
||||
void createConnection(ConnectionConfig *init = nullptr);
|
||||
void createConnection();
|
||||
/// Starts the form for editing a conncetion.
|
||||
/// This function returns immidiatly!
|
||||
void editConnection(QModelIndex index);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
#include "ConnectionListModel.h"
|
||||
#include "ScopeGuard.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <botan/cryptobox.h>
|
||||
#include <QDir>
|
||||
#include <QException>
|
||||
#include <QMimeData>
|
||||
#include <QSettings>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QString>
|
||||
#include <QStringBuilder>
|
||||
#include <QStandardPaths>
|
||||
#include <QStringBuilder>
|
||||
#include <ranges>
|
||||
#include <unordered_set>
|
||||
|
||||
|
||||
namespace {
|
||||
|
|
@ -45,195 +41,63 @@ CREATE TABLE IF NOT EXISTS connection (
|
|||
password TEXT
|
||||
);)__";
|
||||
|
||||
const char * const q_create_table_migrations =
|
||||
R"__(
|
||||
CREATE TABLE IF NOT EXISTS _migration (
|
||||
migration_id TEXT PRIMARY KEY
|
||||
);)__";
|
||||
|
||||
const char * const q_load_migrations_present =
|
||||
R"__(
|
||||
SELECT migration_id
|
||||
FROM _migration;)__";
|
||||
|
||||
|
||||
// Keeping migration function name and id DRY
|
||||
#define APPLY_MIGRATION(id) ApplyMigration(#id, &MigrationDirector::id)
|
||||
|
||||
class MigrationDirector {
|
||||
public:
|
||||
explicit MigrationDirector(SQLiteConnection &db)
|
||||
: db(db)
|
||||
{
|
||||
}
|
||||
|
||||
void Execute()
|
||||
{
|
||||
InitConnectionTables();
|
||||
present = LoadMigrations();
|
||||
APPLY_MIGRATION(M20250215_0933_Parameters);
|
||||
}
|
||||
|
||||
private:
|
||||
SQLiteConnection &db;
|
||||
std::unordered_set<QString> present;
|
||||
|
||||
void M20250215_0933_Parameters()
|
||||
{
|
||||
db.Exec(R"__(
|
||||
CREATE TABLE connection_parameter (
|
||||
connection_uuid TEXT,
|
||||
pname TEXT,
|
||||
pvalue TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY(connection_uuid, pname)
|
||||
);)__");
|
||||
|
||||
db.Exec(R"__(
|
||||
INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||
SELECT uuid, 'sslmode' AS pname, CASE
|
||||
WHEN sslmode = '0' THEN 'disable'
|
||||
WHEN sslmode = '1' THEN 'allow'
|
||||
WHEN sslmode = '2' THEN 'prefer'
|
||||
WHEN sslmode = '3' THEN 'require'
|
||||
WHEN sslmode = '4' THEN 'verify_ca'
|
||||
WHEN sslmode = '5' THEN 'verify_full'
|
||||
END AS pvalue
|
||||
FROM connection
|
||||
WHERE sslmode is not null and sslmode between 0 and 5)__");
|
||||
|
||||
|
||||
for (QString key : { "host", "hostaddr", "user", "dbname", "sslcert", "sslkey", "sslrootcert", "sslcrl" })
|
||||
{
|
||||
db.Exec(
|
||||
"INSERT INTO connection_parameter (connection_uuid, pname, pvalue)"
|
||||
" SELECT uuid, '" % key % "', " % key % "\n"
|
||||
" FROM connection\n"
|
||||
" WHERE " % key % " IS NOT NULL and " % key % " <> '';");
|
||||
}
|
||||
db.Exec(R"__(
|
||||
INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||
SELECT uuid, 'port', port
|
||||
FROM connection
|
||||
WHERE port IS NOT NULL;
|
||||
)__");
|
||||
|
||||
for (QString column : { "host", "hostaddr", "user", "dbname", "sslmode", "sslcert", "sslkey", "sslrootcert", "sslcrl", "port" })
|
||||
{
|
||||
// sqlite does not seem to support dropping more then one column per alter table
|
||||
db.Exec("ALTER TABLE connection DROP COLUMN " % column % ";");
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyMigration(QString migration_id, void (MigrationDirector::*func)())
|
||||
{
|
||||
if (!present.contains(migration_id))
|
||||
{
|
||||
SQLiteTransaction tx(db);
|
||||
(this->*func)();
|
||||
RegisterMigration(migration_id);
|
||||
tx.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_set<QString> LoadMigrations()
|
||||
{
|
||||
std::unordered_set<QString> result;
|
||||
|
||||
auto stmt = db.Prepare(q_load_migrations_present);
|
||||
while (stmt.Step())
|
||||
{
|
||||
result.insert(stmt.ColumnText(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void RegisterMigration(QString migrationId)
|
||||
{
|
||||
auto stmt = db.Prepare("INSERT INTO _migration VALUES (?1);");
|
||||
stmt.Bind(1, migrationId);
|
||||
stmt.Step();
|
||||
}
|
||||
|
||||
void InitConnectionTables()
|
||||
{
|
||||
// Original schema
|
||||
db.Exec(q_create_table_conngroup);
|
||||
db.Exec(q_create_table_connection);
|
||||
// Start using migrations
|
||||
db.Exec(q_create_table_migrations);
|
||||
}
|
||||
};
|
||||
|
||||
void RemoveConnection(SQLiteConnection &db, QUuid uuid)
|
||||
{
|
||||
SQLiteTransaction tx(db);
|
||||
|
||||
auto stmt = db.Prepare(
|
||||
"DELETE FROM connection_parameter "
|
||||
" WHERE connection_uuid=?1");
|
||||
stmt.Bind(1, uuid.toString());
|
||||
stmt.Step();
|
||||
|
||||
stmt = db.Prepare(
|
||||
"DELETE FROM connection "
|
||||
" WHERE uuid=?1");
|
||||
stmt.Bind(1, uuid.toString());
|
||||
stmt.Step();
|
||||
|
||||
tx.Commit();
|
||||
}
|
||||
|
||||
|
||||
void SaveConnectionConfig(SQLiteConnection &db, const ConnectionConfig &cc, int conngroup_id)
|
||||
{
|
||||
const char * const q_insert_or_replace_into_connection =
|
||||
R"__(INSERT OR REPLACE INTO connection
|
||||
VALUES (?1, ?2, ?3, ?4);
|
||||
R"__(INSERT OR REPLACE INTO connection
|
||||
VALUES (:uuid, :name, :conngroup_id, :host, :hostaddr, :port, :user, :dbname,
|
||||
:sslmode, :sslcert, :sslkey, :sslrootcert, :sslcrl, :password);
|
||||
)__" ;
|
||||
|
||||
QByteArray b64; // needs to stay in scope until query is executed
|
||||
SQLiteTransaction tx(db);
|
||||
std::tuple<bool, QSqlError> InitConnectionTables(QSqlDatabase &db)
|
||||
{
|
||||
QSqlQuery q_create_table(db);
|
||||
q_create_table.prepare(q_create_table_conngroup);
|
||||
if (!q_create_table.exec()) {
|
||||
auto err = q_create_table.lastError();
|
||||
return { false, err };
|
||||
}
|
||||
q_create_table.prepare(q_create_table_connection);
|
||||
if (!q_create_table.exec()) {
|
||||
auto err = q_create_table.lastError();
|
||||
return { false, err };
|
||||
}
|
||||
return {true, {}};
|
||||
}
|
||||
|
||||
SQLitePreparedStatement stmt = db.Prepare(q_insert_or_replace_into_connection);
|
||||
stmt.Bind(1, cc.uuid().toString());
|
||||
stmt.Bind(2, cc.name());
|
||||
stmt.Bind(3, conngroup_id);
|
||||
std::optional<QSqlError> SaveConnectionConfig(QSqlDatabase &db, const ConnectionConfig &cc, int conngroup_id)
|
||||
{
|
||||
QSqlQuery q(db);
|
||||
q.prepare(q_insert_or_replace_into_connection);
|
||||
q.bindValue(":uuid", cc.uuid().toString());
|
||||
q.bindValue(":name", cc.name());
|
||||
q.bindValue(":conngroup_id", conngroup_id);
|
||||
q.bindValue(":host", cc.host());
|
||||
q.bindValue(":hostaddr", cc.hostAddr());
|
||||
q.bindValue(":port", (int)cc.port());
|
||||
q.bindValue(":user", cc.user());
|
||||
q.bindValue(":dbname", cc.dbname());
|
||||
q.bindValue(":sslmode", static_cast<int>(cc.sslMode()));
|
||||
q.bindValue(":sslcert", cc.sslCert());
|
||||
q.bindValue(":sslkey", cc.sslKey());
|
||||
q.bindValue(":sslrootcert", cc.sslRootCert());
|
||||
q.bindValue(":sslcrl", cc.sslCrl());
|
||||
auto& encodedPassword = cc.encodedPassword();
|
||||
if (!encodedPassword.isEmpty())
|
||||
{
|
||||
stmt.Bind(4, encodedPassword.data(), encodedPassword.length());
|
||||
}
|
||||
stmt.Step();
|
||||
if (encodedPassword.isEmpty())
|
||||
q.bindValue(":password", QVariant());
|
||||
else
|
||||
q.bindValue(":password", encodedPassword);
|
||||
|
||||
stmt = db.Prepare(
|
||||
"DELETE FROM connection_parameter WHERE connection_uuid=?1");
|
||||
stmt.Bind(1, cc.uuid().toString());
|
||||
stmt.Step();
|
||||
|
||||
stmt = db.Prepare(
|
||||
R"__(INSERT INTO connection_parameter (connection_uuid, pname, pvalue)
|
||||
VALUES(?1, ?2, ?3))__");
|
||||
const std::unordered_map<QString, QString>& params = cc.getParameters();
|
||||
for (auto && p : params | std::views::filter(
|
||||
[] (auto ¶m)
|
||||
{
|
||||
// do not save unencrypted password
|
||||
return param.first != "password";
|
||||
}))
|
||||
{
|
||||
stmt.Reset();
|
||||
stmt.Bind(1, cc.uuid().toString());
|
||||
stmt.Bind(2, p.first);
|
||||
stmt.Bind(3, p.second);
|
||||
stmt.Step();
|
||||
if (!q.exec()) {
|
||||
auto sql_error = q.lastError();
|
||||
return { sql_error };
|
||||
}
|
||||
tx.Commit();
|
||||
return {};
|
||||
}
|
||||
|
||||
} // end of unnamed namespace
|
||||
|
||||
ConnectionTreeModel::ConnectionTreeModel(QObject *parent, SQLiteConnection &db)
|
||||
ConnectionTreeModel::ConnectionTreeModel(QObject *parent, QSqlDatabase &db)
|
||||
: QAbstractItemModel(parent)
|
||||
, m_db(db)
|
||||
{
|
||||
|
|
@ -241,41 +105,51 @@ ConnectionTreeModel::ConnectionTreeModel(QObject *parent, SQLiteConnection &db)
|
|||
|
||||
void ConnectionTreeModel::load()
|
||||
{
|
||||
//InitConnectionTables(m_db);
|
||||
MigrationDirector md(m_db);
|
||||
md.Execute();
|
||||
InitConnectionTables(m_db);
|
||||
|
||||
loadGroups();
|
||||
loadConnections();
|
||||
}
|
||||
QSqlQuery q(m_db);
|
||||
q.prepare("SELECT conngroup_id, gname FROM conngroup;");
|
||||
if (!q.exec()) {
|
||||
// auto err = q_create_table.lastError();
|
||||
// return { false, err };
|
||||
throw std::runtime_error("Loading groups failed");
|
||||
}
|
||||
while (q.next()) {
|
||||
int id = q.value(0).toInt();
|
||||
QString name = q.value(1).toString();
|
||||
|
||||
void ConnectionTreeModel::loadGroups()
|
||||
{
|
||||
auto stmt = m_db.Prepare("SELECT conngroup_id, gname FROM conngroup;");
|
||||
while (stmt.Step())
|
||||
{
|
||||
auto g = std::make_shared<ConnectionGroup>();
|
||||
g->conngroup_id = stmt.ColumnInteger(0);
|
||||
g->name = stmt.ColumnText(1);
|
||||
g->conngroup_id = id;
|
||||
g->name = name;
|
||||
m_groups.push_back(g);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionTreeModel::loadConnections()
|
||||
{
|
||||
auto stmt = m_db.Prepare(
|
||||
"SELECT uuid, cname, conngroup_id, password "
|
||||
q.prepare("SELECT uuid, cname, conngroup_id, host, hostaddr, port, "
|
||||
" user, dbname, sslmode, sslcert, sslkey, sslrootcert, sslcrl, "
|
||||
" password "
|
||||
"FROM connection ORDER BY conngroup_id, cname;");
|
||||
|
||||
while (stmt.Step()) {
|
||||
if (!q.exec()) {
|
||||
// auto err = q_create_table.lastError();
|
||||
// return { false, err };
|
||||
throw std::runtime_error("Loading groups failed");
|
||||
}
|
||||
while (q.next()) {
|
||||
auto cc = std::make_shared<ConnectionConfig>();
|
||||
cc->setUuid(QUuid::fromString(stmt.ColumnText(0)));
|
||||
cc->setName(stmt.ColumnText(1));
|
||||
const char* p = stmt.ColumnCharPtr(3);
|
||||
cc->setEncodedPassword(p);
|
||||
loadConnectionParameters(*cc);
|
||||
cc->setUuid(q.value(0).toUuid());
|
||||
cc->setName(q.value(1).toString());
|
||||
cc->setHost(q.value(3).toString());
|
||||
cc->setHostAddr(q.value(4).toString());
|
||||
cc->setPort(static_cast<uint16_t>(q.value(5).toInt()));
|
||||
cc->setUser(q.value(6).toString());
|
||||
cc->setDbname(q.value(7).toString());
|
||||
cc->setSslMode(static_cast<SslMode>(q.value(8).toInt()));
|
||||
cc->setSslCert(q.value(9).toString());
|
||||
cc->setSslKey(q.value(10).toString());
|
||||
cc->setSslRootCert(q.value(11).toString());
|
||||
cc->setSslCrl(q.value(12).toString());
|
||||
cc->setEncodedPassword(q.value(13).toByteArray());
|
||||
|
||||
int group_id = stmt.ColumnInteger(2);
|
||||
int group_id = q.value(2).toInt();
|
||||
auto find_res = std::find_if(m_groups.begin(), m_groups.end(),
|
||||
[group_id] (auto item) { return item->conngroup_id == group_id; });
|
||||
if (find_res != m_groups.end()) {
|
||||
|
|
@ -287,22 +161,6 @@ void ConnectionTreeModel::loadConnections()
|
|||
}
|
||||
}
|
||||
|
||||
void ConnectionTreeModel::loadConnectionParameters(ConnectionConfig &cc)
|
||||
{
|
||||
auto stmt = m_db.Prepare(
|
||||
"SELECT pname, pvalue \n"
|
||||
"FROM connection_parameter\n"
|
||||
"WHERE connection_uuid=?1");
|
||||
stmt.Bind(1, cc.uuid().toString());
|
||||
while (stmt.Step())
|
||||
{
|
||||
cc.setParameter(
|
||||
stmt.ColumnText(0),
|
||||
stmt.ColumnText(1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ConnectionTreeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// Code below assumes two level tree groups/connections
|
||||
|
|
@ -422,7 +280,15 @@ bool ConnectionTreeModel::removeRows(int row, int count, const QModelIndex &pare
|
|||
auto grp = m_groups[parent.row()];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QUuid uuid = grp->connections().at(row + i)->uuid();
|
||||
RemoveConnection(m_db, uuid);
|
||||
QSqlQuery q(m_db);
|
||||
q.prepare(
|
||||
"DELETE FROM connection "
|
||||
" WHERE uuid=:uuid");
|
||||
q.bindValue(":uuid", uuid);
|
||||
if (!q.exec()) {
|
||||
auto err = q.lastError();
|
||||
throw std::runtime_error("QqlError");
|
||||
}
|
||||
}
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
SCOPE_EXIT { endRemoveRows(); };
|
||||
|
|
@ -442,7 +308,7 @@ void ConnectionTreeModel::save(const QString &group_name, const ConnectionConfig
|
|||
grp->update(conn_idx, cc);
|
||||
// send change event
|
||||
auto node = grp->connections().at(conn_idx);
|
||||
emit dataChanged(
|
||||
dataChanged(
|
||||
createIndex(conn_idx, 0, node.get()),
|
||||
createIndex(conn_idx, ColCount-1, node.get()));
|
||||
saveToDb(*node);
|
||||
|
|
@ -461,7 +327,13 @@ void ConnectionTreeModel::save(const QString &group_name, const ConnectionConfig
|
|||
int new_grp_idx = findGroup(group_name);
|
||||
if (new_grp_idx < 0) {
|
||||
// Group not found we are g
|
||||
new_grp_idx = addGroup(group_name);
|
||||
auto add_grp_res = addGroup(group_name);
|
||||
if (std::holds_alternative<int>(add_grp_res)) {
|
||||
new_grp_idx = std::get<int>(add_grp_res);
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("SqlError1");
|
||||
}
|
||||
}
|
||||
auto new_grp = m_groups[new_grp_idx];
|
||||
|
||||
|
|
@ -471,7 +343,14 @@ void ConnectionTreeModel::save(const QString &group_name, const ConnectionConfig
|
|||
SCOPE_EXIT { endInsertRows(); };
|
||||
auto node = std::make_shared<ConnectionConfig>(cc);
|
||||
new_grp->add(node);
|
||||
saveToDb(*node);
|
||||
auto save_res = saveToDb(*node);
|
||||
if (save_res) {
|
||||
QString msg = save_res->text()
|
||||
% "\n" % save_res->driverText()
|
||||
% "\n" % save_res->databaseText();
|
||||
|
||||
throw std::runtime_error(msg.toUtf8().data());
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionTreeModel::save(const ConnectionConfig &cc)
|
||||
|
|
@ -516,13 +395,17 @@ int ConnectionTreeModel::findGroup(const QString &name) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
int ConnectionTreeModel::addGroup(const QString &group_name)
|
||||
std::variant<int, QSqlError> ConnectionTreeModel::addGroup(const QString &group_name)
|
||||
{
|
||||
auto stmt = m_db.Prepare("INSERT INTO conngroup (gname) VALUES (?1)");
|
||||
stmt.Bind(1, group_name);
|
||||
|
||||
QSqlQuery q(m_db);
|
||||
q.prepare("INSERT INTO conngroup (gname) VALUES (:name)");
|
||||
q.bindValue(":name", group_name);
|
||||
if (!q.exec()) {
|
||||
auto err = q.lastError();
|
||||
return { err };
|
||||
}
|
||||
auto cg = std::make_shared<ConnectionGroup>();
|
||||
cg->conngroup_id = m_db.LastInsertRowId();
|
||||
cg->conngroup_id = q.lastInsertId().toInt();
|
||||
cg->name = group_name;
|
||||
|
||||
int row = m_groups.size();
|
||||
|
|
@ -532,21 +415,27 @@ int ConnectionTreeModel::addGroup(const QString &group_name)
|
|||
return row;
|
||||
}
|
||||
|
||||
void ConnectionTreeModel::removeGroup(int row)
|
||||
std::optional<QSqlError> ConnectionTreeModel::removeGroup(int row)
|
||||
{
|
||||
beginRemoveRows({}, row, row);
|
||||
SCOPE_EXIT { endRemoveRows(); };
|
||||
auto id = m_groups[row]->conngroup_id;
|
||||
|
||||
auto stmt = m_db.Prepare("DELETE FROM connection WHERE conngroup_id=?1");
|
||||
stmt.Bind(1, id);
|
||||
stmt.Step();
|
||||
|
||||
stmt = m_db.Prepare("DELETE FROM conngroup WHERE conngroup_id=?1");
|
||||
stmt.Bind(1, id);
|
||||
stmt.Step();
|
||||
QSqlQuery q(m_db);
|
||||
q.prepare("DELETE FROM connection WHERE conngroup_id=:id");
|
||||
q.bindValue(":id", id);
|
||||
if (!q.exec()) {
|
||||
auto err = q.lastError();
|
||||
return { err };
|
||||
}
|
||||
q.prepare("DELETE FROM conngroup WHERE conngroup_id=:id");
|
||||
q.bindValue(":id", id);
|
||||
if (!q.exec()) {
|
||||
auto err = q.lastError();
|
||||
return { err };
|
||||
}
|
||||
|
||||
m_groups.remove(row);
|
||||
return {};
|
||||
}
|
||||
|
||||
int ConnectionTreeModel::findGroup(int conngroup_id) const
|
||||
|
|
@ -574,9 +463,9 @@ ConnectionGroup *ConnectionTreeModel::getGroupFromModelIndex(QModelIndex index)
|
|||
return dynamic_cast<ConnectionGroup*>(node);
|
||||
}
|
||||
|
||||
void ConnectionTreeModel::saveToDb(const ConnectionConfig &cc)
|
||||
std::optional<QSqlError> ConnectionTreeModel::saveToDb(const ConnectionConfig &cc)
|
||||
{
|
||||
SaveConnectionConfig(m_db, cc, cc.parent()->conngroup_id);
|
||||
return SaveConnectionConfig(m_db, cc, cc.parent()->conngroup_id);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@
|
|||
#include <variant>
|
||||
#include <QVector>
|
||||
|
||||
#include "sqlite/SQLiteConnection.h"
|
||||
#include <QSqlError>
|
||||
class QSqlDatabase;
|
||||
|
||||
class ConnectionTreeModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
|
@ -26,7 +27,7 @@ public:
|
|||
ColCount
|
||||
};
|
||||
|
||||
ConnectionTreeModel(QObject *parent, SQLiteConnection &db);
|
||||
ConnectionTreeModel(QObject *parent, QSqlDatabase &db);
|
||||
|
||||
void load();
|
||||
|
||||
|
|
@ -60,8 +61,8 @@ public:
|
|||
void save(const ConnectionConfig &cc);
|
||||
void clearAllPasswords();
|
||||
/// Create a new group in the DB and place in the tree
|
||||
int addGroup(const QString &group_name);
|
||||
void removeGroup(int row);
|
||||
std::variant<int, QSqlError> addGroup(const QString &group_name);
|
||||
std::optional<QSqlError> removeGroup(int row);
|
||||
int findGroup(int conngroup_id) const;
|
||||
|
||||
static ConnectionConfig* getConfigFromModelIndex(QModelIndex index);
|
||||
|
|
@ -70,7 +71,7 @@ public:
|
|||
private:
|
||||
using Groups = QVector<std::shared_ptr<ConnectionGroup>>;
|
||||
|
||||
SQLiteConnection &m_db;
|
||||
QSqlDatabase &m_db;
|
||||
Groups m_groups;
|
||||
|
||||
/// Finds the connection with the specified uuid and returns
|
||||
|
|
@ -78,11 +79,8 @@ private:
|
|||
std::tuple<int, int> findConfig(const QUuid uuid) const;
|
||||
int findGroup(const QString &name) const;
|
||||
|
||||
void saveToDb(const ConnectionConfig &cc);
|
||||
std::optional<QSqlError> saveToDb(const ConnectionConfig &cc);
|
||||
|
||||
void loadGroups();
|
||||
void loadConnections();
|
||||
void loadConnectionParameters(ConnectionConfig &cc);
|
||||
// QAbstractItemModel interface
|
||||
public:
|
||||
virtual Qt::DropActions supportedDropActions() const override;
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ enum class ReferencedType {
|
|||
};
|
||||
|
||||
///
|
||||
enum class DataMeaning {
|
||||
Normal,
|
||||
Bytes ///< the value represents bytes pretty print in KiB, MiB, GiB, TiB, PiB, EiB
|
||||
enum DataMeaning {
|
||||
DataMeaningNormal,
|
||||
DataMeaningBytes ///< the value represents bytes pretty print in KiB, MiB, GiB, TiB, PiB, EiB
|
||||
};
|
||||
|
||||
enum CustomDataRole {
|
||||
|
|
|
|||
|
|
@ -443,12 +443,6 @@ void DatabaseWindow::on_actionShow_connection_manager_triggered()
|
|||
m_masterController->connectionController()->showConnectionManager();
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionSave_connection_triggered()
|
||||
{
|
||||
if (m_config.uuid().isNull())
|
||||
m_masterController->connectionController()->createConnection(&m_config);
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionManual_triggered()
|
||||
{
|
||||
OpenManual();
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ private slots:
|
|||
void on_actionSave_query_as_triggered();
|
||||
void on_actionSave_copy_of_query_as_triggered();
|
||||
void on_actionShow_connection_manager_triggered();
|
||||
void on_actionSave_connection_triggered();
|
||||
|
||||
void on_actionManual_triggered();
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1260</width>
|
||||
<height>21</height>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
@ -44,7 +44,6 @@
|
|||
<addaction name="actionSave_query_as"/>
|
||||
<addaction name="actionSave_copy_of_query_as"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionSave_connection"/>
|
||||
<addaction name="actionExport_data"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionClose"/>
|
||||
|
|
@ -332,11 +331,6 @@
|
|||
<string>Manual</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_connection">
|
||||
<property name="text">
|
||||
<string>Save connection</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
#include "MasterController.h"
|
||||
#include "ConnectionController.h"
|
||||
#include "utils/PostgresqlUrlParser.h"
|
||||
#include <ConnectionConfig.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
|
@ -30,23 +27,18 @@ MasterController::~MasterController()
|
|||
|
||||
void MasterController::init()
|
||||
{
|
||||
m_userConfigDatabase.Open(GetUserConfigDatabaseName());
|
||||
m_userConfigDatabase = QSqlDatabase::addDatabase("QSQLITE");
|
||||
m_userConfigDatabase.setDatabaseName(GetUserConfigDatabaseName());
|
||||
|
||||
if (!m_userConfigDatabase.open()) {
|
||||
qDebug() << "Error: connection with database fail";
|
||||
}
|
||||
else {
|
||||
qDebug() << "Database: connection ok";
|
||||
}
|
||||
|
||||
m_connectionController = new ConnectionController(this);
|
||||
m_connectionController->init();
|
||||
|
||||
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
for (auto && arg : arguments)
|
||||
{
|
||||
ConnectionConfig cfg;
|
||||
if (TryParsePostgresqlUrl(arg, cfg)) {
|
||||
m_connectionController->openSqlWindowForConnection(cfg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_connectionController->showConnectionManager();
|
||||
}
|
||||
|
||||
ConnectionController *MasterController::connectionController()
|
||||
|
|
@ -54,7 +46,7 @@ ConnectionController *MasterController::connectionController()
|
|||
return m_connectionController;
|
||||
}
|
||||
|
||||
SQLiteConnection& MasterController::userConfigDatabase()
|
||||
QSqlDatabase& MasterController::userConfigDatabase()
|
||||
{
|
||||
return m_userConfigDatabase;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
#define MASTERCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "sqlite/SQLiteConnection.h"
|
||||
|
||||
|
||||
class ConnectionController;
|
||||
|
|
@ -23,14 +23,14 @@ public:
|
|||
void init();
|
||||
|
||||
ConnectionController* connectionController();
|
||||
SQLiteConnection& userConfigDatabase();
|
||||
QSqlDatabase& userConfigDatabase();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
SQLiteConnection m_userConfigDatabase;
|
||||
QSqlDatabase m_userConfigDatabase;
|
||||
ConnectionController* m_connectionController = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ OpenDatabase::OpenDatabaseSPtr OpenDatabase::createOpenDatabase(const Connection
|
|||
odb->Init();
|
||||
return odb;
|
||||
}
|
||||
catch (const std::exception &ex) {
|
||||
catch (const Pgsql::PgException &ex) {
|
||||
throw OpenDatabaseException(ex.what());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "ResultTableModelUtil.h"
|
||||
#include "Pgsql_oids.h"
|
||||
#include <QTableView>
|
||||
#include <QHeaderView>
|
||||
|
||||
|
|
@ -27,7 +28,29 @@ Qt::Alignment GetDefaultAlignmentForType(Oid o)
|
|||
return r;
|
||||
}
|
||||
|
||||
|
||||
QColor GetDefaultColorForType(Oid o)
|
||||
{
|
||||
QColor c;
|
||||
switch (o) {
|
||||
case int2_oid:
|
||||
case int4_oid:
|
||||
case int8_oid:
|
||||
c = GetDefaultIntegerColor();
|
||||
break;
|
||||
case float4_oid:
|
||||
case float8_oid:
|
||||
c = GetDefaultFloatColor();
|
||||
break;
|
||||
case numeric_oid:
|
||||
c = GetDefaultNumericColor();
|
||||
break;
|
||||
case oid_oid:
|
||||
case bool_oid:
|
||||
default:
|
||||
c = Qt::black;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
QString FormatBoolForDisplay(bool v)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,36 +1,10 @@
|
|||
#pragma once
|
||||
#include "Pgsql_oids.h"
|
||||
#include "Pgsql_declare.h"
|
||||
#include <QAbstractTableModel>
|
||||
#include <QColor>
|
||||
#include <util/Colors.h>
|
||||
|
||||
Qt::Alignment GetDefaultAlignmentForType(Oid oid);
|
||||
|
||||
// inline QColor GetDefaultColorForType(Oid oid)
|
||||
// {
|
||||
// using namespace Pgsql;
|
||||
// const ColorTheme &theme = GetColorTheme();
|
||||
// QColor c;
|
||||
// switch (oid) {
|
||||
// case int2_oid:
|
||||
// case int4_oid:
|
||||
// case int8_oid:
|
||||
// c = theme.integerColor;
|
||||
// break;
|
||||
// case float4_oid:
|
||||
// case float8_oid:
|
||||
// c = theme.floatColor;
|
||||
// break;
|
||||
// case numeric_oid:
|
||||
// c = theme.numericColor;
|
||||
// break;
|
||||
// case oid_oid:
|
||||
// case bool_oid:
|
||||
// default:
|
||||
// c = Qt::black;
|
||||
// }
|
||||
// return c;
|
||||
// }
|
||||
QColor GetDefaultColorForType(Oid oid);
|
||||
|
||||
inline Qt::Alignment GetDefaultAlignment() { return Qt::AlignLeft | Qt::AlignVCenter; }
|
||||
inline Qt::Alignment GetDefaultBoolAlignment() { return Qt::AlignCenter | Qt::AlignVCenter; }
|
||||
|
|
@ -38,14 +12,13 @@ inline Qt::Alignment GetDefaultNumberAlignment() { return Qt::AlignRight | Qt::A
|
|||
|
||||
inline QColor GetDefaultBoolColor(bool v)
|
||||
{
|
||||
const ColorTheme& colorTheme = GetColorTheme();
|
||||
return v ? colorTheme.booleanTrue : colorTheme.booleanFalse;
|
||||
return v ? Qt::darkGreen : Qt::darkRed;
|
||||
}
|
||||
|
||||
// inline QColor GetDefaultIntegerColor() { return Qt::darkBlue; }
|
||||
// inline QColor GetDefaultFloatColor() { return Qt::darkCyan; }
|
||||
// inline QColor GetDefaultNumericColor() { return Qt::darkGreen; }
|
||||
// inline QColor GetDefaultNullColor() { return Qt::gray; }
|
||||
inline QColor GetDefaultIntegerColor() { return Qt::darkBlue; }
|
||||
inline QColor GetDefaultFloatColor() { return Qt::darkCyan; }
|
||||
inline QColor GetDefaultNumericColor() { return Qt::darkGreen; }
|
||||
inline QColor GetDefaultNullColor() { return Qt::gray; }
|
||||
|
||||
QString FormatBoolForDisplay(bool v);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,5 @@ QVariant BaseTableModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
QVariant BaseTableModel::getDataMeaning(const QModelIndex &) const
|
||||
{
|
||||
return static_cast<int>(DataMeaning::Normal);
|
||||
return static_cast<int>(DataMeaningNormal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,6 @@ namespace {
|
|||
|
||||
}
|
||||
|
||||
ColumnTableModel::ColumnTableModel(QObject *parent)
|
||||
: BaseTableModel(parent)
|
||||
, theme(GetColorTheme())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &table)
|
||||
{
|
||||
if (cat != m_catalog) {
|
||||
|
|
@ -292,19 +285,22 @@ QVariant ColumnTableModel::data(const QModelIndex &index, int role) const
|
|||
QVariant v;
|
||||
const auto &t = m_columns[index.row()];
|
||||
if (t.typid == InvalidOid)
|
||||
v = QBrush(theme.defaultTextColor);
|
||||
v = QBrush(Qt::black);
|
||||
else {
|
||||
auto c = m_catalog->types()->getByKey(t.typid);
|
||||
switch (c->category) {
|
||||
case TypCategory::Boolean:
|
||||
v = QBrush(Qt::darkGreen);
|
||||
break;
|
||||
case TypCategory::Numeric:
|
||||
v = QBrush(theme.numericTypeColor);
|
||||
v = QBrush(Qt::darkBlue);
|
||||
break;
|
||||
case TypCategory::DateTime:
|
||||
case TypCategory::Timespan:
|
||||
v = QBrush(theme.dateTimeTypeColor);
|
||||
v = QBrush(Qt::darkMagenta);
|
||||
break;
|
||||
case TypCategory::String:
|
||||
v = QBrush(theme.stringTypeColor);
|
||||
v = QBrush(Qt::darkYellow);
|
||||
break;
|
||||
case TypCategory::Array:
|
||||
case TypCategory::Composite:
|
||||
|
|
@ -317,8 +313,7 @@ QVariant ColumnTableModel::data(const QModelIndex &index, int role) const
|
|||
case TypCategory::BitString:
|
||||
case TypCategory::Unknown:
|
||||
default:
|
||||
v = QBrush(theme.defaultTextColor);
|
||||
break;
|
||||
v = QBrush(Qt::black);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef COLUMNTABLEMODEL_H
|
||||
#define COLUMNTABLEMODEL_H
|
||||
|
||||
#include "util/Colors.h"
|
||||
#include "catalog/models/BaseTableModel.h"
|
||||
#include "catalog/PgAttribute.h"
|
||||
#include "catalog/PgDatabaseCatalog.h"
|
||||
|
|
@ -30,8 +29,7 @@ public:
|
|||
colCount };
|
||||
|
||||
|
||||
|
||||
explicit ColumnTableModel(QObject *parent = nullptr);
|
||||
using BaseTableModel::BaseTableModel;
|
||||
void setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &table);
|
||||
|
||||
// Header:
|
||||
|
|
@ -59,9 +57,6 @@ protected:
|
|||
QString getFKey(const PgAttribute &column) const;
|
||||
QString getDefaultString(const PgAttribute &column) const;
|
||||
|
||||
private:
|
||||
const ColorTheme &theme;
|
||||
|
||||
private slots:
|
||||
/// Retrieves required data from catalog, called everytime it might have changed
|
||||
void refresh();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include "catalog/PgDatabaseContainer.h"
|
||||
#include "catalog/PgAuthIdContainer.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include <QtConcurrent>
|
||||
#include "Pgsql_Connection.h"
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ void DatabasesTableModel::setDatabaseList(std::shared_ptr<const PgDatabaseCatalo
|
|||
for (const auto& d : *dats)
|
||||
{
|
||||
databases.emplace_back(d);
|
||||
oidIndex.emplace(d.oid(), static_cast<int>(databases.size() - 1));
|
||||
oidIndex.emplace(d.oid(), databases.size() - 1);
|
||||
}
|
||||
StartLoadDatabaseSizes(std::move(oidIndex));
|
||||
}
|
||||
|
|
@ -89,7 +90,7 @@ QVariant DatabasesTableModel::headerData(int section, Qt::Orientation orientatio
|
|||
int DatabasesTableModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
int result = 0;
|
||||
result = static_cast<int>(databases.size());
|
||||
result = databases.size();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +183,7 @@ QVariant DatabasesTableModel::getDataMeaning(const QModelIndex &index) const
|
|||
{
|
||||
if (index.column() == SizeCol)
|
||||
{
|
||||
return static_cast<int>(DataMeaning::Bytes);
|
||||
return static_cast<int>(DataMeaningBytes);
|
||||
}
|
||||
return BaseTableModel::getDataMeaning(index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,9 +133,9 @@ QVariant IndexModel::data(const QModelIndex &index, int role) const
|
|||
else if (role == CustomDataMeaningRole) {
|
||||
switch (index.column()) {
|
||||
case SizeCol:
|
||||
return static_cast<int>(DataMeaning::Bytes);
|
||||
return static_cast<int>(DataMeaningBytes);
|
||||
default:
|
||||
return static_cast<int>(DataMeaning::Normal);
|
||||
return static_cast<int>(DataMeaningNormal);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
|
|
|
|||
|
|
@ -200,9 +200,9 @@ QVariant TablesTableModel::data(const QModelIndex &index, int role) const
|
|||
case TableSizeCol:
|
||||
case IndexSizeCol:
|
||||
case ToastSizeCol:
|
||||
return static_cast<int>(DataMeaning::Bytes);
|
||||
return static_cast<int>(DataMeaningBytes);
|
||||
default:
|
||||
return static_cast<int>(DataMeaning::Normal);
|
||||
return static_cast<int>(DataMeaningNormal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -304,5 +304,5 @@ std::function<bool (const PgClass &)> TablesTableModel::GetNamespaceFilterLambda
|
|||
case NamespaceFilter::InformationSchema:
|
||||
return [] (const PgClass &c) { return c.ns().objectName() == "information_schema"; };
|
||||
}
|
||||
throw std::logic_error("missing case");
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ CatalogInspector::CatalogInspector(std::shared_ptr<OpenDatabase> open_database,
|
|||
: QWidget(parent)
|
||||
{
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
m_namespacePage = new CatalogNamespacePage(this);
|
||||
// m_namespacePage = new CatalogNamespacePage(this);
|
||||
m_tablesPage = new CatalogTablesPage(open_database, this);
|
||||
m_functionsPage = new CatalogFunctionsPage(this);
|
||||
m_sequencesPage = new CatalogSequencesPage(this);
|
||||
|
|
@ -26,7 +26,7 @@ CatalogInspector::CatalogInspector(std::shared_ptr<OpenDatabase> open_database,
|
|||
auto layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
layout->addWidget(m_tabWidget);
|
||||
m_tabWidget->addTab(m_namespacePage, "");
|
||||
// m_tabWidget->addTab(m_namespacePage, "");
|
||||
m_tabWidget->addTab(m_tablesPage, "");
|
||||
m_tabWidget->addTab(m_functionsPage, "");
|
||||
m_tabWidget->addTab(m_sequencesPage, "");
|
||||
|
|
@ -40,8 +40,8 @@ void CatalogInspector::retranslateUi(bool all)
|
|||
{
|
||||
m_tablesPage->retranslateUi(all);
|
||||
|
||||
m_tabWidget->setTabText(m_tabWidget->indexOf(m_namespacePage),
|
||||
QApplication::translate("CatalogInspector", "Schemas", nullptr));
|
||||
// m_tabWidget->setTabText(m_tabWidget->indexOf(m_namespacePage),
|
||||
// QApplication::translate("CatalogInspector", "Schemas", nullptr));
|
||||
m_tabWidget->setTabText(m_tabWidget->indexOf(m_tablesPage),
|
||||
QApplication::translate("CatalogInspector", "Tables", nullptr));
|
||||
m_tabWidget->setTabText(m_tabWidget->indexOf(m_functionsPage),
|
||||
|
|
@ -59,7 +59,7 @@ CatalogInspector::~CatalogInspector()
|
|||
void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_namespacePage->setCatalog(cat);
|
||||
// m_namespacePage->setCatalog(cat);
|
||||
m_tablesPage->setCatalog(cat);
|
||||
m_functionsPage->setCatalog(cat);
|
||||
m_sequencesPage->setCatalog(cat);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public:
|
|||
CatalogTablesPage *tablesPage();
|
||||
private:
|
||||
QTabWidget *m_tabWidget = nullptr;
|
||||
CatalogNamespacePage *m_namespacePage = nullptr;
|
||||
// CatalogNamespacePage *m_namespacePage = nullptr;
|
||||
CatalogTablesPage *m_tablesPage = nullptr;
|
||||
CatalogFunctionsPage *m_functionsPage = nullptr;
|
||||
CatalogSequencesPage *m_sequencesPage = nullptr;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
CodeEditor::CodeEditor(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
, gutterArea(new EditorGutter(this))
|
||||
, colorTheme(GetColorTheme())
|
||||
{
|
||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateGutterAreaWidth(int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateGutterArea(QRect,int)));
|
||||
|
|
@ -70,7 +69,8 @@ void CodeEditor::resizeEvent(QResizeEvent *e)
|
|||
void CodeEditor::highlightCurrentLine()
|
||||
{
|
||||
QTextEdit::ExtraSelection selection;
|
||||
selection.format.setBackground(colorTheme.currentLine);
|
||||
QColor lineColor = QColor(Qt::yellow).lighter(160);
|
||||
selection.format.setBackground(lineColor);
|
||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.clearSelection();
|
||||
|
|
@ -87,7 +87,8 @@ void CodeEditor::onTextChanged()
|
|||
void CodeEditor::addErrorMarker(int position, int length)
|
||||
{
|
||||
QTextEdit::ExtraSelection selection;
|
||||
selection.format.setBackground(colorTheme.errorLine);
|
||||
QColor lineColor = QColor(Qt::red).lighter(160);
|
||||
selection.format.setBackground(lineColor);
|
||||
selection.format.setFontItalic(true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.setPosition(position);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <QPlainTextEdit>
|
||||
#include <set>
|
||||
#include "util/Colors.h"
|
||||
|
||||
/** This class adds some capabilities to QPlainTextEdit that are useful
|
||||
* in code editor scenarios.
|
||||
|
|
@ -40,7 +39,6 @@ private:
|
|||
|
||||
QTextEdit::ExtraSelection currentLine;
|
||||
QList<QTextEdit::ExtraSelection> errorMarkers;
|
||||
const ColorTheme &colorTheme;
|
||||
|
||||
std::set<int> errorLines;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,14 +7,11 @@ GutterPainter::GutterPainter(CodeEditor *editor, QPaintEvent *event)
|
|||
, painter(editor->gutterArea)
|
||||
, event(event)
|
||||
, fontMetrics(editor->fontMetrics())
|
||||
, colorTheme(GetColorTheme())
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
void GutterPainter::Paint()
|
||||
{
|
||||
painter.fillRect(event->rect(), colorTheme.gutterBackground);
|
||||
painter.fillRect(event->rect(), Qt::lightGray);
|
||||
|
||||
LoopState loopState(editor);
|
||||
// We will now loop through all visible lines and paint the line numbers in the
|
||||
|
|
@ -40,7 +37,7 @@ void GutterPainter::Paint()
|
|||
void GutterPainter::drawLineNumber(const LoopState &loopState)
|
||||
{
|
||||
QString number = QString::number(loopState.blockNumber() + 1);
|
||||
painter.setPen(colorTheme.lineNumber);
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(0, loopState.top, editor->gutterArea->width(), fontMetrics.height(),
|
||||
Qt::AlignRight, number);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include <QPainter>
|
||||
#include <QTextBlock>
|
||||
#include "util/Colors.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -14,13 +13,10 @@ public:
|
|||
|
||||
void Paint();
|
||||
private:
|
||||
|
||||
CodeEditor *editor;
|
||||
QPainter painter;
|
||||
QPaintEvent *event;
|
||||
QFontMetrics fontMetrics;
|
||||
const ColorTheme &colorTheme;
|
||||
|
||||
|
||||
struct LoopState {
|
||||
CodeEditor *editor;
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ void CrudModel::loadIntoModel(std::shared_ptr<Pgsql::Result> data)
|
|||
initializeColumnList();
|
||||
lastRowKey = data->rows() - 1;
|
||||
initRowMapping();
|
||||
appendNewRowInternal();
|
||||
appendNewRow();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
|
@ -247,9 +247,9 @@ void CrudModel::initRowMapping()
|
|||
m_rowMapping.emplace_back(i);
|
||||
}
|
||||
|
||||
void CrudModel::connectionStateChanged()
|
||||
void CrudModel::connectionStateChanged(ASyncDBConnection::StateData state)
|
||||
{
|
||||
switch (m_dbConn.state()) {
|
||||
switch (state.State) {
|
||||
case ASyncDBConnection::State::NotConnected:
|
||||
break;
|
||||
case ASyncDBConnection::State::Connecting:
|
||||
|
|
@ -429,7 +429,7 @@ std::tuple<QString, Pgsql::Params> CrudModel::createInsertQuery(const PendingRow
|
|||
first = false;
|
||||
else
|
||||
q << ",";
|
||||
q << quoteIdent(column.name);
|
||||
q << column.name;
|
||||
}
|
||||
q << ") VALUES ($1";
|
||||
for (size_t p = 2; p <= data.size(); ++p)
|
||||
|
|
@ -525,8 +525,7 @@ void CrudModel::initializeColumnList()
|
|||
{
|
||||
columnList.clear();
|
||||
columnList.reserve(m_roData->cols());
|
||||
auto atts = m_database->catalog()->attributes();
|
||||
auto columns = atts->getColumnsForRelation(m_table->oid());
|
||||
auto columns = m_database->catalog()->attributes()->getColumnsForRelation(m_table->oid());
|
||||
for (int col = 0; col < m_roData->cols(); ++col)
|
||||
{
|
||||
int attnum = m_roData->ftableCol(col);
|
||||
|
|
@ -548,15 +547,10 @@ void CrudModel::revert()
|
|||
|
||||
void CrudModel::appendNewRow()
|
||||
{
|
||||
int row = static_cast<int>(m_rowMapping.size());
|
||||
int row = m_rowMapping.size();
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
appendNewRowInternal();
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void CrudModel::appendNewRowInternal()
|
||||
{
|
||||
m_rowMapping.emplace_back(allocNewRowKey(), std::vector<Value>(m_roData->cols()));
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> CrudModel::removeRows(const std::set<IntegerRange<int>> &row_ranges)
|
||||
|
|
|
|||
|
|
@ -211,13 +211,6 @@ private:
|
|||
bool callLoadData = false;
|
||||
|
||||
std::shared_ptr<Pgsql::Result> m_roData;
|
||||
|
||||
struct ColumnData
|
||||
{
|
||||
std::string name;
|
||||
// identity allways or generated
|
||||
};
|
||||
|
||||
std::vector<PgAttribute> columnList; // list of columnMeta 1 to 1 with columns in m_roData.
|
||||
|
||||
PendingRowList m_pendingRowList;
|
||||
|
|
@ -253,7 +246,6 @@ private:
|
|||
std::tuple<bool, std::vector<Value>> saveRow(const PendingRow &pending_row);
|
||||
|
||||
void appendNewRow();
|
||||
void appendNewRowInternal();
|
||||
|
||||
int lastRowKey = -1;
|
||||
int allocNewRowKey() { return ++lastRowKey; }
|
||||
|
|
@ -271,7 +263,7 @@ private:
|
|||
private slots:
|
||||
|
||||
void loadIntoModel(std::shared_ptr<Pgsql::Result> data);
|
||||
void connectionStateChanged();
|
||||
void connectionStateChanged(ASyncDBConnection::StateData state);
|
||||
};
|
||||
|
||||
#endif // CRUDMODEL_H
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
#include "MasterController.h"
|
||||
#include "util/Colors.h"
|
||||
#include <QApplication>
|
||||
#ifdef _WIN32
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
#include <QPalette>
|
||||
#include <memory>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
@ -30,8 +28,6 @@ int main(int argc, char *argv[])
|
|||
QCoreApplication::setOrganizationDomain("eelkeklein.nl");
|
||||
QCoreApplication::setApplicationName("pglab");
|
||||
|
||||
InitApplicationPalette();
|
||||
|
||||
int result = -1;
|
||||
{
|
||||
// make sure the io_service is stopped before we wait on the future
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ SOURCES += main.cpp\
|
|||
serverinspector/DatabasesPage.cpp \
|
||||
serverinspector/RolesPage.cpp \
|
||||
serverinspector/ServerInspector.cpp \
|
||||
util/Colors.cpp \
|
||||
util/PgLabItemDelegate.cpp \
|
||||
util/PgLabTableView.cpp \
|
||||
util/SqlSyntaxHighlighter.cpp \
|
||||
|
|
@ -131,7 +130,6 @@ HEADERS += \
|
|||
serverinspector/DatabasesPage.h \
|
||||
serverinspector/RolesPage.h \
|
||||
serverinspector/ServerInspector.h \
|
||||
util/Colors.h \
|
||||
util/PgLabItemDelegate.h \
|
||||
util/PgLabTableView.h \
|
||||
util/PgLabTableViewHelper.h \
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ const int c_NumberOfColumns = 8;
|
|||
QueryExplainModel::QueryExplainModel(QObject *parent, ExplainRoot::SPtr exp)
|
||||
: QAbstractItemModel(parent)
|
||||
, explain(std::move(exp))
|
||||
, theme(GetColorTheme())
|
||||
{}
|
||||
|
||||
QVariant QueryExplainModel::data(const QModelIndex &index, int role) const
|
||||
|
|
@ -68,35 +67,35 @@ if (role == Qt::DisplayRole) {
|
|||
if (tt > 0.000000001f) {
|
||||
float f = t / tt;
|
||||
if (f > 0.9f) {
|
||||
result = theme.explainTime[0];
|
||||
result = QColor(255, 192, 192);
|
||||
}
|
||||
else if (f > 0.63f) {
|
||||
result = theme.explainTime[1];
|
||||
result = QColor(255, 224, 192);
|
||||
}
|
||||
else if (f > 0.36f) {
|
||||
result = theme.explainTime[2];
|
||||
result = QColor(255, 255, 192);
|
||||
}
|
||||
else if (f > 0.09f) {
|
||||
result = theme.explainTime[3];
|
||||
result = QColor(255, 255, 224);
|
||||
}
|
||||
else {
|
||||
result = {};
|
||||
result = QColor(Qt::white);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (col == c_ColumnEstErr) {
|
||||
float e = std::fabs(item->estimateError());
|
||||
if (e > 1000.0f) {
|
||||
result = theme.explainEstError[0];
|
||||
result = QColor(255, 192, 192);
|
||||
}
|
||||
else if (e > 100.0f) {
|
||||
result = theme.explainEstError[1];
|
||||
result = QColor(255, 224, 192);
|
||||
}
|
||||
else if (e > 10.0f) {
|
||||
result = theme.explainEstError[2];
|
||||
result = QColor(255, 255, 192);
|
||||
}
|
||||
else {
|
||||
result = {}; //QColor(Qt::white);
|
||||
result = QColor(Qt::white);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <QAbstractItemModel>
|
||||
#include <string>
|
||||
#include <util/Colors.h>
|
||||
#include "ExplainTreeModelItem.h"
|
||||
|
||||
/** \brief Model class for displaying the explain of a query in a tree like format.
|
||||
|
|
@ -31,5 +30,4 @@ public:
|
|||
|
||||
private:
|
||||
ExplainRoot::SPtr explain;
|
||||
const ColorTheme &theme;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -322,14 +322,13 @@ void QueryTool::queryTextChanged()
|
|||
setQueryTextChanged(true);
|
||||
}
|
||||
|
||||
void QueryTool::connectionStateChanged()
|
||||
void QueryTool::connectionStateChanged(ASyncDBConnection::StateData state)
|
||||
{
|
||||
QString iconname;
|
||||
|
||||
switch (m_dbConnection.state()) {
|
||||
switch (state.State) {
|
||||
case ASyncDBConnection::State::NotConnected:
|
||||
QMessageBox::warning(this, "pglab", tr("Warning connection and any of its session state has been lost"));
|
||||
//startConnect();
|
||||
startConnect();
|
||||
iconname = "red.png";
|
||||
break;
|
||||
case ASyncDBConnection::State::Connecting:
|
||||
|
|
@ -587,9 +586,7 @@ void QueryTool::generateCode()
|
|||
{
|
||||
QString command = getCommand();
|
||||
if (resultList.empty()) {
|
||||
QMessageBox::question(this, "pglab", tr("Please execute the query first"),
|
||||
QMessageBox::StandardButtons(QMessageBox::Ok),
|
||||
QMessageBox::Ok);
|
||||
QMessageBox::question(this, "pglab", tr("Please execute the query first"), QMessageBox::Ok);
|
||||
}
|
||||
if (resultList.size() == 1) {
|
||||
std::shared_ptr<const Pgsql::Result> dbres = resultList[0]->GetPgsqlResult();
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ private slots:
|
|||
void query_ready(std::shared_ptr<Pgsql::Result>, qint64 elapsedms);
|
||||
|
||||
void queryTextChanged();
|
||||
void connectionStateChanged();
|
||||
void connectionStateChanged(ASyncDBConnection::StateData state);
|
||||
void receiveNotice(Pgsql::ErrorDetails notice);
|
||||
|
||||
void startConnect();
|
||||
|
|
|
|||
|
|
@ -1,165 +0,0 @@
|
|||
#include "Colors.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QPalette>
|
||||
#include <QColor>
|
||||
|
||||
|
||||
bool isDarkModeInternal()
|
||||
{
|
||||
QPalette palette = QGuiApplication::palette();
|
||||
QColor backgroundColor = palette.color(QPalette::Window);
|
||||
return backgroundColor.lightness() < 128; // Check if the background color is dark
|
||||
}
|
||||
|
||||
bool isDarkMode()
|
||||
{
|
||||
static bool darkMode = isDarkModeInternal();
|
||||
return darkMode;
|
||||
}
|
||||
|
||||
ColorTheme GetLightMode()
|
||||
{
|
||||
ColorTheme t;
|
||||
|
||||
t.defaultTextColor = Qt::black;
|
||||
|
||||
t.gutterBackground = Qt::lightGray;
|
||||
t.lineNumber = Qt::black;
|
||||
t.currentLine = QColor(Qt::yellow).lighter(160);
|
||||
t.errorLine = QColor(Qt::red).lighter(160);
|
||||
|
||||
t.keyword = QColor(32, 32, 192);
|
||||
t.comment = QColor(128, 128, 128);
|
||||
t.quotedString = QColor(192, 32, 192);
|
||||
t.quotedIdentifier = QColor(192, 128, 32);
|
||||
t.type = QColor(32, 192, 32);
|
||||
t.parameter = QColor(192, 32, 32);
|
||||
|
||||
t.gigaBytes = QColorConstants::Svg::darkorange;
|
||||
t.megaBytes = QColorConstants::Svg::darkgoldenrod;
|
||||
t.kiloBytes = QColorConstants::Svg::darkgreen;
|
||||
t.bytes = QColorConstants::Svg::darkblue;
|
||||
|
||||
t.booleanTrue = Qt::darkGreen;
|
||||
t.booleanFalse = Qt::darkRed;
|
||||
|
||||
t.integerColor = Qt::darkBlue;
|
||||
t.floatColor = Qt::darkCyan;
|
||||
t.numericColor = Qt::darkGreen;
|
||||
t.nullColor = Qt::gray;
|
||||
|
||||
t.numericTypeColor = Qt::darkBlue;
|
||||
t.dateTimeTypeColor = Qt::darkMagenta;
|
||||
t.stringTypeColor = Qt::darkYellow;
|
||||
|
||||
t.explainTime[0] = QColor(255, 192, 192);
|
||||
t.explainTime[1] = QColor(255, 224, 192);
|
||||
t.explainTime[2] = QColor(255, 255, 192);
|
||||
t.explainTime[3] = QColor(255, 255, 224);
|
||||
|
||||
t.explainEstError[0] = QColor(255, 192, 192);
|
||||
t.explainEstError[1] = QColor(255, 224, 192);
|
||||
t.explainEstError[2] = QColor(255, 255, 192);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
ColorTheme GetDarkMode()
|
||||
{
|
||||
ColorTheme t;
|
||||
|
||||
t.defaultTextColor = Qt::lightGray;
|
||||
|
||||
t.gutterBackground = QColor(Qt::darkGray).darker(400);
|
||||
t.lineNumber = Qt::lightGray;
|
||||
t.currentLine = QColor(Qt::darkGray).darker(400);;
|
||||
t.errorLine = QColor(Qt::red).darker(180);
|
||||
|
||||
t.keyword = QColor(160, 160, 255);
|
||||
t.comment = QColor(160, 160, 160);
|
||||
t.quotedString = QColor(255, 160, 255);
|
||||
t.quotedIdentifier = QColor(255, 192, 128);
|
||||
t.type = QColor(160, 255, 160);
|
||||
t.parameter = QColor(255, 160, 160);
|
||||
|
||||
t.gigaBytes = QColorConstants::Svg::lightcoral;
|
||||
t.megaBytes = QColorConstants::Svg::lightgoldenrodyellow;
|
||||
t.kiloBytes = QColorConstants::Svg::lightgreen;
|
||||
t.bytes = QColorConstants::Svg::lightblue;
|
||||
|
||||
t.booleanTrue = QColorConstants::Svg::lightgreen;
|
||||
t.booleanFalse = QColorConstants::Svg::lightcoral;
|
||||
|
||||
t.integerColor = QColorConstants::Svg::deepskyblue;
|
||||
t.floatColor = QColorConstants::Svg::cyan;
|
||||
t.numericColor = QColorConstants::Svg::lime;
|
||||
t.nullColor = Qt::darkGray;
|
||||
|
||||
t.numericTypeColor = QColorConstants::Svg::lightblue;
|
||||
t.dateTimeTypeColor = QColor(Qt::magenta);
|
||||
t.stringTypeColor = QColor(Qt::yellow);
|
||||
|
||||
t.explainTime[0] = QColor(120, 20, 20);
|
||||
t.explainTime[1] = QColor(110, 40, 20);
|
||||
t.explainTime[2] = QColor(90, 50, 20);
|
||||
t.explainTime[3] = QColor(70, 70, 20);
|
||||
|
||||
t.explainEstError[0] = QColor(120, 20, 20);
|
||||
t.explainEstError[1] = QColor(90, 50, 20);
|
||||
t.explainEstError[2] = QColor(70, 70, 20);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
const ColorTheme& GetColorTheme()
|
||||
{
|
||||
static ColorTheme lightMode = GetLightMode();
|
||||
static ColorTheme darkMode = GetDarkMode();
|
||||
|
||||
return isDarkMode() ? darkMode : lightMode;
|
||||
}
|
||||
|
||||
void InitApplicationPalette()
|
||||
{
|
||||
if (isDarkMode())
|
||||
{
|
||||
QPalette pal = QGuiApplication::palette();
|
||||
pal.setColor(QPalette::Active, QPalette::Base, QColor(20, 20, 20));
|
||||
pal.setColor(QPalette::Active, QPalette::AlternateBase, Qt::black);
|
||||
pal.setColor(QPalette::Inactive, QPalette::Base, QColor(20, 20, 20));
|
||||
pal.setColor(QPalette::Inactive, QPalette::AlternateBase, Qt::black);
|
||||
QGuiApplication::setPalette(pal);
|
||||
}
|
||||
}
|
||||
|
||||
QColor ColorTheme::GetColorForType(Oid oid) const
|
||||
{
|
||||
using namespace Pgsql;
|
||||
|
||||
QColor c;
|
||||
switch (oid) {
|
||||
case int2_oid:
|
||||
case int4_oid:
|
||||
case int8_oid:
|
||||
c = integerColor;
|
||||
break;
|
||||
|
||||
case float4_oid:
|
||||
case float8_oid:
|
||||
c = floatColor;
|
||||
break;
|
||||
|
||||
case numeric_oid:
|
||||
c = numericColor;
|
||||
break;
|
||||
|
||||
case varchar_oid:
|
||||
case text_oid:
|
||||
case oid_oid:
|
||||
case bool_oid:
|
||||
default:
|
||||
c = defaultTextColor;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#include <QColor>
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
bool isDarkMode();
|
||||
|
||||
struct ColorTheme
|
||||
{
|
||||
QColor defaultTextColor;
|
||||
|
||||
QColor gutterBackground;
|
||||
QColor lineNumber;
|
||||
QColor currentLine;
|
||||
QColor errorLine;
|
||||
|
||||
QColor keyword;
|
||||
QColor comment;
|
||||
QColor quotedString;
|
||||
QColor quotedIdentifier;
|
||||
QColor type;
|
||||
QColor parameter;
|
||||
|
||||
QColor gigaBytes;
|
||||
QColor megaBytes;
|
||||
QColor kiloBytes;
|
||||
QColor bytes;
|
||||
|
||||
QColor booleanTrue;
|
||||
QColor booleanFalse;
|
||||
|
||||
QColor integerColor;
|
||||
QColor floatColor;
|
||||
QColor numericColor;
|
||||
QColor nullColor;
|
||||
|
||||
QColor numericTypeColor;
|
||||
QColor dateTimeTypeColor;
|
||||
QColor stringTypeColor;
|
||||
|
||||
|
||||
QColor GetColorForType(Oid oid) const;
|
||||
|
||||
QColor explainTime[4];
|
||||
QColor explainEstError[3];
|
||||
};
|
||||
|
||||
const ColorTheme& GetColorTheme();
|
||||
|
||||
void InitApplicationPalette();
|
||||
|
|
@ -1,14 +1,10 @@
|
|||
#include "util/PgLabItemDelegate.h"
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
#include "Pgsql_oids.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "AbstractEditorFactory.h"
|
||||
#include "Colors.h"
|
||||
#include "utils/HumanReadableBytes.h"
|
||||
#include "qstyleoption.h"
|
||||
|
||||
PgLabItemDelegate::PgLabItemDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
|
|
@ -86,8 +82,6 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
// }
|
||||
// }
|
||||
|
||||
const ColorTheme &theme = GetColorTheme();
|
||||
|
||||
Oid oid = InvalidOid;
|
||||
value = index.data(CustomDataTypeRole); // get OID
|
||||
if (value.isValid())
|
||||
|
|
@ -96,7 +90,7 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
value = index.data(CustomDataMeaningRole);
|
||||
DataMeaning meaning = value.isValid()
|
||||
? static_cast<DataMeaning>(value.toInt())
|
||||
: DataMeaning::Normal;
|
||||
: DataMeaningNormal;
|
||||
|
||||
value = index.data(Qt::DisplayRole);
|
||||
|
||||
|
|
@ -104,7 +98,9 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
|
||||
|
||||
if (value.isValid() && ! value.isNull()) {
|
||||
QColor forground_color;
|
||||
QColor forground_color = oid == Pgsql::bool_oid
|
||||
? GetDefaultBoolColor(value.toBool())
|
||||
: GetDefaultColorForType(oid);
|
||||
|
||||
option->features |= QStyleOptionViewItem::HasDisplay;
|
||||
if (oid == Pgsql::bool_oid) {
|
||||
|
|
@ -113,62 +109,58 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
option->text = FormatBoolForDisplay(b);
|
||||
}
|
||||
else {
|
||||
forground_color = theme.GetColorForType(oid);
|
||||
if (meaning == DataMeaning::Bytes) {
|
||||
option->text = HandleBytes(value.toLongLong(), forground_color);
|
||||
forground_color = GetDefaultColorForType(oid);
|
||||
if (meaning == DataMeaningBytes) {
|
||||
QString suffix;
|
||||
auto s = value.toLongLong();
|
||||
double val;
|
||||
if (s > 1024 * 1024 * 1000) {
|
||||
val = s / (1024 * 1024 * 1024);
|
||||
suffix = "GiB";
|
||||
forground_color = QColorConstants::Svg::darkorange;
|
||||
option->font.setBold(true);
|
||||
}
|
||||
else if (s > 1024 * 1000) {
|
||||
val = s / (1024 * 1024);
|
||||
suffix = "MiB";
|
||||
forground_color = QColorConstants::Svg::darkgoldenrod;
|
||||
}
|
||||
else if (s > 1000) {
|
||||
val = s / 1024;
|
||||
suffix = "KiB";
|
||||
forground_color = QColorConstants::Svg::darkgreen;
|
||||
}
|
||||
else {
|
||||
val = s;
|
||||
suffix = "B";
|
||||
forground_color = QColorConstants::Svg::darkblue;
|
||||
}
|
||||
option->text = QString{ "%1 %2" }.arg(val, 0, 'g', 3).arg(suffix) ;
|
||||
}
|
||||
else {
|
||||
auto str = value.toString();
|
||||
auto s = str.left(100);
|
||||
// auto f = s.indexOf('\n');
|
||||
// option->text = ((f > 0) ? s.left(f) : s).toString();
|
||||
option->text = s;
|
||||
}
|
||||
}
|
||||
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
|
||||
}
|
||||
else {
|
||||
option->palette.setBrush(QPalette::Text, QBrush(theme.nullColor));
|
||||
option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor()));
|
||||
|
||||
option->features |= QStyleOptionViewItem::HasDisplay;
|
||||
option->text = "null";
|
||||
}
|
||||
|
||||
|
||||
// if (option->state & QStyle::State_HasFocus) {
|
||||
// QColor color = Qt::darkYellow;
|
||||
// option->palette.setColor(QPalette::Active, QPalette::Highlight, color);
|
||||
// // option->palette.setColor(QPalette::Active, QPalette::AlternateBase, color);
|
||||
// option->backgroundBrush = QBrush(color);
|
||||
// option->font.setWeight(QFont::ExtraBold);
|
||||
// }
|
||||
|
||||
|
||||
// option->backgroundBrush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));
|
||||
|
||||
// disable style animations for checkboxes etc. within itemviews (QTBUG-30146)
|
||||
option->styleObject = nullptr;
|
||||
}
|
||||
|
||||
QString PgLabItemDelegate::HandleBytes(qlonglong s, QColor &forground_color) const
|
||||
{
|
||||
const ColorTheme& theme = GetColorTheme();
|
||||
auto str = HumanReadableBytes(s);
|
||||
if (s > 1024 * 1024 * 1024) {
|
||||
forground_color = theme.gigaBytes;
|
||||
}
|
||||
else if (s > 1024 * 1024) {
|
||||
forground_color = theme.megaBytes;
|
||||
}
|
||||
else if (s > 1024) {
|
||||
forground_color = theme.kiloBytes;
|
||||
}
|
||||
else {
|
||||
forground_color = theme.bytes;
|
||||
}
|
||||
return QString::fromStdString(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PgLabItemDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
|
|
@ -180,13 +172,6 @@ void PgLabItemDelegate::paint(QPainter *painter,
|
|||
const QWidget *widget = option.widget; // QStyledItemDelegatePrivate::widget(option);
|
||||
QStyle *style = widget ? widget->style() : QApplication::style();
|
||||
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
|
||||
|
||||
if (option.state & QStyle::State_HasFocus) {
|
||||
QColor color = Qt::red;
|
||||
painter->setPen(QPen(QBrush(color), 2.0));
|
||||
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QWidget *PgLabItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ protected:
|
|||
|
||||
private:
|
||||
AbstractEditorFactory *m_editorFactory = nullptr;
|
||||
QString HandleBytes(qlonglong s, QColor &forground_color) const;
|
||||
};
|
||||
|
||||
#endif // PGLABITEMDELEGATE_H
|
||||
|
|
|
|||
|
|
@ -7,18 +7,13 @@ PgLabTableView::PgLabTableView(QWidget *parent)
|
|||
: QTableView(parent)
|
||||
{
|
||||
setAlternatingRowColors(true);
|
||||
|
||||
setItemDelegate(new PgLabItemDelegate(this));
|
||||
setWordWrap(false);
|
||||
|
||||
QPalette pal = palette();
|
||||
|
||||
//pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight));
|
||||
//pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText));
|
||||
|
||||
// pal.setColor(QPalette::Active, QPalette::Base, QColor(20, 20, 20));
|
||||
// pal.setColor(QPalette::Active, QPalette::AlternateBase, Qt::black);
|
||||
// setPalette(pal);
|
||||
auto pal = palette();
|
||||
pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight));
|
||||
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText));
|
||||
setPalette(pal);
|
||||
|
||||
auto vertical_header = verticalHeader();
|
||||
vertical_header->setMinimumSectionSize(16);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ public:
|
|||
m_itemView->setModel(m_sortFilter);
|
||||
m_itemView->setSortingEnabled(true);
|
||||
m_sortFilter->sort(0, Qt::AscendingOrder);
|
||||
|
||||
}
|
||||
|
||||
PgLabTableViewHelper(QWidget * parent)
|
||||
|
|
|
|||
|
|
@ -2,28 +2,25 @@
|
|||
|
||||
#include "catalog/PgTypeContainer.h"
|
||||
#include "SqlLexer.h"
|
||||
#include "util/Colors.h"
|
||||
|
||||
|
||||
|
||||
SqlSyntaxHighlighter::SqlSyntaxHighlighter(QTextDocument *parent)
|
||||
: QSyntaxHighlighter(parent)
|
||||
{
|
||||
const ColorTheme& theme = GetColorTheme();
|
||||
|
||||
m_keywordFormat.setForeground(theme.keyword);
|
||||
m_keywordFormat.setForeground(QColor(32, 32, 192));
|
||||
m_keywordFormat.setFontWeight(QFont::Bold);
|
||||
|
||||
m_commentFormat.setForeground(theme.comment);
|
||||
m_commentFormat.setForeground(QColor(128, 128, 128));
|
||||
|
||||
m_quotedStringFormat.setForeground(theme.quotedString);
|
||||
m_quotedStringFormat.setForeground(QColor(192, 32, 192));
|
||||
|
||||
m_quotedIdentifierFormat.setForeground(theme.quotedIdentifier);
|
||||
m_quotedIdentifierFormat.setForeground(QColor(192, 128, 32));
|
||||
|
||||
m_typeFormat.setForeground(theme.type);
|
||||
m_typeFormat.setForeground(QColor(32, 192, 32));
|
||||
m_typeFormat.setFontWeight(QFont::Bold);
|
||||
|
||||
m_parameterFormat.setForeground(theme.parameter);
|
||||
m_parameterFormat.setForeground(QColor(192, 32, 32));
|
||||
m_parameterFormat.setFontWeight(QFont::Bold);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ private:
|
|||
|
||||
void doStateCallback(ASyncDBConnection::StateData state);
|
||||
/// Wait's for a command to come in and send's it to the server
|
||||
bool waitForAndSendCommand();
|
||||
void waitForAndSendCommand();
|
||||
void doNewCommand();
|
||||
void waitForResult();
|
||||
|
||||
|
|
@ -236,9 +236,7 @@ void ASyncDBConnectionThread::communicate()
|
|||
|
||||
|
||||
if (m_state == ASyncDBConnection::State::Connected) {
|
||||
if (!waitForAndSendCommand()) {
|
||||
return;
|
||||
}
|
||||
waitForAndSendCommand();
|
||||
}
|
||||
else if (m_state == ASyncDBConnection::State::QuerySend || m_state == ASyncDBConnection::State::CancelSend) {
|
||||
// Wait for result, even after a cancel we should wait, for all results
|
||||
|
|
@ -257,22 +255,15 @@ void ASyncDBConnectionThread::stop()
|
|||
|
||||
void ASyncDBConnectionThread::doStateCallback(ASyncDBConnection::StateData state)
|
||||
{
|
||||
qDebug() << "State change " + state.Message;
|
||||
m_state = state.State;
|
||||
Q_EMIT asyncConnObject->onStateChanged();
|
||||
Q_EMIT asyncConnObject->onStateChanged(state);
|
||||
}
|
||||
|
||||
bool ASyncDBConnectionThread::waitForAndSendCommand()
|
||||
void ASyncDBConnectionThread::waitForAndSendCommand()
|
||||
{
|
||||
SOCKET sock = static_cast<SOCKET>(m_connection.socket());
|
||||
Win32Event socket_event(Win32Event::Reset::Manual, Win32Event::Initial::Clear);
|
||||
long fd = FD_READ | FD_CLOSE;
|
||||
WSAEventSelect(sock, socket_event.handle(), fd);
|
||||
|
||||
WaitHandleList whl;
|
||||
auto wait_result_new_command = whl.add(m_commandQueue.m_newEvent);
|
||||
auto wait_result_socket = whl.add(socket_event);
|
||||
whl.add(m_stopEvent);
|
||||
auto wait_result_stop = whl.add(m_stopEvent);
|
||||
|
||||
DWORD res = MsgWaitForMultipleObjectsEx(
|
||||
whl.count(), // _In_ DWORD nCount,
|
||||
|
|
@ -284,17 +275,8 @@ bool ASyncDBConnectionThread::waitForAndSendCommand()
|
|||
if (res == wait_result_new_command) {
|
||||
doNewCommand();
|
||||
}
|
||||
else if (res == wait_result_socket) {
|
||||
WSANETWORKEVENTS net_events;
|
||||
WSAEnumNetworkEvents(sock, socket_event.handle(), &net_events);
|
||||
if (net_events.lNetworkEvents & FD_CLOSE) {
|
||||
doStateCallback({ ASyncDBConnection::State::NotConnected, "Connection lost" });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Note if it was stop we can just return and function
|
||||
// above will stop looping because terminateRequested has been set too by stop
|
||||
return true;
|
||||
}
|
||||
|
||||
void ASyncDBConnectionThread::doNewCommand()
|
||||
|
|
@ -302,6 +284,7 @@ void ASyncDBConnectionThread::doNewCommand()
|
|||
// get command from top of queue (but leave it in the queue, we need the callback)
|
||||
if (! m_commandQueue.m_queue.empty()) {
|
||||
const Command &command = m_commandQueue.m_queue.front();
|
||||
bool query_send = false;
|
||||
if (command.params.empty())
|
||||
m_connection.sendQuery(command.command.c_str());
|
||||
else
|
||||
|
|
@ -376,11 +359,6 @@ void ASyncDBConnectionThread::waitForResult()
|
|||
finished = true;
|
||||
}
|
||||
}
|
||||
else if (net_events.lNetworkEvents & FD_CLOSE) {
|
||||
doStateCallback({ ASyncDBConnection::State::NotConnected, "Close while waiting for result" });
|
||||
finished = true;
|
||||
stop();
|
||||
}
|
||||
}
|
||||
if (res == wait_result_stop) {
|
||||
// Send cancel, close connection and terminate thread
|
||||
|
|
@ -435,7 +413,7 @@ void ASyncDBConnection::doStateCallback(State state)
|
|||
m_connection.setNoticeReceiver(
|
||||
[this](const PGresult *result) { processNotice(result); });
|
||||
}
|
||||
Q_EMIT onStateChanged();
|
||||
Q_EMIT onStateChanged(state);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public:
|
|||
bool cancel();
|
||||
|
||||
Q_SIGNALS:
|
||||
void onStateChanged();
|
||||
void onStateChanged(ASyncDBConnection::StateData state);
|
||||
void onNotice(Pgsql::ErrorDetails notice);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -19,24 +19,10 @@ namespace {
|
|||
{ SslMode::verify_full, "verify-full" }
|
||||
};
|
||||
|
||||
// inline const char *valuePtr(const std::string &v)
|
||||
// {
|
||||
// return v.empty() ? nullptr : v.c_str();
|
||||
// }
|
||||
|
||||
struct {
|
||||
const char * host = "host";
|
||||
const char * hostaddr = "hostaddr";
|
||||
const char * port = "port";
|
||||
const char * dbname = "dbname";
|
||||
const char * user = "user";
|
||||
const char * password = "password";
|
||||
const char * sslmode = "sslmode";
|
||||
const char * sslcert = "sslcert";
|
||||
const char * sslkey = "sslkey";
|
||||
const char * sslrootcert = "sslrootcert";
|
||||
const char * sslcrl = "sslcrl";
|
||||
} keywords;
|
||||
inline const char *valuePtr(const std::string &v)
|
||||
{
|
||||
return v.empty() ? nullptr : v.c_str();
|
||||
}
|
||||
|
||||
} // end unnamed namespace
|
||||
|
||||
|
|
@ -51,15 +37,16 @@ QString SslModeToString(SslMode sm)
|
|||
|
||||
SslMode StringToSslMode(QString s)
|
||||
{
|
||||
SslMode result = SslMode::allow;
|
||||
for (auto e : SslModeStringTable)
|
||||
if (e.string == s)
|
||||
return e.mode;
|
||||
result = e.mode;
|
||||
|
||||
return SslMode::allow;
|
||||
return {};
|
||||
}
|
||||
|
||||
ConnectionConfig::ConnectionConfig()
|
||||
: m_parameters{{"application_name", QCoreApplication::applicationName()}}
|
||||
: m_applicationName(QCoreApplication::applicationName().toUtf8().data())
|
||||
{}
|
||||
|
||||
const ConnectionGroup *ConnectionConfig::parent() const
|
||||
|
|
@ -105,131 +92,168 @@ const QString& ConnectionConfig::name() const
|
|||
|
||||
void ConnectionConfig::setHost(const QString& host)
|
||||
{
|
||||
setParameter(keywords.host, host);
|
||||
if (m_host != host)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_host = std::move(host);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::host() const
|
||||
const QString& ConnectionConfig::host() const
|
||||
{
|
||||
return getParameter(keywords.host);
|
||||
return m_host;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setHostAddr(const QString &v)
|
||||
{
|
||||
setParameter(keywords.hostaddr, v);
|
||||
if (m_hostaddr != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_hostaddr = std::move(v);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::hostAddr() const
|
||||
const QString& ConnectionConfig::hostAddr() const
|
||||
{
|
||||
return getParameter(keywords.hostaddr);
|
||||
return m_hostaddr;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setPort(unsigned short port)
|
||||
{
|
||||
setParameter(keywords.port, QString::number(port));
|
||||
if (m_port != port)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_port = port;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short ConnectionConfig::port() const
|
||||
{
|
||||
QString s = getParameter(keywords.port);
|
||||
if (s.isEmpty())
|
||||
return 5432;
|
||||
|
||||
unsigned short port = static_cast<unsigned short>(s.toInt());
|
||||
return port;
|
||||
return m_port;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setUser(const QString& v)
|
||||
{
|
||||
setParameter(keywords.user, v);
|
||||
if (m_user != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_user = v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString ConnectionConfig::user() const
|
||||
const QString& ConnectionConfig::user() const
|
||||
{
|
||||
return getParameter(keywords.user);
|
||||
return m_user;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setPassword(const QString& v)
|
||||
{
|
||||
setParameter(keywords.password, v);
|
||||
if (m_password != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_password = v;
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::password() const
|
||||
const QString& ConnectionConfig::password() const
|
||||
{
|
||||
return getParameter(keywords.password);
|
||||
return m_password;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setDbname(const QString& v)
|
||||
{
|
||||
setParameter(keywords.dbname, v);
|
||||
if (m_dbname != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_dbname = v;
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::dbname() const
|
||||
const QString& ConnectionConfig::dbname() const
|
||||
{
|
||||
return getParameter(keywords.dbname);
|
||||
return m_dbname;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setSslMode(SslMode m)
|
||||
{
|
||||
setParameter(keywords.sslmode, SslModeToString(m));
|
||||
if (m_sslMode != m)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_sslMode = m;
|
||||
}
|
||||
}
|
||||
|
||||
SslMode ConnectionConfig::sslMode() const
|
||||
{
|
||||
QString s = getParameter(keywords.sslmode);
|
||||
return StringToSslMode(s);
|
||||
return m_sslMode;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setSslCert(const QString& v)
|
||||
{
|
||||
setParameter(keywords.sslcert, v);
|
||||
if (m_sslCert != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_sslCert = std::move(v);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::sslCert() const
|
||||
const QString& ConnectionConfig::sslCert() const
|
||||
{
|
||||
return getParameter(keywords.sslcert);
|
||||
return m_sslCert;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setSslKey(const QString& v)
|
||||
{
|
||||
setParameter(keywords.sslkey, v);
|
||||
if (m_sslKey != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_sslKey = std::move(v);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::sslKey() const
|
||||
const QString& ConnectionConfig::sslKey() const
|
||||
{
|
||||
return getParameter(keywords.sslkey);
|
||||
return m_sslKey;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setSslRootCert(const QString& v)
|
||||
{
|
||||
setParameter(keywords.sslrootcert, v);
|
||||
if (m_sslRootCert != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_sslRootCert = std::move(v);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::sslRootCert() const
|
||||
const QString& ConnectionConfig::sslRootCert() const
|
||||
{
|
||||
return getParameter(keywords.sslrootcert);
|
||||
return m_sslRootCert;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setSslCrl(const QString& v)
|
||||
{
|
||||
setParameter(keywords.sslcrl, v);
|
||||
if (m_sslCrl != v)
|
||||
{
|
||||
m_dirty = true;
|
||||
m_sslCrl = std::move(v);
|
||||
}
|
||||
}
|
||||
|
||||
QString ConnectionConfig::sslCrl() const
|
||||
const QString& ConnectionConfig::sslCrl() const
|
||||
{
|
||||
return getParameter(keywords.sslcrl);
|
||||
return m_sslCrl;
|
||||
}
|
||||
|
||||
// bool ConnectionConfig::isSameDatabase(const ConnectionConfig &rhs) const
|
||||
// {
|
||||
// return host() == rhs.host()
|
||||
// // && m_hostaddr == rhs.m_hostaddr
|
||||
// // && m_port == rhs.m_port
|
||||
// // && m_user == rhs.m_user
|
||||
// // && m_password == rhs.m_password
|
||||
// // && m_dbname == rhs.m_dbname
|
||||
// ;
|
||||
|
||||
// }
|
||||
bool ConnectionConfig::isSameDatabase(const ConnectionConfig &rhs) const
|
||||
{
|
||||
return m_host == rhs.m_host
|
||||
&& m_hostaddr == rhs.m_hostaddr
|
||||
&& m_port == rhs.m_port
|
||||
&& m_user == rhs.m_user
|
||||
&& m_password == rhs.m_password
|
||||
&& m_dbname == rhs.m_dbname;
|
||||
}
|
||||
|
||||
bool ConnectionConfig::dirty() const
|
||||
{
|
||||
|
|
@ -290,76 +314,58 @@ QString ConnectionConfig::escapeConnectionStringValue(const QString &value)
|
|||
QString ConnectionConfig::connectionString() const
|
||||
{
|
||||
QString s;
|
||||
s += "host="
|
||||
% escapeConnectionStringValue(m_host)
|
||||
% " port="
|
||||
% QString::number(m_port)
|
||||
% " user="
|
||||
% escapeConnectionStringValue(m_user);
|
||||
s += " password=";
|
||||
s += escapeConnectionStringValue(m_password);
|
||||
s += " dbname=";
|
||||
s += escapeConnectionStringValue(m_dbname);
|
||||
s += " sslmode=";
|
||||
s += SslModeToString(m_sslMode);
|
||||
if (!m_sslCert.isEmpty())
|
||||
{
|
||||
s += " sslcert=";
|
||||
s += escapeConnectionStringValue(m_sslCert);
|
||||
}
|
||||
if (!m_sslKey.isEmpty())
|
||||
{
|
||||
s += " sslkey=";
|
||||
s += escapeConnectionStringValue(m_sslKey);
|
||||
}
|
||||
if (!m_sslRootCert.isEmpty())
|
||||
{
|
||||
s += " sslrootcrt=";
|
||||
s += escapeConnectionStringValue(m_sslRootCert);
|
||||
}
|
||||
if (!m_sslCrl.isEmpty())
|
||||
{
|
||||
s += " sslCrl=";
|
||||
s += escapeConnectionStringValue(m_sslCrl);
|
||||
}
|
||||
s += " client_encoding=utf8";
|
||||
s += " application_name=";
|
||||
s += escapeConnectionStringValue(m_applicationName);
|
||||
|
||||
for (auto && param : m_parameters)
|
||||
{
|
||||
// maybe we should prevent empty parameters from staying in the map?
|
||||
if (!param.second.isEmpty())
|
||||
{
|
||||
if (!s.isEmpty())
|
||||
s += " ";
|
||||
s += param.first % "=" % escapeConnectionStringValue(param.second);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void ConnectionConfig::setParameter(const QString &name, const QString &value)
|
||||
{
|
||||
if (value.isEmpty())
|
||||
{
|
||||
if (m_parameters.erase(name) > 0)
|
||||
{
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto findResult = m_parameters.find(name);
|
||||
if (findResult == m_parameters.end())
|
||||
{
|
||||
m_parameters.insert({name, value});
|
||||
m_dirty = true;
|
||||
}
|
||||
else if (findResult->second != value)
|
||||
{
|
||||
findResult->second = value;
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
//if (name == "sslMode")
|
||||
// m_sslMode = StringToSslMode(value);
|
||||
|
||||
// Would it better to store everything in the map or keep the specific
|
||||
// fields for common keywords?
|
||||
// Map over fields
|
||||
// + can use foreach
|
||||
// - not strongly typed, but we should be carefull not to restrict ourselves
|
||||
// the specific fields are more something that helps in the UI
|
||||
}
|
||||
|
||||
QString ConnectionConfig::getParameter(const QString &name) const
|
||||
{
|
||||
auto findResult = m_parameters.find(name);
|
||||
if (findResult == m_parameters.end())
|
||||
return {};
|
||||
return findResult->second;
|
||||
}
|
||||
|
||||
void ConnectionConfig::writeToEnvironment(QProcessEnvironment &env) const
|
||||
{
|
||||
strToEnv(env, "PGHOST", getParameter(keywords.host));
|
||||
strToEnv(env, "PGHOSTADDR", getParameter(keywords.hostaddr));
|
||||
strToEnv(env, "PGPORT", getParameter(keywords.port));
|
||||
strToEnv(env, "PGDATABASE", getParameter(keywords.dbname));
|
||||
strToEnv(env, "PGUSER", getParameter(keywords.user));
|
||||
strToEnv(env, "PGPASSWORD", getParameter(keywords.password));
|
||||
strToEnv(env, "PGSSLMODE", getParameter(keywords.sslmode));
|
||||
// strToEnv(env, "PGSSLCERT", m_sslCert);
|
||||
// strToEnv(env, "PGSSLKEY", m_sslKey);
|
||||
// strToEnv(env, "PGSSLROOTCERT", m_sslRootCert);
|
||||
// strToEnv(env, "PGSSLCRL", m_sslCrl);
|
||||
strToEnv(env, "PGHOST", m_host);
|
||||
strToEnv(env, "PGHOSTADDR", m_hostaddr);
|
||||
strToEnv(env, "PGPORT", QString::number(m_port));
|
||||
strToEnv(env, "PGDATABASE", m_dbname);
|
||||
strToEnv(env, "PGUSER", m_user);
|
||||
strToEnv(env, "PGPASSWORD", m_password);
|
||||
strToEnv(env, "PGSSLMODE", SslModeToString(m_sslMode));
|
||||
strToEnv(env, "PGSSLCERT", m_sslCert);
|
||||
strToEnv(env, "PGSSLKEY", m_sslKey);
|
||||
strToEnv(env, "PGSSLROOTCERT", m_sslRootCert);
|
||||
strToEnv(env, "PGSSLCRL", m_sslCrl);
|
||||
strToEnv(env, "PGSSLCOMPRESSION", "0");
|
||||
strToEnv(env, "PGCONNECT_TIMEOUT", "10");
|
||||
env.insert("PGCLIENTENCODING", "utf8");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <QMetaType>
|
||||
#include <QUuid>
|
||||
#include <QVector>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -75,42 +74,42 @@ public:
|
|||
const QString& name() const;
|
||||
|
||||
void setHost(const QString& host);
|
||||
QString host() const;
|
||||
const QString& host() const;
|
||||
|
||||
void setHostAddr(const QString& v);
|
||||
QString hostAddr() const;
|
||||
const QString& hostAddr() const;
|
||||
|
||||
void setPort(unsigned short port);
|
||||
unsigned short port() const;
|
||||
|
||||
void setUser(const QString& v);
|
||||
QString user() const;
|
||||
const QString& user() const;
|
||||
|
||||
void setPassword(const QString& v);
|
||||
QString password() const;
|
||||
const QString& password() const;
|
||||
|
||||
void setDbname(const QString& v);
|
||||
QString dbname() const;
|
||||
const QString& dbname() const;
|
||||
|
||||
void setSslMode(SslMode m);
|
||||
SslMode sslMode() const;
|
||||
|
||||
void setSslCert(const QString& v);
|
||||
QString sslCert() const;
|
||||
const QString& sslCert() const;
|
||||
|
||||
void setSslKey(const QString& v);
|
||||
QString sslKey() const;
|
||||
const QString& sslKey() const;
|
||||
|
||||
void setSslRootCert(const QString& v);
|
||||
QString sslRootCert() const;
|
||||
const QString& sslRootCert() const;
|
||||
|
||||
void setSslCrl(const QString& v);
|
||||
QString sslCrl() const;
|
||||
const QString& sslCrl() const;
|
||||
|
||||
// const char * const * getKeywords() const;
|
||||
// const char * const * getValues() const;
|
||||
|
||||
// bool isSameDatabase(const ConnectionConfig &rhs) const;
|
||||
bool isSameDatabase(const ConnectionConfig &rhs) const;
|
||||
|
||||
void writeToEnvironment(QProcessEnvironment &env) const;
|
||||
|
||||
|
|
@ -132,35 +131,26 @@ public:
|
|||
*/
|
||||
static QString escapeConnectionStringValue(const QString &value);
|
||||
QString connectionString() const;
|
||||
|
||||
void setParameter(const QString &name, const QString &value);
|
||||
QString getParameter(const QString &name) const;
|
||||
const std::unordered_map<QString, QString>& getParameters() const
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
private:
|
||||
QUuid m_uuid;
|
||||
QString m_name;
|
||||
// QString m_host;
|
||||
// QString m_hostaddr;
|
||||
// uint16_t m_port = 5432;
|
||||
QString m_host;
|
||||
QString m_hostaddr;
|
||||
uint16_t m_port = 5432;
|
||||
|
||||
// QString m_user;
|
||||
// QString m_password; ///< Note this is not saved in the DB only the m_encodedPassword is safed.
|
||||
// QString m_dbname;
|
||||
QString m_user;
|
||||
QString m_password; ///< Note this is not saved in the DB only the m_encodedPassword is safed.
|
||||
QString m_dbname;
|
||||
|
||||
// SslMode m_sslMode = SslMode::prefer;
|
||||
// QString m_sslCert;
|
||||
// QString m_sslKey;
|
||||
// QString m_sslRootCert;
|
||||
// QString m_sslCrl;
|
||||
SslMode m_sslMode = SslMode::prefer;
|
||||
QString m_sslCert;
|
||||
QString m_sslKey;
|
||||
QString m_sslRootCert;
|
||||
QString m_sslCrl;
|
||||
|
||||
// QString m_applicationName;
|
||||
QString m_applicationName;
|
||||
QByteArray m_encodedPassword;
|
||||
|
||||
std::unordered_map<QString, QString> m_parameters;
|
||||
|
||||
bool m_dirty = false;
|
||||
ConnectionGroup* m_group = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ Json::Value ParamToJson(const Param ¶m)
|
|||
return v;
|
||||
}
|
||||
|
||||
// Param ParamFromJson(const Json::Value &json)
|
||||
// {
|
||||
// Param p;
|
||||
Param ParamFromJson(const Json::Value &json)
|
||||
{
|
||||
Param p;
|
||||
|
||||
// return p;
|
||||
// }
|
||||
return p;
|
||||
}
|
||||
|
||||
Json::Value ParamListToJson(const t_ParamList &list)
|
||||
{
|
||||
|
|
@ -24,15 +24,14 @@ Json::Value ParamListToJson(const t_ParamList &list)
|
|||
return root;
|
||||
}
|
||||
|
||||
// t_ParamList ParamListFromJson(const Json::Value &json)
|
||||
// {
|
||||
// t_ParamList result;
|
||||
// if (json.isArray()) {
|
||||
// result.reserve(json.size());
|
||||
// for (auto &e : json) {
|
||||
// result.push_back(ParamFromJson(e));
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
t_ParamList ParamListFromJson(const Json::Value &json)
|
||||
{
|
||||
t_ParamList result;
|
||||
if (json.isArray()) {
|
||||
result.reserve(json.size());
|
||||
for (auto &e : json) {
|
||||
result.push_back(ParamFromJson(e));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ QVariant ParamListModel::headerData(int section, Qt::Orientation orientation, in
|
|||
|
||||
int ParamListModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return static_cast<int>(m_paramList.size());
|
||||
return m_paramList.size();
|
||||
}
|
||||
|
||||
int ParamListModel::columnCount(const QModelIndex &) const
|
||||
|
|
|
|||
|
|
@ -21,19 +21,7 @@ public:
|
|||
Stored
|
||||
};
|
||||
|
||||
class Key {
|
||||
public:
|
||||
Key() = default;
|
||||
Key(Oid relationId, int16_t num)
|
||||
: RelationId(relationId)
|
||||
, Num(num)
|
||||
{}
|
||||
|
||||
std::strong_ordering operator <=> (const Key &rhs) const = default;
|
||||
private:
|
||||
Oid RelationId = InvalidOid;
|
||||
int16_t Num = 0;
|
||||
};
|
||||
using Key = std::tuple<Oid, int16_t>;
|
||||
|
||||
Oid relid = InvalidOid;
|
||||
QString name;
|
||||
|
|
@ -59,22 +47,9 @@ public:
|
|||
QString sername, serschema; // serial sequence name and schema
|
||||
QString description; ///< from pg_description
|
||||
|
||||
Key key() const
|
||||
{
|
||||
return Key(relid, num);
|
||||
}
|
||||
|
||||
std::strong_ordering operator <=> (const Key& rhs) const
|
||||
{
|
||||
return key() <=> rhs;
|
||||
}
|
||||
|
||||
bool operator==(const Key &k) const
|
||||
{
|
||||
return key() == k;
|
||||
}
|
||||
|
||||
bool operator==(Key _k) const { return relid == std::get<0>(_k) && num == std::get<1>(_k); }
|
||||
bool operator==(const QString &n) const { return name == n; }
|
||||
bool operator<(Key _k) const { return relid < std::get<0>(_k) || (relid == std::get<0>(_k) && num < std::get<1>(_k)); }
|
||||
bool operator<(const PgAttribute &rhs) const { return relid < rhs.relid || (relid == rhs.relid && num < rhs.num); }
|
||||
|
||||
/// Return the part of the SQL create statement that can be reused for both the CREATE TABLE and ALTER TABLE ADD COLUMN
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ SELECT attrelid, attname, atttypid, attstattarget,
|
|||
LEFT JOIN pg_attrdef AS def ON attrelid=adrelid AND attnum=adnum
|
||||
LEFT JOIN (pg_depend JOIN pg_class cs ON classid='pg_class'::regclass AND objid=cs.oid AND cs.relkind='S') ON refobjid=att.attrelid AND refobjsubid=att.attnum
|
||||
LEFT JOIN pg_namespace ns ON ns.oid=cs.relnamespace
|
||||
LEFT JOIN pg_catalog.pg_description AS d ON (objoid=attrelid AND d.objsubid=attnum) )__";
|
||||
LEFT JOIN pg_catalog.pg_description AS d ON (objoid=attrelid AND d.objsubid=attnum))__";
|
||||
|
||||
return q;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "PgClass.h"
|
||||
#include "PgAttribute.h"
|
||||
#include "PgAttributeContainer.h"
|
||||
#include "PgClassContainer.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
|
|
@ -8,7 +7,6 @@
|
|||
#include <QStringBuilder>
|
||||
#include "SqlFormattingUtils.h"
|
||||
#include <ranges>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
void operator<<(RelPersistence &s, const Pgsql::Value &v)
|
||||
|
|
@ -70,25 +68,6 @@ void operator<<(RelKind &s, const Pgsql::Value &v)
|
|||
}
|
||||
}
|
||||
|
||||
void operator<<(PartitioningStrategy &s, const Pgsql::Value &v)
|
||||
{
|
||||
const char *c = v.c_str();
|
||||
switch (*c)
|
||||
{
|
||||
case 'h':
|
||||
s = PartitioningStrategy::Hash;
|
||||
break;
|
||||
case 'l':
|
||||
s = PartitioningStrategy::List;
|
||||
break;
|
||||
case 'r':
|
||||
s = PartitioningStrategy::Range;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unknown PartitioningStrategy");
|
||||
}
|
||||
}
|
||||
|
||||
QString PgClass::createSql() const
|
||||
{
|
||||
if (createSqlCache.isEmpty())
|
||||
|
|
@ -96,7 +75,6 @@ QString PgClass::createSql() const
|
|||
switch (kind)
|
||||
{
|
||||
case RelKind::Table:
|
||||
case RelKind::PartitionedTable:
|
||||
createSqlCache = createTableSql();
|
||||
break;
|
||||
case RelKind::View:
|
||||
|
|
@ -136,17 +114,6 @@ QString PgClass::aclAllPattern() const
|
|||
return {};
|
||||
}
|
||||
|
||||
QString PgClass::ddlTypeName() const
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case RelKind::PartitionedTable:
|
||||
return "TABLE";
|
||||
default:
|
||||
return PgNamespaceObject::ddlTypeName();
|
||||
}
|
||||
}
|
||||
|
||||
QString PgClass::createTableSql() const
|
||||
{
|
||||
QString sql;
|
||||
|
|
@ -167,9 +134,7 @@ QString PgClass::createTableSql() const
|
|||
else
|
||||
sql += generateBodySql(false);
|
||||
|
||||
|
||||
sql += generateInheritsSql()
|
||||
% partitionBySql()
|
||||
% generateTablespaceSql()
|
||||
% ";\n";
|
||||
return sql;
|
||||
|
|
@ -262,49 +227,6 @@ QString PgClass::generateInheritsSql() const
|
|||
return sql;
|
||||
}
|
||||
|
||||
QString PgClass::partitionBySql() const
|
||||
{
|
||||
if (kind != RelKind::PartitionedTable)
|
||||
return {};
|
||||
|
||||
QString sql = "\nPARTITION BY " % PartitionStrategyKeyword(partitionedTable.strategy);
|
||||
sql += partitionKeySql();
|
||||
return sql;
|
||||
}
|
||||
|
||||
QString PgClass::partitionKeySql() const
|
||||
{
|
||||
QString result;
|
||||
result += "(";
|
||||
auto keyItem = partitionedTable.keyColumns.begin();
|
||||
if (keyItem != partitionedTable.keyColumns.end())
|
||||
{
|
||||
result += partitionKeyItemSql(*keyItem);
|
||||
for (++keyItem; keyItem != partitionedTable.keyColumns.end(); ++keyItem)
|
||||
result += ", " % partitionKeyItemSql(*keyItem);
|
||||
}
|
||||
result += ")";
|
||||
return result;
|
||||
}
|
||||
|
||||
QString PgClass::partitionKeyItemSql(
|
||||
const PartitioningKeyItem &keyItem
|
||||
) const
|
||||
{
|
||||
if (keyItem.attNum == 0)
|
||||
return keyItem.expression;
|
||||
|
||||
const PgAttribute *col = catalog().attributes()->findIf(
|
||||
[this, &keyItem] (const auto &att)
|
||||
{
|
||||
return att.relid == oid() && att.num == keyItem.attNum;
|
||||
}
|
||||
);
|
||||
|
||||
assert(col != nullptr);
|
||||
return quoteIdent(col->name);
|
||||
}
|
||||
|
||||
QString PgClass::getPartitionOfName() const
|
||||
{
|
||||
auto parents = catalog().inherits()->getParentsOf(oid());
|
||||
|
|
@ -341,15 +263,4 @@ QString PgClass::createViewSql() const
|
|||
return sql;
|
||||
}
|
||||
|
||||
QString PartitionStrategyKeyword(PartitioningStrategy ps)
|
||||
{
|
||||
switch (ps) {
|
||||
case PartitioningStrategy::Hash:
|
||||
return "HASH";
|
||||
case PartitioningStrategy::List:
|
||||
return "LIST";
|
||||
case PartitioningStrategy::Range:
|
||||
return "RANGE";
|
||||
}
|
||||
throw std::runtime_error("Unknown PartitioningStrategy");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@
|
|||
#include "PgNamespaceObject.h"
|
||||
#include <QString>
|
||||
#include <libpq-fe.h>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
class PgAttribute;
|
||||
|
||||
enum class RelPersistence {
|
||||
Permanent, // p
|
||||
|
|
@ -17,8 +14,7 @@ enum class RelPersistence {
|
|||
|
||||
void operator<<(RelPersistence &s, const Pgsql::Value &v);
|
||||
|
||||
enum class RelKind
|
||||
{
|
||||
enum class RelKind {
|
||||
Table, // r
|
||||
Index, // i
|
||||
Sequence, // S
|
||||
|
|
@ -33,37 +29,6 @@ enum class RelKind
|
|||
|
||||
void operator<<(RelKind &s, const Pgsql::Value &v);
|
||||
|
||||
enum class PartitioningStrategy
|
||||
{
|
||||
Hash, // h
|
||||
List, // l
|
||||
Range // r
|
||||
};
|
||||
|
||||
void operator<<(PartitioningStrategy &s, const Pgsql::Value &v);
|
||||
|
||||
QString PartitionStrategyKeyword(PartitioningStrategy ps);
|
||||
|
||||
class PartitioningKeyItem
|
||||
{
|
||||
public:
|
||||
int16_t attNum;
|
||||
Oid opClass;
|
||||
Oid collation;
|
||||
// expre nodetree
|
||||
QString expression; // pg_get_expr(pg_node_tree, relation_oid)
|
||||
};
|
||||
using PartitioningKeyItems = boost::container::small_vector<PartitioningKeyItem, 3>;
|
||||
|
||||
class PgPartitionedTable
|
||||
{
|
||||
public:
|
||||
PartitioningStrategy strategy;
|
||||
Oid defaultPartition;
|
||||
|
||||
PartitioningKeyItems keyColumns;
|
||||
};
|
||||
|
||||
|
||||
class PgClass: public PgNamespaceObject {
|
||||
public:
|
||||
|
|
@ -85,7 +50,6 @@ public:
|
|||
std::vector<QString> options;
|
||||
QString viewdef;
|
||||
QString partitionBoundaries;
|
||||
PgPartitionedTable partitionedTable; // ignore if RelKind != PartitionedTable
|
||||
|
||||
using PgNamespaceObject::PgNamespaceObject;
|
||||
|
||||
|
|
@ -94,21 +58,12 @@ public:
|
|||
QString typeName() const override;
|
||||
QString aclAllPattern() const override;
|
||||
|
||||
|
||||
protected:
|
||||
virtual QString ddlTypeName() const override;
|
||||
|
||||
private:
|
||||
mutable QString createSqlCache;
|
||||
|
||||
QString createTableSql() const;
|
||||
QString generateBodySql(bool isPartition) const;
|
||||
QString generateInheritsSql() const;
|
||||
QString partitionBySql() const;
|
||||
QString partitionKeySql() const;
|
||||
QString partitionKeyItemSql(
|
||||
const PartitioningKeyItem &keyItem
|
||||
) const;
|
||||
QString getPartitionOfName() const;
|
||||
QString generateTablespaceSql() const;
|
||||
QString createViewSql() const;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include "PgClassContainer.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
#include "Pgsql_Col.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include "PgNamespaceContainer.h"
|
||||
#include <iterator>
|
||||
|
||||
std::string PgClassContainer::getLoadQuery() const
|
||||
|
|
@ -15,55 +17,16 @@ std::string PgClassContainer::getLoadQuery() const
|
|||
if (lessThenVersion(120000))
|
||||
q += ", relhasoids ";
|
||||
if (minimumVersion(100000))
|
||||
q +=
|
||||
", pg_get_expr(relpartbound, pg_class.oid)"
|
||||
", partstrat, partnatts, partattrs, partclass, partcollation "
|
||||
", pg_get_expr(partexprs, partrelid) AS partexprs";
|
||||
if (minimumVersion(110000))
|
||||
q += ", partdefid";
|
||||
q += ", pg_get_expr(relpartbound, oid)"; // partition specification
|
||||
|
||||
q +=
|
||||
"\nFROM pg_catalog.pg_class \n"
|
||||
" LEFT JOIN pg_catalog.pg_description AS d ON (objoid=pg_class.oid AND objsubid=0) \n";
|
||||
|
||||
if (minimumVersion(100000))
|
||||
q += " LEFT JOIN pg_partitioned_table AS pt ON (partrelid=pg_class.oid) \n";
|
||||
|
||||
q +=
|
||||
" LEFT JOIN pg_catalog.pg_description AS d ON (objoid=pg_class.oid AND objsubid=0) \n"
|
||||
"WHERE relkind IN ('r', 'i', 'p', 'I', 'v', 'm', 'f')";
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class PartitionedTableKeyItemsBuilder {
|
||||
public:
|
||||
int16_t attCount;
|
||||
std::vector<int16_t> attNums;
|
||||
std::vector<Oid> attOpClass;
|
||||
std::vector<Oid> attCollation;
|
||||
std::vector<QString> expressions;
|
||||
|
||||
PartitioningKeyItems Build()
|
||||
{
|
||||
int expr_idx = 0;
|
||||
PartitioningKeyItems result(attCount);
|
||||
for (int attIdx = 0; attIdx < attCount; ++attIdx)
|
||||
{
|
||||
auto& item = result[attIdx];
|
||||
item.attNum = attNums[attIdx];
|
||||
item.opClass = attOpClass[attIdx];
|
||||
item.collation = attCollation[attIdx];
|
||||
if (item.attNum == 0)
|
||||
item.expression = expressions[expr_idx++];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
||||
{
|
||||
Pgsql::Col col(row);
|
||||
|
|
@ -72,7 +35,7 @@ PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
|||
Oid schema_oid = col.nextValue();
|
||||
|
||||
PgClass v(m_catalog, class_oid, name, schema_oid);
|
||||
Oid owner;
|
||||
Oid owner ;
|
||||
col >> v.type >> v.oftype
|
||||
>> owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
|
||||
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
|
||||
|
|
@ -92,33 +55,8 @@ PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
|||
if (lessThenVersion(120000))
|
||||
col >> v.hasoids;
|
||||
|
||||
PgPartitionedTable &pt = v.partitionedTable;
|
||||
if (minimumVersion(100000))
|
||||
{
|
||||
PartitionedTableKeyItemsBuilder kibuilder;
|
||||
|
||||
col >> v.partitionBoundaries;
|
||||
|
||||
auto strategy = col.nextValue();
|
||||
if (strategy.null())
|
||||
{
|
||||
int s = minimumVersion(110000) ? 5 : 4;
|
||||
col.skip(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
pt.strategy << strategy;
|
||||
col >> kibuilder.attCount;
|
||||
col.getAsVector<int16_t>(std::back_inserter(kibuilder.attNums));
|
||||
col.getAsVector<Oid>(std::back_inserter(kibuilder.attOpClass));
|
||||
col.getAsVector<Oid>(std::back_inserter(kibuilder.attCollation));
|
||||
col.getAsVector<QString>(std::back_inserter(kibuilder.expressions));
|
||||
|
||||
pt.keyColumns = kibuilder.Build();
|
||||
if (minimumVersion(110000))
|
||||
col >> pt.defaultPartition;
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,6 @@ void operator<<(ConstraintType &s, const Pgsql::Value &v)
|
|||
case 'x':
|
||||
s = ConstraintType::ExclusionConstraint;
|
||||
break;
|
||||
case 'n':
|
||||
s = ConstraintType::NotNull;
|
||||
break;
|
||||
default:
|
||||
s = ConstraintType::Unknown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,9 +49,6 @@ QString ShortNameForConstraintType(ConstraintType ct)
|
|||
case ConstraintType::ExclusionConstraint:
|
||||
s = "XC";
|
||||
break;
|
||||
case ConstraintType::NotNull:
|
||||
s = "NN";
|
||||
break;
|
||||
default:
|
||||
s = "?";
|
||||
break;
|
||||
|
|
@ -87,9 +78,6 @@ QString LongNameForConstraintType(ConstraintType ct)
|
|||
case ConstraintType::ExclusionConstraint:
|
||||
s = "exclusion constraint";
|
||||
break;
|
||||
case ConstraintType::NotNull:
|
||||
s = "not null";
|
||||
break;
|
||||
default:
|
||||
s = "?";
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -11,14 +11,12 @@
|
|||
#include <vector>
|
||||
|
||||
enum class ConstraintType {
|
||||
Unknown, // not recognized, new???
|
||||
PrimaryKey, // p
|
||||
ForeignKey, // f
|
||||
Unique, // u
|
||||
Check, // c
|
||||
ConstraintTrigger, // t
|
||||
ExclusionConstraint, // x
|
||||
NotNull, // n
|
||||
};
|
||||
|
||||
void operator<<(ConstraintType &s, const Pgsql::Value &v);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "Pgsql_declare.h"
|
||||
#include "Pgsql_Result.h"
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <libpq-fe.h>
|
||||
|
|
@ -69,15 +68,6 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const T* findIf(std::function<bool(const T&)> func) const
|
||||
{
|
||||
auto findResult = std::find_if(m_container.begin(), m_container.end(), func);
|
||||
if (findResult != m_container.end())
|
||||
return &*findResult;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const T* getByName(const QString &name) const
|
||||
{
|
||||
auto find_res = std::find(m_container.begin(), m_container.end(), name);
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ QString PgServerObject::aclAllPattern() const
|
|||
|
||||
QString PgServerObject::dropSql() const
|
||||
{
|
||||
return "DROP " % ddlTypeName() % " " % fullyQualifiedQuotedObjectName() % ";";
|
||||
return "DROP " % typeName() % " " % fullyQualifiedQuotedObjectName() % ";";
|
||||
}
|
||||
|
||||
QString PgServerObject::createSql() const
|
||||
|
|
@ -110,8 +110,3 @@ QString PgServerObject::commentSql() const
|
|||
+ " IS " + escapeLiteral(description) + ";";
|
||||
}
|
||||
|
||||
QString PgServerObject::ddlTypeName() const
|
||||
{
|
||||
return typeName();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,6 @@ public:
|
|||
virtual QString dropSql() const;
|
||||
virtual QString createSql() const;
|
||||
QString commentSql() const;
|
||||
|
||||
protected:
|
||||
virtual QString ddlTypeName() const;
|
||||
|
||||
private:
|
||||
Oid m_ownerOid = InvalidOid;
|
||||
const PgAuthId * m_owner = nullptr;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
*/
|
||||
// QString convert(QStringView in, ConvertToNumericEscape conversion, NumericEscapeFormat format, QString prefix)
|
||||
// {
|
||||
// return "TODO";
|
||||
// }
|
||||
QString convert(QStringView in, ConvertToNumericEscape conversion, NumericEscapeFormat format, QString prefix)
|
||||
{
|
||||
return "TODO";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,6 @@ SOURCES += \
|
|||
catalog/PgConstraintContainer.cpp \
|
||||
ParamListJson.cpp \
|
||||
ParamListModel.cpp \
|
||||
sqlite/SQLiteConnection.cpp \
|
||||
sqlite/sqlite3.c \
|
||||
ui/catalog/tables/TableNode.cpp \
|
||||
ui/catalog/tables/TableSize.cpp \
|
||||
ui/catalog/tables/TableTreeBuilder.cpp \
|
||||
|
|
@ -89,11 +87,7 @@ SOURCES += \
|
|||
catalog/PgLanguage.cpp \
|
||||
catalog/PgAcl.cpp \
|
||||
catalog/PgSequence.cpp \
|
||||
catalog/PgSequenceContainer.cpp \
|
||||
utils/HumanReadableBytes.cpp \
|
||||
utils/KeyStrengthener.cpp \
|
||||
utils/PasswordManager.cpp \
|
||||
utils/PostgresqlUrlParser.cpp
|
||||
catalog/PgSequenceContainer.cpp
|
||||
|
||||
HEADERS += \
|
||||
Pglablib.h \
|
||||
|
|
@ -122,9 +116,6 @@ HEADERS += \
|
|||
catalog/PgConstraintContainer.h \
|
||||
ParamListJson.h \
|
||||
ParamListModel.h \
|
||||
sqlite/SQLiteConnection.h \
|
||||
sqlite/sqlite3.h \
|
||||
sqlite/sqlite3ext.h \
|
||||
ui/catalog/tables/TableNode.h \
|
||||
ui/catalog/tables/TableSize.h \
|
||||
ui/catalog/tables/TableTreeBuilder.h \
|
||||
|
|
@ -171,11 +162,7 @@ HEADERS += \
|
|||
catalog/PgLanguage.h \
|
||||
catalog/PgAcl.h \
|
||||
catalog/PgSequence.h \
|
||||
catalog/PgSequenceContainer.h \
|
||||
utils/HumanReadableBytes.h \
|
||||
utils/KeyStrengthener.h \
|
||||
utils/PasswordManager.h \
|
||||
utils/PostgresqlUrlParser.h
|
||||
catalog/PgSequenceContainer.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
|
|
|||
|
|
@ -1,159 +0,0 @@
|
|||
#include "SQLiteConnection.h"
|
||||
|
||||
|
||||
|
||||
SQLitePreparedStatement::SQLitePreparedStatement(SQLitePreparedStatement &&rhs)
|
||||
: pStatement(rhs.pStatement)
|
||||
{
|
||||
rhs.pStatement = nullptr;
|
||||
}
|
||||
|
||||
SQLitePreparedStatement &SQLitePreparedStatement::operator=(SQLitePreparedStatement &&rhs)
|
||||
{
|
||||
Free();
|
||||
pStatement = rhs.pStatement;
|
||||
rhs.pStatement = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SQLitePreparedStatement::~SQLitePreparedStatement()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
void SQLitePreparedStatement::Open(SQLiteConnection &db, const char *query)
|
||||
{
|
||||
int result = sqlite3_prepare_v2(
|
||||
db.pDb,
|
||||
query,
|
||||
-1,
|
||||
&pStatement,
|
||||
nullptr);
|
||||
db.CheckResult(result);
|
||||
}
|
||||
|
||||
void SQLitePreparedStatement::Open(SQLiteConnection &db, const QString &query)
|
||||
{
|
||||
Open(db, query.toUtf8().constData());
|
||||
}
|
||||
|
||||
void SQLitePreparedStatement::Bind(int index, const char *s, int length)
|
||||
{
|
||||
int result = sqlite3_bind_text(pStatement, index, s, length, SQLITE_STATIC);
|
||||
if (result != SQLITE_OK)
|
||||
throw SQLiteException("failed to bind");
|
||||
}
|
||||
|
||||
void SQLitePreparedStatement::Bind(int index, const QString &s)
|
||||
{
|
||||
int result = sqlite3_bind_text16(pStatement, index, s.constData(), -1, SQLITE_TRANSIENT);
|
||||
if (result != SQLITE_OK)
|
||||
throw SQLiteException("failed to bind");
|
||||
}
|
||||
|
||||
void SQLitePreparedStatement::Bind(int index, int v)
|
||||
{
|
||||
int result = sqlite3_bind_int(pStatement, index, v);
|
||||
if (result != SQLITE_OK)
|
||||
throw SQLiteException("failed to bind");
|
||||
}
|
||||
|
||||
const char *SQLitePreparedStatement::ColumnCharPtr(int col)
|
||||
{
|
||||
return (const char*)sqlite3_column_text(pStatement, col);
|
||||
}
|
||||
|
||||
QString SQLitePreparedStatement::ColumnText(int col)
|
||||
{
|
||||
const unsigned char *val = sqlite3_column_text(pStatement, col);
|
||||
if (val != nullptr)
|
||||
{
|
||||
return QString::fromUtf8(val);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
int SQLitePreparedStatement::ColumnInteger(int col)
|
||||
{
|
||||
return sqlite3_column_int(pStatement, col);
|
||||
}
|
||||
|
||||
bool SQLitePreparedStatement::Step()
|
||||
{
|
||||
int result = sqlite3_step(pStatement);
|
||||
switch (result)
|
||||
{
|
||||
case SQLITE_ROW:
|
||||
return true;
|
||||
case SQLITE_DONE:
|
||||
return false;
|
||||
default:
|
||||
throw std::runtime_error("Error in step");
|
||||
}
|
||||
}
|
||||
|
||||
SQLiteConnection::SQLiteConnection(SQLiteConnection &&rhs)
|
||||
: pDb(rhs.pDb)
|
||||
{
|
||||
rhs.pDb = nullptr;
|
||||
}
|
||||
|
||||
SQLiteConnection &SQLiteConnection::operator=(SQLiteConnection &&rhs)
|
||||
{
|
||||
if (pDb != nullptr)
|
||||
{
|
||||
sqlite3_close(pDb);
|
||||
}
|
||||
pDb = rhs.pDb;
|
||||
rhs.pDb = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SQLiteTransaction::SQLiteTransaction(SQLiteConnection &db)
|
||||
: db(db)
|
||||
{
|
||||
SQLitePreparedStatement stmt = db.Prepare("BEGIN TRANSACTION;");
|
||||
stmt.Step();
|
||||
inTransaction = true;
|
||||
}
|
||||
|
||||
SQLiteTransaction::~SQLiteTransaction()
|
||||
{
|
||||
if (inTransaction)
|
||||
{
|
||||
UncheckedRollback();
|
||||
}
|
||||
}
|
||||
|
||||
void SQLiteTransaction::Commit()
|
||||
{
|
||||
if (inTransaction)
|
||||
{
|
||||
SQLitePreparedStatement stmt = db.Prepare("COMMIT TRANSACTION;");
|
||||
stmt.Step();
|
||||
inTransaction = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw SQLiteException("Transaction already ended or never started");
|
||||
}
|
||||
}
|
||||
|
||||
void SQLiteTransaction::Rollback()
|
||||
{
|
||||
if (inTransaction)
|
||||
{
|
||||
UncheckedRollback();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw SQLiteException("Transaction already ended or never started");
|
||||
}
|
||||
}
|
||||
|
||||
void SQLiteTransaction::UncheckedRollback()
|
||||
{
|
||||
SQLitePreparedStatement stmt = db.Prepare("ROLLBACK TRANSACTION;");
|
||||
stmt.Step();
|
||||
inTransaction = false;
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "sqlite3.h"
|
||||
#include <qstring.h>
|
||||
#include <stdexcept>
|
||||
|
||||
class SQLiteException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit SQLiteException(const char* msg)
|
||||
: std::runtime_error(msg)
|
||||
{}
|
||||
};
|
||||
|
||||
class SQLiteConnection;
|
||||
|
||||
class SQLitePreparedStatement
|
||||
{
|
||||
public:
|
||||
SQLitePreparedStatement() = default;
|
||||
SQLitePreparedStatement(const SQLitePreparedStatement &) = delete;
|
||||
SQLitePreparedStatement(SQLitePreparedStatement&& rhs);
|
||||
SQLitePreparedStatement &operator=(SQLitePreparedStatement&& rhs);
|
||||
|
||||
~SQLitePreparedStatement();
|
||||
|
||||
void Open(SQLiteConnection &db, const char *query);
|
||||
void Open(SQLiteConnection &db, const QString &query);
|
||||
|
||||
void Bind(int index, const char *s, int length = 0);
|
||||
void Bind(int index, const QString &s);
|
||||
void Bind(int index, int v);
|
||||
|
||||
const char* ColumnCharPtr(int col);
|
||||
QString ColumnText(int col);
|
||||
int ColumnInteger(int col);
|
||||
|
||||
bool Step();
|
||||
|
||||
void Reset()
|
||||
{
|
||||
sqlite3_reset(pStatement);
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3_stmt *pStatement = nullptr;
|
||||
|
||||
void Free()
|
||||
{
|
||||
if (pStatement != nullptr)
|
||||
{
|
||||
sqlite3_finalize(pStatement);
|
||||
pStatement = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SQLiteTransaction
|
||||
{
|
||||
public:
|
||||
explicit SQLiteTransaction(SQLiteConnection &db);
|
||||
SQLiteTransaction(const SQLiteTransaction&&) = delete;
|
||||
|
||||
~SQLiteTransaction();
|
||||
|
||||
void Commit();
|
||||
void Rollback();
|
||||
private:
|
||||
SQLiteConnection &db;
|
||||
bool inTransaction = false;
|
||||
void UncheckedRollback();
|
||||
};
|
||||
|
||||
class SQLiteConnection
|
||||
{
|
||||
public:
|
||||
SQLiteConnection() = default;
|
||||
SQLiteConnection(const SQLiteConnection&) = delete;
|
||||
|
||||
SQLiteConnection(SQLiteConnection&& rhs);
|
||||
|
||||
SQLiteConnection& operator=(const SQLiteConnection &) = delete;
|
||||
|
||||
SQLiteConnection& operator=(SQLiteConnection && rhs);
|
||||
|
||||
~SQLiteConnection()
|
||||
{
|
||||
if (pDb)
|
||||
{
|
||||
sqlite3_close(pDb);
|
||||
}
|
||||
}
|
||||
|
||||
void Open(const char *filename)
|
||||
{
|
||||
int result = sqlite3_open(filename, &pDb);
|
||||
CheckResult(result);
|
||||
}
|
||||
|
||||
void Open(QString filename)
|
||||
{
|
||||
int result = sqlite3_open16((void*)filename.data(), &pDb);
|
||||
CheckResult(result);
|
||||
}
|
||||
|
||||
void CheckResult(int result)
|
||||
{
|
||||
if (result == SQLITE_OK)
|
||||
return;
|
||||
|
||||
if (pDb == nullptr)
|
||||
{
|
||||
const char * msg = sqlite3_errstr(result);
|
||||
throw SQLiteException(msg);
|
||||
}
|
||||
const char * msg = sqlite3_errmsg(pDb);
|
||||
throw SQLiteException(msg);
|
||||
}
|
||||
|
||||
SQLitePreparedStatement Prepare(const char* query)
|
||||
{
|
||||
SQLitePreparedStatement stmt;
|
||||
stmt.Open(*this, query);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
SQLitePreparedStatement Prepare(const QString &query)
|
||||
{
|
||||
SQLitePreparedStatement stmt;
|
||||
stmt.Open(*this, query);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
void Exec(const char* query)
|
||||
{
|
||||
SQLitePreparedStatement stmt = Prepare(query);
|
||||
stmt.Step();
|
||||
}
|
||||
|
||||
void Exec(QString query)
|
||||
{
|
||||
SQLitePreparedStatement stmt = Prepare(query.toUtf8().constData());
|
||||
stmt.Step();
|
||||
}
|
||||
|
||||
int64_t LastInsertRowId()
|
||||
{
|
||||
return sqlite3_last_insert_rowid(pDb);
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3 *pDb = nullptr;
|
||||
|
||||
friend class SQLitePreparedStatement;
|
||||
};
|
||||
261452
pglablib/sqlite/sqlite3.c
261452
pglablib/sqlite/sqlite3.c
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,719 +0,0 @@
|
|||
/*
|
||||
** 2006 June 7
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This header file defines the SQLite interface for use by
|
||||
** shared libraries that want to be imported as extensions into
|
||||
** an SQLite instance. Shared libraries that intend to be loaded
|
||||
** as extensions by SQLite should #include this file instead of
|
||||
** sqlite3.h.
|
||||
*/
|
||||
#ifndef SQLITE3EXT_H
|
||||
#define SQLITE3EXT_H
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*
|
||||
** The following structure holds pointers to all of the SQLite API
|
||||
** routines.
|
||||
**
|
||||
** WARNING: In order to maintain backwards compatibility, add new
|
||||
** interfaces to the end of this structure only. If you insert new
|
||||
** interfaces in the middle of this structure, then older different
|
||||
** versions of SQLite will not be able to load each other's shared
|
||||
** libraries!
|
||||
*/
|
||||
struct sqlite3_api_routines {
|
||||
void * (*aggregate_context)(sqlite3_context*,int nBytes);
|
||||
int (*aggregate_count)(sqlite3_context*);
|
||||
int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
|
||||
int (*bind_double)(sqlite3_stmt*,int,double);
|
||||
int (*bind_int)(sqlite3_stmt*,int,int);
|
||||
int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
|
||||
int (*bind_null)(sqlite3_stmt*,int);
|
||||
int (*bind_parameter_count)(sqlite3_stmt*);
|
||||
int (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
|
||||
const char * (*bind_parameter_name)(sqlite3_stmt*,int);
|
||||
int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
|
||||
int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
|
||||
int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
|
||||
int (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
|
||||
int (*busy_timeout)(sqlite3*,int ms);
|
||||
int (*changes)(sqlite3*);
|
||||
int (*close)(sqlite3*);
|
||||
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const char*));
|
||||
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const void*));
|
||||
const void * (*column_blob)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_count)(sqlite3_stmt*pStmt);
|
||||
const char * (*column_database_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_database_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_decltype)(sqlite3_stmt*,int i);
|
||||
const void * (*column_decltype16)(sqlite3_stmt*,int);
|
||||
double (*column_double)(sqlite3_stmt*,int iCol);
|
||||
int (*column_int)(sqlite3_stmt*,int iCol);
|
||||
sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol);
|
||||
const char * (*column_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_origin_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_origin_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_table_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_table_name16)(sqlite3_stmt*,int);
|
||||
const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
|
||||
const void * (*column_text16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_type)(sqlite3_stmt*,int iCol);
|
||||
sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
|
||||
void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
|
||||
int (*complete)(const char*sql);
|
||||
int (*complete16)(const void*sql);
|
||||
int (*create_collation)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_collation16)(sqlite3*,const void*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_function)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_function16)(sqlite3*,const void*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
|
||||
int (*data_count)(sqlite3_stmt*pStmt);
|
||||
sqlite3 * (*db_handle)(sqlite3_stmt*);
|
||||
int (*declare_vtab)(sqlite3*,const char*);
|
||||
int (*enable_shared_cache)(int);
|
||||
int (*errcode)(sqlite3*db);
|
||||
const char * (*errmsg)(sqlite3*);
|
||||
const void * (*errmsg16)(sqlite3*);
|
||||
int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
|
||||
int (*expired)(sqlite3_stmt*);
|
||||
int (*finalize)(sqlite3_stmt*pStmt);
|
||||
void (*free)(void*);
|
||||
void (*free_table)(char**result);
|
||||
int (*get_autocommit)(sqlite3*);
|
||||
void * (*get_auxdata)(sqlite3_context*,int);
|
||||
int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
|
||||
int (*global_recover)(void);
|
||||
void (*interruptx)(sqlite3*);
|
||||
sqlite_int64 (*last_insert_rowid)(sqlite3*);
|
||||
const char * (*libversion)(void);
|
||||
int (*libversion_number)(void);
|
||||
void *(*malloc)(int);
|
||||
char * (*mprintf)(const char*,...);
|
||||
int (*open)(const char*,sqlite3**);
|
||||
int (*open16)(const void*,sqlite3**);
|
||||
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
|
||||
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
|
||||
void *(*realloc)(void*,int);
|
||||
int (*reset)(sqlite3_stmt*pStmt);
|
||||
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_double)(sqlite3_context*,double);
|
||||
void (*result_error)(sqlite3_context*,const char*,int);
|
||||
void (*result_error16)(sqlite3_context*,const void*,int);
|
||||
void (*result_int)(sqlite3_context*,int);
|
||||
void (*result_int64)(sqlite3_context*,sqlite_int64);
|
||||
void (*result_null)(sqlite3_context*);
|
||||
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
|
||||
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_value)(sqlite3_context*,sqlite3_value*);
|
||||
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
|
||||
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
|
||||
const char*,const char*),void*);
|
||||
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
|
||||
char * (*xsnprintf)(int,char*,const char*,...);
|
||||
int (*step)(sqlite3_stmt*);
|
||||
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
|
||||
char const**,char const**,int*,int*,int*);
|
||||
void (*thread_cleanup)(void);
|
||||
int (*total_changes)(sqlite3*);
|
||||
void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
|
||||
int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
|
||||
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
|
||||
sqlite_int64),void*);
|
||||
void * (*user_data)(sqlite3_context*);
|
||||
const void * (*value_blob)(sqlite3_value*);
|
||||
int (*value_bytes)(sqlite3_value*);
|
||||
int (*value_bytes16)(sqlite3_value*);
|
||||
double (*value_double)(sqlite3_value*);
|
||||
int (*value_int)(sqlite3_value*);
|
||||
sqlite_int64 (*value_int64)(sqlite3_value*);
|
||||
int (*value_numeric_type)(sqlite3_value*);
|
||||
const unsigned char * (*value_text)(sqlite3_value*);
|
||||
const void * (*value_text16)(sqlite3_value*);
|
||||
const void * (*value_text16be)(sqlite3_value*);
|
||||
const void * (*value_text16le)(sqlite3_value*);
|
||||
int (*value_type)(sqlite3_value*);
|
||||
char *(*vmprintf)(const char*,va_list);
|
||||
/* Added ??? */
|
||||
int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
|
||||
/* Added by 3.3.13 */
|
||||
int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
int (*clear_bindings)(sqlite3_stmt*);
|
||||
/* Added by 3.4.1 */
|
||||
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
|
||||
void (*xDestroy)(void *));
|
||||
/* Added by 3.5.0 */
|
||||
int (*bind_zeroblob)(sqlite3_stmt*,int,int);
|
||||
int (*blob_bytes)(sqlite3_blob*);
|
||||
int (*blob_close)(sqlite3_blob*);
|
||||
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
|
||||
int,sqlite3_blob**);
|
||||
int (*blob_read)(sqlite3_blob*,void*,int,int);
|
||||
int (*blob_write)(sqlite3_blob*,const void*,int,int);
|
||||
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*),
|
||||
void(*)(void*));
|
||||
int (*file_control)(sqlite3*,const char*,int,void*);
|
||||
sqlite3_int64 (*memory_highwater)(int);
|
||||
sqlite3_int64 (*memory_used)(void);
|
||||
sqlite3_mutex *(*mutex_alloc)(int);
|
||||
void (*mutex_enter)(sqlite3_mutex*);
|
||||
void (*mutex_free)(sqlite3_mutex*);
|
||||
void (*mutex_leave)(sqlite3_mutex*);
|
||||
int (*mutex_try)(sqlite3_mutex*);
|
||||
int (*open_v2)(const char*,sqlite3**,int,const char*);
|
||||
int (*release_memory)(int);
|
||||
void (*result_error_nomem)(sqlite3_context*);
|
||||
void (*result_error_toobig)(sqlite3_context*);
|
||||
int (*sleep)(int);
|
||||
void (*soft_heap_limit)(int);
|
||||
sqlite3_vfs *(*vfs_find)(const char*);
|
||||
int (*vfs_register)(sqlite3_vfs*,int);
|
||||
int (*vfs_unregister)(sqlite3_vfs*);
|
||||
int (*xthreadsafe)(void);
|
||||
void (*result_zeroblob)(sqlite3_context*,int);
|
||||
void (*result_error_code)(sqlite3_context*,int);
|
||||
int (*test_control)(int, ...);
|
||||
void (*randomness)(int,void*);
|
||||
sqlite3 *(*context_db_handle)(sqlite3_context*);
|
||||
int (*extended_result_codes)(sqlite3*,int);
|
||||
int (*limit)(sqlite3*,int,int);
|
||||
sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
|
||||
const char *(*sql)(sqlite3_stmt*);
|
||||
int (*status)(int,int*,int*,int);
|
||||
int (*backup_finish)(sqlite3_backup*);
|
||||
sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*);
|
||||
int (*backup_pagecount)(sqlite3_backup*);
|
||||
int (*backup_remaining)(sqlite3_backup*);
|
||||
int (*backup_step)(sqlite3_backup*,int);
|
||||
const char *(*compileoption_get)(int);
|
||||
int (*compileoption_used)(const char*);
|
||||
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*),
|
||||
void(*xDestroy)(void*));
|
||||
int (*db_config)(sqlite3*,int,...);
|
||||
sqlite3_mutex *(*db_mutex)(sqlite3*);
|
||||
int (*db_status)(sqlite3*,int,int*,int*,int);
|
||||
int (*extended_errcode)(sqlite3*);
|
||||
void (*log)(int,const char*,...);
|
||||
sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
|
||||
const char *(*sourceid)(void);
|
||||
int (*stmt_status)(sqlite3_stmt*,int,int);
|
||||
int (*strnicmp)(const char*,const char*,int);
|
||||
int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
|
||||
int (*wal_autocheckpoint)(sqlite3*,int);
|
||||
int (*wal_checkpoint)(sqlite3*,const char*);
|
||||
void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
|
||||
int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
|
||||
int (*vtab_config)(sqlite3*,int op,...);
|
||||
int (*vtab_on_conflict)(sqlite3*);
|
||||
/* Version 3.7.16 and later */
|
||||
int (*close_v2)(sqlite3*);
|
||||
const char *(*db_filename)(sqlite3*,const char*);
|
||||
int (*db_readonly)(sqlite3*,const char*);
|
||||
int (*db_release_memory)(sqlite3*);
|
||||
const char *(*errstr)(int);
|
||||
int (*stmt_busy)(sqlite3_stmt*);
|
||||
int (*stmt_readonly)(sqlite3_stmt*);
|
||||
int (*stricmp)(const char*,const char*);
|
||||
int (*uri_boolean)(const char*,const char*,int);
|
||||
sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
|
||||
const char *(*uri_parameter)(const char*,const char*);
|
||||
char *(*xvsnprintf)(int,char*,const char*,va_list);
|
||||
int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
|
||||
/* Version 3.8.7 and later */
|
||||
int (*auto_extension)(void(*)(void));
|
||||
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
|
||||
void(*)(void*),unsigned char);
|
||||
int (*cancel_auto_extension)(void(*)(void));
|
||||
int (*load_extension)(sqlite3*,const char*,const char*,char**);
|
||||
void *(*malloc64)(sqlite3_uint64);
|
||||
sqlite3_uint64 (*msize)(void*);
|
||||
void *(*realloc64)(void*,sqlite3_uint64);
|
||||
void (*reset_auto_extension)(void);
|
||||
void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
|
||||
void(*)(void*), unsigned char);
|
||||
int (*strglob)(const char*,const char*);
|
||||
/* Version 3.8.11 and later */
|
||||
sqlite3_value *(*value_dup)(const sqlite3_value*);
|
||||
void (*value_free)(sqlite3_value*);
|
||||
int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
|
||||
int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
|
||||
/* Version 3.9.0 and later */
|
||||
unsigned int (*value_subtype)(sqlite3_value*);
|
||||
void (*result_subtype)(sqlite3_context*,unsigned int);
|
||||
/* Version 3.10.0 and later */
|
||||
int (*status64)(int,sqlite3_int64*,sqlite3_int64*,int);
|
||||
int (*strlike)(const char*,const char*,unsigned int);
|
||||
int (*db_cacheflush)(sqlite3*);
|
||||
/* Version 3.12.0 and later */
|
||||
int (*system_errno)(sqlite3*);
|
||||
/* Version 3.14.0 and later */
|
||||
int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
|
||||
char *(*expanded_sql)(sqlite3_stmt*);
|
||||
/* Version 3.18.0 and later */
|
||||
void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64);
|
||||
/* Version 3.20.0 and later */
|
||||
int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
|
||||
sqlite3_stmt**,const char**);
|
||||
int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
|
||||
sqlite3_stmt**,const void**);
|
||||
int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
|
||||
void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
|
||||
void *(*value_pointer)(sqlite3_value*,const char*);
|
||||
int (*vtab_nochange)(sqlite3_context*);
|
||||
int (*value_nochange)(sqlite3_value*);
|
||||
const char *(*vtab_collation)(sqlite3_index_info*,int);
|
||||
/* Version 3.24.0 and later */
|
||||
int (*keyword_count)(void);
|
||||
int (*keyword_name)(int,const char**,int*);
|
||||
int (*keyword_check)(const char*,int);
|
||||
sqlite3_str *(*str_new)(sqlite3*);
|
||||
char *(*str_finish)(sqlite3_str*);
|
||||
void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
|
||||
void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
|
||||
void (*str_append)(sqlite3_str*, const char *zIn, int N);
|
||||
void (*str_appendall)(sqlite3_str*, const char *zIn);
|
||||
void (*str_appendchar)(sqlite3_str*, int N, char C);
|
||||
void (*str_reset)(sqlite3_str*);
|
||||
int (*str_errcode)(sqlite3_str*);
|
||||
int (*str_length)(sqlite3_str*);
|
||||
char *(*str_value)(sqlite3_str*);
|
||||
/* Version 3.25.0 and later */
|
||||
int (*create_window_function)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*),
|
||||
void (*xValue)(sqlite3_context*),
|
||||
void (*xInv)(sqlite3_context*,int,sqlite3_value**),
|
||||
void(*xDestroy)(void*));
|
||||
/* Version 3.26.0 and later */
|
||||
const char *(*normalized_sql)(sqlite3_stmt*);
|
||||
/* Version 3.28.0 and later */
|
||||
int (*stmt_isexplain)(sqlite3_stmt*);
|
||||
int (*value_frombind)(sqlite3_value*);
|
||||
/* Version 3.30.0 and later */
|
||||
int (*drop_modules)(sqlite3*,const char**);
|
||||
/* Version 3.31.0 and later */
|
||||
sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64);
|
||||
const char *(*uri_key)(const char*,int);
|
||||
const char *(*filename_database)(const char*);
|
||||
const char *(*filename_journal)(const char*);
|
||||
const char *(*filename_wal)(const char*);
|
||||
/* Version 3.32.0 and later */
|
||||
const char *(*create_filename)(const char*,const char*,const char*,
|
||||
int,const char**);
|
||||
void (*free_filename)(const char*);
|
||||
sqlite3_file *(*database_file_object)(const char*);
|
||||
/* Version 3.34.0 and later */
|
||||
int (*txn_state)(sqlite3*,const char*);
|
||||
/* Version 3.36.1 and later */
|
||||
sqlite3_int64 (*changes64)(sqlite3*);
|
||||
sqlite3_int64 (*total_changes64)(sqlite3*);
|
||||
/* Version 3.37.0 and later */
|
||||
int (*autovacuum_pages)(sqlite3*,
|
||||
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
|
||||
void*, void(*)(void*));
|
||||
/* Version 3.38.0 and later */
|
||||
int (*error_offset)(sqlite3*);
|
||||
int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
|
||||
int (*vtab_distinct)(sqlite3_index_info*);
|
||||
int (*vtab_in)(sqlite3_index_info*,int,int);
|
||||
int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
|
||||
int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
|
||||
/* Version 3.39.0 and later */
|
||||
int (*deserialize)(sqlite3*,const char*,unsigned char*,
|
||||
sqlite3_int64,sqlite3_int64,unsigned);
|
||||
unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
|
||||
unsigned int);
|
||||
const char *(*db_name)(sqlite3*,int);
|
||||
/* Version 3.40.0 and later */
|
||||
int (*value_encoding)(sqlite3_value*);
|
||||
/* Version 3.41.0 and later */
|
||||
int (*is_interrupted)(sqlite3*);
|
||||
/* Version 3.43.0 and later */
|
||||
int (*stmt_explain)(sqlite3_stmt*,int);
|
||||
/* Version 3.44.0 and later */
|
||||
void *(*get_clientdata)(sqlite3*,const char*);
|
||||
int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
|
||||
};
|
||||
|
||||
/*
|
||||
** This is the function signature used for all extension entry points. It
|
||||
** is also defined in the file "loadext.c".
|
||||
*/
|
||||
typedef int (*sqlite3_loadext_entry)(
|
||||
sqlite3 *db, /* Handle to the database. */
|
||||
char **pzErrMsg, /* Used to set error string on failure. */
|
||||
const sqlite3_api_routines *pThunk /* Extension API function pointers. */
|
||||
);
|
||||
|
||||
/*
|
||||
** The following macros redefine the API routines so that they are
|
||||
** redirected through the global sqlite3_api structure.
|
||||
**
|
||||
** This header file is also used by the loadext.c source file
|
||||
** (part of the main SQLite library - not an extension) so that
|
||||
** it can get access to the sqlite3_api_routines structure
|
||||
** definition. But the main library does not want to redefine
|
||||
** the API. So the redefinition macros are only valid if the
|
||||
** SQLITE_CORE macros is undefined.
|
||||
*/
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
|
||||
#endif
|
||||
#define sqlite3_bind_blob sqlite3_api->bind_blob
|
||||
#define sqlite3_bind_double sqlite3_api->bind_double
|
||||
#define sqlite3_bind_int sqlite3_api->bind_int
|
||||
#define sqlite3_bind_int64 sqlite3_api->bind_int64
|
||||
#define sqlite3_bind_null sqlite3_api->bind_null
|
||||
#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count
|
||||
#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index
|
||||
#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name
|
||||
#define sqlite3_bind_text sqlite3_api->bind_text
|
||||
#define sqlite3_bind_text16 sqlite3_api->bind_text16
|
||||
#define sqlite3_bind_value sqlite3_api->bind_value
|
||||
#define sqlite3_busy_handler sqlite3_api->busy_handler
|
||||
#define sqlite3_busy_timeout sqlite3_api->busy_timeout
|
||||
#define sqlite3_changes sqlite3_api->changes
|
||||
#define sqlite3_close sqlite3_api->close
|
||||
#define sqlite3_collation_needed sqlite3_api->collation_needed
|
||||
#define sqlite3_collation_needed16 sqlite3_api->collation_needed16
|
||||
#define sqlite3_column_blob sqlite3_api->column_blob
|
||||
#define sqlite3_column_bytes sqlite3_api->column_bytes
|
||||
#define sqlite3_column_bytes16 sqlite3_api->column_bytes16
|
||||
#define sqlite3_column_count sqlite3_api->column_count
|
||||
#define sqlite3_column_database_name sqlite3_api->column_database_name
|
||||
#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
|
||||
#define sqlite3_column_decltype sqlite3_api->column_decltype
|
||||
#define sqlite3_column_decltype16 sqlite3_api->column_decltype16
|
||||
#define sqlite3_column_double sqlite3_api->column_double
|
||||
#define sqlite3_column_int sqlite3_api->column_int
|
||||
#define sqlite3_column_int64 sqlite3_api->column_int64
|
||||
#define sqlite3_column_name sqlite3_api->column_name
|
||||
#define sqlite3_column_name16 sqlite3_api->column_name16
|
||||
#define sqlite3_column_origin_name sqlite3_api->column_origin_name
|
||||
#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16
|
||||
#define sqlite3_column_table_name sqlite3_api->column_table_name
|
||||
#define sqlite3_column_table_name16 sqlite3_api->column_table_name16
|
||||
#define sqlite3_column_text sqlite3_api->column_text
|
||||
#define sqlite3_column_text16 sqlite3_api->column_text16
|
||||
#define sqlite3_column_type sqlite3_api->column_type
|
||||
#define sqlite3_column_value sqlite3_api->column_value
|
||||
#define sqlite3_commit_hook sqlite3_api->commit_hook
|
||||
#define sqlite3_complete sqlite3_api->complete
|
||||
#define sqlite3_complete16 sqlite3_api->complete16
|
||||
#define sqlite3_create_collation sqlite3_api->create_collation
|
||||
#define sqlite3_create_collation16 sqlite3_api->create_collation16
|
||||
#define sqlite3_create_function sqlite3_api->create_function
|
||||
#define sqlite3_create_function16 sqlite3_api->create_function16
|
||||
#define sqlite3_create_module sqlite3_api->create_module
|
||||
#define sqlite3_create_module_v2 sqlite3_api->create_module_v2
|
||||
#define sqlite3_data_count sqlite3_api->data_count
|
||||
#define sqlite3_db_handle sqlite3_api->db_handle
|
||||
#define sqlite3_declare_vtab sqlite3_api->declare_vtab
|
||||
#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache
|
||||
#define sqlite3_errcode sqlite3_api->errcode
|
||||
#define sqlite3_errmsg sqlite3_api->errmsg
|
||||
#define sqlite3_errmsg16 sqlite3_api->errmsg16
|
||||
#define sqlite3_exec sqlite3_api->exec
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_expired sqlite3_api->expired
|
||||
#endif
|
||||
#define sqlite3_finalize sqlite3_api->finalize
|
||||
#define sqlite3_free sqlite3_api->free
|
||||
#define sqlite3_free_table sqlite3_api->free_table
|
||||
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
|
||||
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
|
||||
#define sqlite3_get_table sqlite3_api->get_table
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_global_recover sqlite3_api->global_recover
|
||||
#endif
|
||||
#define sqlite3_interrupt sqlite3_api->interruptx
|
||||
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
|
||||
#define sqlite3_libversion sqlite3_api->libversion
|
||||
#define sqlite3_libversion_number sqlite3_api->libversion_number
|
||||
#define sqlite3_malloc sqlite3_api->malloc
|
||||
#define sqlite3_mprintf sqlite3_api->mprintf
|
||||
#define sqlite3_open sqlite3_api->open
|
||||
#define sqlite3_open16 sqlite3_api->open16
|
||||
#define sqlite3_prepare sqlite3_api->prepare
|
||||
#define sqlite3_prepare16 sqlite3_api->prepare16
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_profile sqlite3_api->profile
|
||||
#define sqlite3_progress_handler sqlite3_api->progress_handler
|
||||
#define sqlite3_realloc sqlite3_api->realloc
|
||||
#define sqlite3_reset sqlite3_api->reset
|
||||
#define sqlite3_result_blob sqlite3_api->result_blob
|
||||
#define sqlite3_result_double sqlite3_api->result_double
|
||||
#define sqlite3_result_error sqlite3_api->result_error
|
||||
#define sqlite3_result_error16 sqlite3_api->result_error16
|
||||
#define sqlite3_result_int sqlite3_api->result_int
|
||||
#define sqlite3_result_int64 sqlite3_api->result_int64
|
||||
#define sqlite3_result_null sqlite3_api->result_null
|
||||
#define sqlite3_result_text sqlite3_api->result_text
|
||||
#define sqlite3_result_text16 sqlite3_api->result_text16
|
||||
#define sqlite3_result_text16be sqlite3_api->result_text16be
|
||||
#define sqlite3_result_text16le sqlite3_api->result_text16le
|
||||
#define sqlite3_result_value sqlite3_api->result_value
|
||||
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
|
||||
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
|
||||
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
|
||||
#define sqlite3_snprintf sqlite3_api->xsnprintf
|
||||
#define sqlite3_step sqlite3_api->step
|
||||
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
|
||||
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
|
||||
#define sqlite3_total_changes sqlite3_api->total_changes
|
||||
#define sqlite3_trace sqlite3_api->trace
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
|
||||
#endif
|
||||
#define sqlite3_update_hook sqlite3_api->update_hook
|
||||
#define sqlite3_user_data sqlite3_api->user_data
|
||||
#define sqlite3_value_blob sqlite3_api->value_blob
|
||||
#define sqlite3_value_bytes sqlite3_api->value_bytes
|
||||
#define sqlite3_value_bytes16 sqlite3_api->value_bytes16
|
||||
#define sqlite3_value_double sqlite3_api->value_double
|
||||
#define sqlite3_value_int sqlite3_api->value_int
|
||||
#define sqlite3_value_int64 sqlite3_api->value_int64
|
||||
#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type
|
||||
#define sqlite3_value_text sqlite3_api->value_text
|
||||
#define sqlite3_value_text16 sqlite3_api->value_text16
|
||||
#define sqlite3_value_text16be sqlite3_api->value_text16be
|
||||
#define sqlite3_value_text16le sqlite3_api->value_text16le
|
||||
#define sqlite3_value_type sqlite3_api->value_type
|
||||
#define sqlite3_vmprintf sqlite3_api->vmprintf
|
||||
#define sqlite3_vsnprintf sqlite3_api->xvsnprintf
|
||||
#define sqlite3_overload_function sqlite3_api->overload_function
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
|
||||
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
|
||||
#define sqlite3_blob_bytes sqlite3_api->blob_bytes
|
||||
#define sqlite3_blob_close sqlite3_api->blob_close
|
||||
#define sqlite3_blob_open sqlite3_api->blob_open
|
||||
#define sqlite3_blob_read sqlite3_api->blob_read
|
||||
#define sqlite3_blob_write sqlite3_api->blob_write
|
||||
#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2
|
||||
#define sqlite3_file_control sqlite3_api->file_control
|
||||
#define sqlite3_memory_highwater sqlite3_api->memory_highwater
|
||||
#define sqlite3_memory_used sqlite3_api->memory_used
|
||||
#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc
|
||||
#define sqlite3_mutex_enter sqlite3_api->mutex_enter
|
||||
#define sqlite3_mutex_free sqlite3_api->mutex_free
|
||||
#define sqlite3_mutex_leave sqlite3_api->mutex_leave
|
||||
#define sqlite3_mutex_try sqlite3_api->mutex_try
|
||||
#define sqlite3_open_v2 sqlite3_api->open_v2
|
||||
#define sqlite3_release_memory sqlite3_api->release_memory
|
||||
#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem
|
||||
#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig
|
||||
#define sqlite3_sleep sqlite3_api->sleep
|
||||
#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit
|
||||
#define sqlite3_vfs_find sqlite3_api->vfs_find
|
||||
#define sqlite3_vfs_register sqlite3_api->vfs_register
|
||||
#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister
|
||||
#define sqlite3_threadsafe sqlite3_api->xthreadsafe
|
||||
#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob
|
||||
#define sqlite3_result_error_code sqlite3_api->result_error_code
|
||||
#define sqlite3_test_control sqlite3_api->test_control
|
||||
#define sqlite3_randomness sqlite3_api->randomness
|
||||
#define sqlite3_context_db_handle sqlite3_api->context_db_handle
|
||||
#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes
|
||||
#define sqlite3_limit sqlite3_api->limit
|
||||
#define sqlite3_next_stmt sqlite3_api->next_stmt
|
||||
#define sqlite3_sql sqlite3_api->sql
|
||||
#define sqlite3_status sqlite3_api->status
|
||||
#define sqlite3_backup_finish sqlite3_api->backup_finish
|
||||
#define sqlite3_backup_init sqlite3_api->backup_init
|
||||
#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount
|
||||
#define sqlite3_backup_remaining sqlite3_api->backup_remaining
|
||||
#define sqlite3_backup_step sqlite3_api->backup_step
|
||||
#define sqlite3_compileoption_get sqlite3_api->compileoption_get
|
||||
#define sqlite3_compileoption_used sqlite3_api->compileoption_used
|
||||
#define sqlite3_create_function_v2 sqlite3_api->create_function_v2
|
||||
#define sqlite3_db_config sqlite3_api->db_config
|
||||
#define sqlite3_db_mutex sqlite3_api->db_mutex
|
||||
#define sqlite3_db_status sqlite3_api->db_status
|
||||
#define sqlite3_extended_errcode sqlite3_api->extended_errcode
|
||||
#define sqlite3_log sqlite3_api->log
|
||||
#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64
|
||||
#define sqlite3_sourceid sqlite3_api->sourceid
|
||||
#define sqlite3_stmt_status sqlite3_api->stmt_status
|
||||
#define sqlite3_strnicmp sqlite3_api->strnicmp
|
||||
#define sqlite3_unlock_notify sqlite3_api->unlock_notify
|
||||
#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint
|
||||
#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint
|
||||
#define sqlite3_wal_hook sqlite3_api->wal_hook
|
||||
#define sqlite3_blob_reopen sqlite3_api->blob_reopen
|
||||
#define sqlite3_vtab_config sqlite3_api->vtab_config
|
||||
#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict
|
||||
/* Version 3.7.16 and later */
|
||||
#define sqlite3_close_v2 sqlite3_api->close_v2
|
||||
#define sqlite3_db_filename sqlite3_api->db_filename
|
||||
#define sqlite3_db_readonly sqlite3_api->db_readonly
|
||||
#define sqlite3_db_release_memory sqlite3_api->db_release_memory
|
||||
#define sqlite3_errstr sqlite3_api->errstr
|
||||
#define sqlite3_stmt_busy sqlite3_api->stmt_busy
|
||||
#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
|
||||
#define sqlite3_stricmp sqlite3_api->stricmp
|
||||
#define sqlite3_uri_boolean sqlite3_api->uri_boolean
|
||||
#define sqlite3_uri_int64 sqlite3_api->uri_int64
|
||||
#define sqlite3_uri_parameter sqlite3_api->uri_parameter
|
||||
#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf
|
||||
#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
|
||||
/* Version 3.8.7 and later */
|
||||
#define sqlite3_auto_extension sqlite3_api->auto_extension
|
||||
#define sqlite3_bind_blob64 sqlite3_api->bind_blob64
|
||||
#define sqlite3_bind_text64 sqlite3_api->bind_text64
|
||||
#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension
|
||||
#define sqlite3_load_extension sqlite3_api->load_extension
|
||||
#define sqlite3_malloc64 sqlite3_api->malloc64
|
||||
#define sqlite3_msize sqlite3_api->msize
|
||||
#define sqlite3_realloc64 sqlite3_api->realloc64
|
||||
#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension
|
||||
#define sqlite3_result_blob64 sqlite3_api->result_blob64
|
||||
#define sqlite3_result_text64 sqlite3_api->result_text64
|
||||
#define sqlite3_strglob sqlite3_api->strglob
|
||||
/* Version 3.8.11 and later */
|
||||
#define sqlite3_value_dup sqlite3_api->value_dup
|
||||
#define sqlite3_value_free sqlite3_api->value_free
|
||||
#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
|
||||
#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
|
||||
/* Version 3.9.0 and later */
|
||||
#define sqlite3_value_subtype sqlite3_api->value_subtype
|
||||
#define sqlite3_result_subtype sqlite3_api->result_subtype
|
||||
/* Version 3.10.0 and later */
|
||||
#define sqlite3_status64 sqlite3_api->status64
|
||||
#define sqlite3_strlike sqlite3_api->strlike
|
||||
#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush
|
||||
/* Version 3.12.0 and later */
|
||||
#define sqlite3_system_errno sqlite3_api->system_errno
|
||||
/* Version 3.14.0 and later */
|
||||
#define sqlite3_trace_v2 sqlite3_api->trace_v2
|
||||
#define sqlite3_expanded_sql sqlite3_api->expanded_sql
|
||||
/* Version 3.18.0 and later */
|
||||
#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid
|
||||
/* Version 3.20.0 and later */
|
||||
#define sqlite3_prepare_v3 sqlite3_api->prepare_v3
|
||||
#define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3
|
||||
#define sqlite3_bind_pointer sqlite3_api->bind_pointer
|
||||
#define sqlite3_result_pointer sqlite3_api->result_pointer
|
||||
#define sqlite3_value_pointer sqlite3_api->value_pointer
|
||||
/* Version 3.22.0 and later */
|
||||
#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
|
||||
#define sqlite3_value_nochange sqlite3_api->value_nochange
|
||||
#define sqlite3_vtab_collation sqlite3_api->vtab_collation
|
||||
/* Version 3.24.0 and later */
|
||||
#define sqlite3_keyword_count sqlite3_api->keyword_count
|
||||
#define sqlite3_keyword_name sqlite3_api->keyword_name
|
||||
#define sqlite3_keyword_check sqlite3_api->keyword_check
|
||||
#define sqlite3_str_new sqlite3_api->str_new
|
||||
#define sqlite3_str_finish sqlite3_api->str_finish
|
||||
#define sqlite3_str_appendf sqlite3_api->str_appendf
|
||||
#define sqlite3_str_vappendf sqlite3_api->str_vappendf
|
||||
#define sqlite3_str_append sqlite3_api->str_append
|
||||
#define sqlite3_str_appendall sqlite3_api->str_appendall
|
||||
#define sqlite3_str_appendchar sqlite3_api->str_appendchar
|
||||
#define sqlite3_str_reset sqlite3_api->str_reset
|
||||
#define sqlite3_str_errcode sqlite3_api->str_errcode
|
||||
#define sqlite3_str_length sqlite3_api->str_length
|
||||
#define sqlite3_str_value sqlite3_api->str_value
|
||||
/* Version 3.25.0 and later */
|
||||
#define sqlite3_create_window_function sqlite3_api->create_window_function
|
||||
/* Version 3.26.0 and later */
|
||||
#define sqlite3_normalized_sql sqlite3_api->normalized_sql
|
||||
/* Version 3.28.0 and later */
|
||||
#define sqlite3_stmt_isexplain sqlite3_api->stmt_isexplain
|
||||
#define sqlite3_value_frombind sqlite3_api->value_frombind
|
||||
/* Version 3.30.0 and later */
|
||||
#define sqlite3_drop_modules sqlite3_api->drop_modules
|
||||
/* Version 3.31.0 and later */
|
||||
#define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64
|
||||
#define sqlite3_uri_key sqlite3_api->uri_key
|
||||
#define sqlite3_filename_database sqlite3_api->filename_database
|
||||
#define sqlite3_filename_journal sqlite3_api->filename_journal
|
||||
#define sqlite3_filename_wal sqlite3_api->filename_wal
|
||||
/* Version 3.32.0 and later */
|
||||
#define sqlite3_create_filename sqlite3_api->create_filename
|
||||
#define sqlite3_free_filename sqlite3_api->free_filename
|
||||
#define sqlite3_database_file_object sqlite3_api->database_file_object
|
||||
/* Version 3.34.0 and later */
|
||||
#define sqlite3_txn_state sqlite3_api->txn_state
|
||||
/* Version 3.36.1 and later */
|
||||
#define sqlite3_changes64 sqlite3_api->changes64
|
||||
#define sqlite3_total_changes64 sqlite3_api->total_changes64
|
||||
/* Version 3.37.0 and later */
|
||||
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
|
||||
/* Version 3.38.0 and later */
|
||||
#define sqlite3_error_offset sqlite3_api->error_offset
|
||||
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
|
||||
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
|
||||
#define sqlite3_vtab_in sqlite3_api->vtab_in
|
||||
#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
|
||||
#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
|
||||
/* Version 3.39.0 and later */
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
#define sqlite3_deserialize sqlite3_api->deserialize
|
||||
#define sqlite3_serialize sqlite3_api->serialize
|
||||
#endif
|
||||
#define sqlite3_db_name sqlite3_api->db_name
|
||||
/* Version 3.40.0 and later */
|
||||
#define sqlite3_value_encoding sqlite3_api->value_encoding
|
||||
/* Version 3.41.0 and later */
|
||||
#define sqlite3_is_interrupted sqlite3_api->is_interrupted
|
||||
/* Version 3.43.0 and later */
|
||||
#define sqlite3_stmt_explain sqlite3_api->stmt_explain
|
||||
/* Version 3.44.0 and later */
|
||||
#define sqlite3_get_clientdata sqlite3_api->get_clientdata
|
||||
#define sqlite3_set_clientdata sqlite3_api->set_clientdata
|
||||
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
/* This case when the file really is being compiled as a loadable
|
||||
** extension */
|
||||
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
|
||||
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
|
||||
# define SQLITE_EXTENSION_INIT3 \
|
||||
extern const sqlite3_api_routines *sqlite3_api;
|
||||
#else
|
||||
/* This case when the file is being statically linked into the
|
||||
** application */
|
||||
# define SQLITE_EXTENSION_INIT1 /*no-op*/
|
||||
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
|
||||
# define SQLITE_EXTENSION_INIT3 /*no-op*/
|
||||
#endif
|
||||
|
||||
#endif /* SQLITE3EXT_H */
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
#include "HumanReadableBytes.h"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
|
||||
struct scale {
|
||||
int64_t scale;
|
||||
const char* prefix;
|
||||
};
|
||||
|
||||
void fmt(std::ostringstream &o, double d)
|
||||
{
|
||||
;
|
||||
if (d < 10.0)
|
||||
{
|
||||
o << fixed << setprecision(2) << d;
|
||||
//return std::format("{:.3g}", d);
|
||||
}
|
||||
else if (d < 100.0)
|
||||
{
|
||||
o << fixed << setprecision(1) << d;
|
||||
//return std::format("{:.3g}", d);
|
||||
}
|
||||
else
|
||||
{
|
||||
o << fixed << setprecision(0) << d;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string HumanReadableBytes(uint64_t bytes)
|
||||
{
|
||||
static scale scales[] = {
|
||||
{ 1024ll * 1024 * 1024 * 1024, "Ti" },
|
||||
{ 1024ll * 1024 * 1024, "Gi" },
|
||||
{ 1024ll * 1024, "Mi" },
|
||||
{ 1024ll, "ki" },
|
||||
};
|
||||
|
||||
std::ostringstream out;
|
||||
for (unsigned int i = 0; i < (sizeof(scales) / sizeof(scale)); ++i)
|
||||
{
|
||||
if (bytes >= scales[i].scale)
|
||||
{
|
||||
fmt(out, bytes / double(scales[i].scale));
|
||||
out << " " << scales[i].prefix << "B";
|
||||
return out.str();
|
||||
}
|
||||
}
|
||||
out << bytes << " B";
|
||||
return out.str();
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string HumanReadableBytes(uint64_t bytes);
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#include "PostgresqlUrlParser.h"
|
||||
|
||||
#include <ConnectionConfig.h>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
|
||||
bool TryParsePostgresqlUrl(const QString &urlString, ConnectionConfig &out)
|
||||
{
|
||||
const char* shortPrefix = "postgres";
|
||||
const char* longPrefix = "postgresql";
|
||||
|
||||
auto url = QUrl(urlString, QUrl::StrictMode);
|
||||
if (url.scheme() != shortPrefix && url.scheme() != longPrefix)
|
||||
return false;
|
||||
|
||||
out.setUser(url.userName());
|
||||
out.setPassword(url.password());
|
||||
out.setHost(url.host());
|
||||
out.setDbname(url.fileName());
|
||||
out.setPort(url.port(5432));
|
||||
|
||||
QUrlQuery query(url.query());
|
||||
for (auto && param : query.queryItems())
|
||||
{
|
||||
if (param.first == "ssl" && param.second == "true") {
|
||||
out.setSslMode(SslMode::require);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.setParameter(param.first, param.second);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
class ConnectionConfig;
|
||||
|
||||
bool TryParsePostgresqlUrl(const QString &urlString, ConnectionConfig &out);
|
||||
|
||||
// class PostgresqlUrlParser
|
||||
// {
|
||||
// public:
|
||||
// PostgresqlUrlParser();
|
||||
|
||||
//};
|
||||
|
|
@ -19,11 +19,6 @@ namespace Pgsql {
|
|||
return row.get(++col);
|
||||
}
|
||||
|
||||
void skip(int n = 1)
|
||||
{
|
||||
col += n;
|
||||
}
|
||||
|
||||
template <typename E, typename I>
|
||||
Col& getAsArray(I insert_iter, NullHandling nullhandling = NullHandling::Throw)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -109,11 +109,6 @@ Result Connection::queryParam(const char * command, const Params ¶ms)
|
|||
return Result(result);
|
||||
}
|
||||
|
||||
Result Connection::queryParam(const std::string &command, const Params ¶ms)
|
||||
{
|
||||
return queryParam(command.c_str(), params);
|
||||
}
|
||||
|
||||
Result Connection::queryParam(const QString &command, const Params ¶ms)
|
||||
{
|
||||
return queryParam(command.toUtf8().data(), params);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@
|
|||
#include <libpq-fe.h>
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
#include <codecvt>
|
||||
#include <memory>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "Pgsql_Canceller.h"
|
||||
#include "Pgsql_Result.h"
|
||||
|
||||
|
|
@ -79,7 +83,6 @@ namespace Pgsql {
|
|||
}
|
||||
|
||||
Result queryParam(const char * command, const Params ¶ms);
|
||||
Result queryParam(const std::string &command, const Params ¶ms);
|
||||
Result queryParam(const QString &command, const Params ¶ms);
|
||||
|
||||
void sendQuery(const char * query);
|
||||
|
|
|
|||
|
|
@ -84,12 +84,6 @@ Param Params::add(const char *data, Oid oid)
|
|||
return addText(p, oid);
|
||||
}
|
||||
|
||||
Param Params::add(int v, Oid oid)
|
||||
{
|
||||
std::string s = std::format("{:d}", v);
|
||||
return add(s.c_str(), oid);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void concatContainers(T &d, const U& s)
|
||||
{
|
||||
|
|
@ -116,7 +110,7 @@ void Params::clear()
|
|||
void Params::appendValues(const t_paramValues &r)
|
||||
{
|
||||
const int n = static_cast<int>(r.size());
|
||||
const size_t ofs = m_paramValues.size();
|
||||
const int ofs = m_paramValues.size();
|
||||
m_paramValues.reserve(ofs + n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (r[i]) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ namespace Pgsql {
|
|||
|
||||
Param add(const QString &s, Oid oid=varchar_oid);
|
||||
Param add(const char *data, Oid oid=varchar_oid);
|
||||
Param add(int v, Oid oid=int4_oid);
|
||||
Param add(std::optional<std::string> s, Oid oid=varchar_oid)
|
||||
{
|
||||
return add(s ? s->c_str() : nullptr, oid);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ Value::operator int64_t() const
|
|||
if (m_val == nullptr)
|
||||
return 0LL;
|
||||
|
||||
const size_t len = std::strlen(m_val);
|
||||
const int len = std::strlen(m_val);
|
||||
if (len > 0) {
|
||||
char *endptr = nullptr;
|
||||
int64_t result = std::strtoll(m_val, &endptr, 10);
|
||||
|
|
@ -136,6 +136,7 @@ Value::operator int64_t() const
|
|||
return result;
|
||||
}
|
||||
throw std::runtime_error("Value conversion to int64_t failed");
|
||||
// return std::strtoll(m_val, nullptr, 10);
|
||||
}
|
||||
|
||||
Value::operator bool() const
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
CONFIG += staticlib
|
||||
QT += core
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets sql
|
||||
|
||||
TARGET = pgsql
|
||||
TEMPLATE = lib
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fix the SQL to drop a partitioned table should be the same as for a normal table.
|
||||
It should NOT include the word PARTITIONED.
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Limited support generating SQL for partitioned tables. It should be able to
|
||||
generate SQL for list, hash and range partitioning involving columns only.
|
||||
issues:
|
||||
- |
|
||||
It can yet generate correct SQL for a table partitioned by an expression.
|
||||
|
|
@ -18,8 +18,6 @@ SOURCES += main.cpp \
|
|||
tst_ConvertLangToSqlString.cpp \
|
||||
tst_ConvertToMultiLineCString.cpp \
|
||||
tst_ExplainJsonParser.cpp \
|
||||
tst_HumanReadableBytes.cpp \
|
||||
tst_TryParsePostgresqlUrl.cpp \
|
||||
tst_escapeConnectionStringValue.cpp \
|
||||
tst_expected.cpp \
|
||||
tst_SqlLexer.cpp \
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
#include "utils/HumanReadableBytes.h"
|
||||
|
||||
TEST(HumanReadableBytesTest, bytes7)
|
||||
{
|
||||
auto s = HumanReadableBytes(7);
|
||||
ASSERT_EQ("7 B", s);
|
||||
}
|
||||
|
||||
TEST(HumanReadableBytesTest, bytes1023)
|
||||
{
|
||||
auto s = HumanReadableBytes(1023);
|
||||
ASSERT_EQ("1023 B", s);
|
||||
}
|
||||
|
||||
TEST(HumanReadableBytesTest, bytes1k)
|
||||
{
|
||||
auto s = HumanReadableBytes(1024);
|
||||
ASSERT_EQ("1.00 kiB", s);
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ using namespace testing;
|
|||
|
||||
|
||||
#include <botan/pwdhash.h>
|
||||
#include <botan/scrypt.h>
|
||||
|
||||
//TEST(Botan, recreate)
|
||||
//{
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include <ConnectionConfig.h>
|
||||
#include "utils/PostgresqlUrlParser.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
TEST(TryParsePostgresqlUrl, emptyInput)
|
||||
{
|
||||
QString urlString = "postgresql://user:secret@localhost:5433/otherdb?connect_timeout=10&application_name=myapp";
|
||||
ConnectionConfig config;
|
||||
bool result = TryParsePostgresqlUrl(urlString, config);
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_THAT(config.user(), Eq("user"));
|
||||
ASSERT_THAT(config.password(), Eq("secret"));
|
||||
ASSERT_THAT(config.host(), Eq("localhost"));
|
||||
ASSERT_THAT(config.dbname(), Eq("otherdb"));
|
||||
ASSERT_THAT(config.port(), Eq(5433));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue