refactor(cpp/core): sql_workbench usa sql_parse
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "core/sql_workbench.h"
|
#include "core/sql_workbench.h"
|
||||||
|
|
||||||
|
#include "core/sql_parse.h"
|
||||||
#include "core/text_editor.h"
|
#include "core/text_editor.h"
|
||||||
#include "core/tokens.h"
|
#include "core/tokens.h"
|
||||||
#include "core/button.h"
|
#include "core/button.h"
|
||||||
@@ -25,24 +26,19 @@ namespace fn {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string ltrim(const std::string& s) {
|
// Clasifica el primer statement con sql_parse pure. Si el input no contiene
|
||||||
size_t i = 0;
|
// statements (todo whitespace/comentarios), devuelve Unknown.
|
||||||
while (i < s.size() && std::isspace(static_cast<unsigned char>(s[i]))) ++i;
|
fn_ui::SqlStmtKind first_stmt_kind(const std::string& sql) {
|
||||||
return s.substr(i);
|
auto stmts = fn_ui::sql_parse(sql);
|
||||||
}
|
if (stmts.empty()) return fn_ui::SqlStmtKind::Unknown;
|
||||||
|
return stmts.front().kind;
|
||||||
std::string upper_first_token(const std::string& sql) {
|
|
||||||
std::string t = ltrim(sql);
|
|
||||||
size_t end = 0;
|
|
||||||
while (end < t.size() && !std::isspace(static_cast<unsigned char>(t[end]))) ++end;
|
|
||||||
std::string tok = t.substr(0, end);
|
|
||||||
for (auto& c : tok) c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
|
||||||
return tok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_readonly_stmt(const std::string& sql) {
|
bool is_readonly_stmt(const std::string& sql) {
|
||||||
const std::string head = upper_first_token(sql);
|
using K = fn_ui::SqlStmtKind;
|
||||||
return head == "SELECT" || head == "PRAGMA" || head == "EXPLAIN" || head == "WITH";
|
K k = first_stmt_kind(sql);
|
||||||
|
// sql_parse clasifica WITH como Select; Pragma y Explain son readonly.
|
||||||
|
return k == K::Select || k == K::Pragma || k == K::Explain;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorState* editor_of(SqlWorkbenchState& state) {
|
TextEditorState* editor_of(SqlWorkbenchState& state) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ purity: impure
|
|||||||
signature: "void fn::sql_workbench(const char* id, sqlite3* db, fn::SqlWorkbenchState& state, ImVec2 size); bool fn::sql_workbench_run_query(sqlite3*, const char*, fn::SqlWorkbenchState&); void fn::sql_workbench_load_schema(sqlite3*, fn::SqlWorkbenchState&); void fn::sql_workbench_destroy(fn::SqlWorkbenchState&)"
|
signature: "void fn::sql_workbench(const char* id, sqlite3* db, fn::SqlWorkbenchState& state, ImVec2 size); bool fn::sql_workbench_run_query(sqlite3*, const char*, fn::SqlWorkbenchState&); void fn::sql_workbench_load_schema(sqlite3*, fn::SqlWorkbenchState&); void fn::sql_workbench_destroy(fn::SqlWorkbenchState&)"
|
||||||
description: "Workbench SQL embebido en ImGui: editor con highlighting (text_editor + CodeLang::SQL), tabla de resultados (table_view), sidebar de schema (sqlite_master) e historial. Ejecuta queries contra una sqlite3* del caller (no abre/cierra la DB)."
|
description: "Workbench SQL embebido en ImGui: editor con highlighting (text_editor + CodeLang::SQL), tabla de resultados (table_view), sidebar de schema (sqlite_master) e historial. Ejecuta queries contra una sqlite3* del caller (no abre/cierra la DB)."
|
||||||
tags: [imgui, sql, sqlite, editor, table, dashboard, registry, debug]
|
tags: [imgui, sql, sqlite, editor, table, dashboard, registry, debug]
|
||||||
uses_functions: ["button_cpp_core", "table_view_cpp_viz", "text_editor_cpp_core", "tokens_cpp_core"]
|
uses_functions: ["button_cpp_core", "sql_parse_cpp_core", "table_view_cpp_viz", "text_editor_cpp_core", "tokens_cpp_core"]
|
||||||
uses_types: []
|
uses_types: []
|
||||||
returns: []
|
returns: []
|
||||||
returns_optional: false
|
returns_optional: false
|
||||||
|
|||||||
Reference in New Issue
Block a user