본문으로 건너뛰기
로딩중...
검색중...
일치하는것 없음
SqlConsoleController.h
1#pragma once
2#include "gdkqt/QtGdkExport.h"
3#include "sql/SqlTypes.h"
4#include <QObject>
5#include <atomic>
6#include <memory>
7#include <mutex>
8#include "gdk_dll/sql/glsSqlConsole.h"
9namespace GDK { class glsSqlExecutor; }
10namespace GdkQt {
11class SqlConsoleWorker;
16 QString Sql;
19 bool ReturnsRows = true;
22 bool AllowWrites = false;
24 int MaxRows = 1000;
25};
26
34 std::atomic_bool Cancelled{false};
36 std::atomic_int Phase{0};
38 mutable std::mutex Gate;
40 std::shared_ptr<GDK::glsSqlConsoleRun> Run;
43 void Bind(std::shared_ptr<GDK::glsSqlConsoleRun> run) { std::lock_guard lock(Gate);Run=std::move(run);if(Cancelled||Phase==2)Run->RequestCancel(); }
45 void Unbind() { std::lock_guard lock(Gate);Run.reset(); }
48 bool CanCancel() const { std::lock_guard lock(Gate);return Run?Run->CanCancel():Phase==0; }
53 void Cancel() { std::lock_guard lock(Gate);if(Run){if(!Run->CanCancel())return;Run->RequestCancel();}int expected=0;if(Phase.compare_exchange_strong(expected,2))Cancelled=true; }
54};
55
61class QT_GDK_API SqlConsoleController final : public QObject {
62 Q_OBJECT
63public:
68 SqlConsoleController(QString kind,QString uri,QObject* parent=nullptr);
77 static bool SupportsProvider(const QString& kind);
87 bool ExecuteAsync(const SqlConsoleRequest&,QString* error=nullptr);
92 void Cancel();
95 bool IsRunning() const { return bool(m_run); }
98 bool CanCancel() const { return m_run && m_run->CanCancel(); }
99 // Worker entry shared by the public controller and the existing rich SQL UI.
110 static SqlRunResult ExecuteSession(GDK::glsSqlConsoleSession*,const SqlConsoleRequest&,const std::shared_ptr<SqlCancellationState>&);
121 static SqlRunResult Execute(GDK::glsSqlExecutor*,const SqlConsoleRequest&,
122 const std::shared_ptr<SqlCancellationState>&);
123signals:
131private:
132 QString m_kind,m_uri;
133 SqlConsoleWorker* m_worker=nullptr;
134 std::shared_ptr<SqlCancellationState> m_run;
135};
136}
bool ExecuteAsync(const SqlConsoleRequest &, QString *error=nullptr)
SQL 실행을 작업 스레드에 맡기고 바로 돌아옵니다.
static bool SupportsProvider(const QString &kind)
공급자 종류가 SQL 콘솔을 지원하는지 알려 줍니다.
~SqlConsoleController() override
진행 중인 실행에 취소를 요청하고 작업 스레드를 끝냅니다.
void Completed(const GdkQt::SqlRunResult &)
ExecuteAsync로 맡긴 실행이 끝났을 때 컨트롤러의 스레드에서 발생합니다.
bool IsRunning() const
실행이 진행 중인지 알려 줍니다.
정의 SqlConsoleController.h:95
SqlConsoleController(QString kind, QString uri, QObject *parent=nullptr)
컨트롤러를 만들고 작업 스레드를 시작합니다.
static SqlRunResult ExecuteSession(GDK::glsSqlConsoleSession *, const SqlConsoleRequest &, const std::shared_ptr< SqlCancellationState > &)
열린 SQL 콘솔 세션에서 요청을 동기로 실행합니다.
bool CanCancel() const
진행 중인 실행을 지금 취소할 수 있는지 알려 줍니다.
정의 SqlConsoleController.h:98
static SqlRunResult Execute(GDK::glsSqlExecutor *, const SqlConsoleRequest &, const std::shared_ptr< SqlCancellationState > &)
SQL 실행기에서 요청을 동기로 실행합니다.
void Cancel()
진행 중인 실행에 취소를 요청합니다.
glsGdkQt의 공개 형식과 함수가 있는 네임스페이스입니다.
정의 AppSettings.h:15
SQL 실행 한 건의 취소 상태입니다.
정의 SqlConsoleController.h:32
std::atomic_bool Cancelled
취소가 요청되었으면 true입니다.
정의 SqlConsoleController.h:34
void Unbind()
묶은 실행 객체를 풉니다.
정의 SqlConsoleController.h:45
void Cancel()
취소를 요청합니다.
정의 SqlConsoleController.h:53
std::mutex Gate
Run과 상태 전이를 보호하는 뮤텍스입니다.
정의 SqlConsoleController.h:38
std::atomic_int Phase
실행 단계입니다. 0은 취소 가능, 1은 결과 게시 시작, 2는 취소가 확정된 상태입니다.
정의 SqlConsoleController.h:36
bool CanCancel() const
지금 취소할 수 있는지 알려 줍니다.
정의 SqlConsoleController.h:48
void Bind(std::shared_ptr< GDK::glsSqlConsoleRun > run)
네이티브 실행 객체를 묶습니다.
정의 SqlConsoleController.h:43
std::shared_ptr< GDK::glsSqlConsoleRun > Run
실행 중인 네이티브 실행 객체입니다. 묶여 있지 않으면 null입니다.
정의 SqlConsoleController.h:40
SQL 실행 한 건의 요청입니다.
정의 SqlConsoleController.h:14
QString Sql
실행할 SQL 텍스트입니다. 공급자의 방언을 따르며, 비어 있거나 공백뿐이면 거부됩니다.
정의 SqlConsoleController.h:16
int MaxRows
담을 최대 행 수입니다. 1부터 1000까지이며 기본값은 1000입니다.
정의 SqlConsoleController.h:24
bool ReturnsRows
true이면 쿼리로 실행해 행을 담고, false이면 행 없는 문장으로 실행해 영향받은 행 수를 보고합니다.
정의 SqlConsoleController.h:19
bool AllowWrites
true이면 쓰기 권한을 얻어 실행합니다.
정의 SqlConsoleController.h:22
SQL 실행 한 건의 결과입니다.
정의 SqlTypes.h:50