Skip to content

Commit

Permalink
fix null
Browse files Browse the repository at this point in the history
  • Loading branch information
mazrean committed Dec 3, 2024
1 parent d699b93 commit ef1103a
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions db/server.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package isudb

import (
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -111,9 +111,9 @@ func queryListHandler(w http.ResponseWriter, r *http.Request) {
type ExplainResult struct {
Table string `json:"table"`
PossibleKeys []string `json:"possible_keys"`
Key string `json:"key"`
Key string `json:"key,omitempty"`
Rows int `json:"rows"`
Filtered int `json:"filtered"`
Filtered float64 `json:"filtered"`
}

func queryExplainHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -152,7 +152,6 @@ func queryExplainHandler(w http.ResponseWriter, r *http.Request) {
explainQuery := "EXPLAIN " + query.Example.query

args := constructArgs(query.Example.args, query.Example.namedArgs)
log.Printf("query: %s, queryArgs: %v, args: %v, namedArgs: %v", explainQuery, args, query.Example.args, query.Example.namedArgs)
rows, err := db.Query(explainQuery, args...)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -161,18 +160,18 @@ func queryExplainHandler(w http.ResponseWriter, r *http.Request) {
defer rows.Close()

type explainRow struct {
ID int `json:"id"`
SelectType string `json:"select_type"`
Table string `json:"table"`
Partitions string `json:"partitions"`
Type string `json:"type"`
PossibleKeys string `json:"possible_keys"`
Key string `json:"key"`
KeyLen int `json:"key_len"`
Ref string `json:"ref"`
Rows int `json:"rows"`
Filtered int `json:"filtered"`
Extra string `json:"Extra"`
ID sql.NullInt64 `json:"id"`
SelectType string `json:"select_type"`
Table string `json:"table"`
Partitions sql.NullString `json:"partitions"`
Type string `json:"type"`
PossibleKeys sql.NullString `json:"possible_keys"`
Key sql.NullString `json:"key"`
KeyLen sql.NullInt64 `json:"key_len"`
Ref sql.NullString `json:"ref"`
Rows int `json:"rows"`
Filtered float64 `json:"filtered"`
Extra sql.NullString `json:"Extra"`
}

for rows.Next() {
Expand All @@ -183,8 +182,8 @@ func queryExplainHandler(w http.ResponseWriter, r *http.Request) {
}
explainResults = append(explainResults, ExplainResult{
Table: row.Table,
PossibleKeys: strings.Split(row.PossibleKeys, ","),
Key: row.Key,
PossibleKeys: strings.Split(row.PossibleKeys.String, ","),
Key: row.Key.String,
Rows: row.Rows,
Filtered: row.Filtered,
})
Expand Down

0 comments on commit ef1103a

Please sign in to comment.