WIP SQL console

This commit is contained in:
Francesco
2023-10-22 16:25:05 +02:00
parent ee58fa0d77
commit e52cc2877f
2 changed files with 10 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
package tech.ailef.dbadmin.external.controller;
import java.sql.ResultSetMetaData;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
@@ -596,6 +597,8 @@ public class DefaultDbAdminController {
public String consoleRun(Model model, @RequestParam(required = false) String query,
@RequestParam(required = false) String queryTitle,
@PathVariable String queryId) {
long startTime = System.currentTimeMillis();
if (!properties.isSqlConsoleEnabled()) {
throw new DbAdminException("SQL console not enabled");
}
@@ -644,7 +647,9 @@ public class DefaultDbAdminController {
model.addAttribute("error", e.getMessage());
}
}
double elapsedTime = (System.currentTimeMillis() - startTime) / 1000.0;
model.addAttribute("elapsedTime", new DecimalFormat("0.0#").format(elapsedTime));
return "console";
}

View File

@@ -34,7 +34,7 @@
<input type="text" class="form-control mb-3"
name="queryTitle" th:value="${activeQuery.getTitle()}">
<span class="text-muted fw-bold mb-1 d-inline-block">SQL</span>
<textarea class="form-control" rows="6" name="query"
<textarea class="form-control font-monospace" rows="6" name="query"
th:text="${activeQuery.getSql()}"></textarea>
<input class="ui-btn btn btn-primary mt-3" type="submit" value="Run">
<a href="#" class="ms-4 ui-btn btn btn-danger mt-3" id="console-delete-btn">Delete</a>
@@ -48,6 +48,9 @@
<div th:if="${error == null && activeQuery.getSql() != null}">
<div class="separator mt-3 mb-3"></div>
<span class="text-muted mb-1 d-inline-block">
[[ ${results.size()} ]] results in [[ ${elapsedTime} ]] seconds
</span>
<div th:replace="~{fragments/generic_table :: table(results=${results})}"></div>
</div>
<div th:if="${error != null}">