mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-27 20:44:13 +02:00
45aec7735b
Since #983, projectDataBase::newQuery() checked a query with sqlite3_prepare_v2() and sqlite3_stmt_readonly() on the handle of the QSQLITE driver. Those calls go to the libsqlite3 QElectroTech links. The QSQLITE plugin of the Qt online installer does not use that library: it carries its own copy of SQLite, so the handle belongs to another library and the call crashes. #1021 then put newQuery() on every element selection, which is where #1045 hits it. The check now runs the query with PRAGMA query_only set, through the driver. SQLite refuses a write itself, before touching a row, so the CTE prefix #983 closed ("WITH x AS (SELECT 1) DELETE FROM element") stays closed. A refused or failed query comes back empty, because several callers call exec() again on what newQuery() returns, after query_only is off. QElectroTech no longer calls the SQLite C API anywhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef SQLREADONLY_H
|
|
#define SQLREADONLY_H
|
|
|
|
#include <QSqlDatabase>
|
|
#include <QSqlQuery>
|
|
#include <QString>
|
|
|
|
/**
|
|
Running a piece of SQL only if it reads.
|
|
|
|
Deliberately its own translation unit, depending on nothing but Qt SQL:
|
|
it is the enforcement point for every query QElectroTech runs against a
|
|
project database, including queries that arrive from outside the
|
|
application (a .qet file's saved report/table query), so it is worth
|
|
being able to test it in isolation -- see
|
|
tests/qttest/tst_sqlreadonly.cpp, which links this file and nothing
|
|
else of QElectroTech.
|
|
*/
|
|
namespace QETSql {
|
|
|
|
QSqlQuery execReadOnly(const QSqlDatabase &db,
|
|
const QString &query,
|
|
QString *error = nullptr);
|
|
}
|
|
|
|
#endif // SQLREADONLY_H
|