Encode sql query to base64 for CSV export, GH-95
This commit is contained in:
parent
2a4edaf08f
commit
c02d15ec34
@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -174,8 +175,12 @@ func GetTableIndexes(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleQuery(query string, c *gin.Context) {
|
func HandleQuery(query string, c *gin.Context) {
|
||||||
result, err := DbClient.Query(query)
|
rawQuery, err := base64.StdEncoding.DecodeString(query)
|
||||||
|
if err == nil {
|
||||||
|
query = string(rawQuery)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := DbClient.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, NewError(err))
|
c.JSON(400, NewError(err))
|
||||||
return
|
return
|
||||||
|
File diff suppressed because one or more lines are too long
@ -24,6 +24,10 @@ function getTableIndexes(table, cb) { apiCall("get", "/tables/" + table + "/i
|
|||||||
function getHistory(cb) { apiCall("get", "/history", {}, cb); }
|
function getHistory(cb) { apiCall("get", "/history", {}, cb); }
|
||||||
function getBookmarks(cb) { apiCall("get", "/bookmarks", {}, cb); }
|
function getBookmarks(cb) { apiCall("get", "/bookmarks", {}, cb); }
|
||||||
|
|
||||||
|
function encodeQuery(query) {
|
||||||
|
return window.btoa(query);
|
||||||
|
}
|
||||||
|
|
||||||
function executeQuery(query, cb) {
|
function executeQuery(query, cb) {
|
||||||
apiCall("post", "/query", { query: query }, cb);
|
apiCall("post", "/query", { query: query }, cb);
|
||||||
}
|
}
|
||||||
@ -344,10 +348,7 @@ function exportToCSV() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace line breaks with spaces and properly encode query
|
var url = "http://" + window.location.host + "/api/query?format=csv&query=" + encodeQuery(query);
|
||||||
query = window.encodeURI(query.replace(/\n/g, " "));
|
|
||||||
|
|
||||||
var url = "http://" + window.location.host + "/api/query?format=csv&query=" + query;
|
|
||||||
var win = window.open(url, '_blank');
|
var win = window.open(url, '_blank');
|
||||||
|
|
||||||
setCurrentTab("table_query");
|
setCurrentTab("table_query");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user