mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 03:42:08 +08:00
Datasource: Fix missing raw SQL query in Query Inspector when query returns zero rows (#67844)
* baldm0mma/issue5799/ add empty frame with all meta data * baldm0mma/issue5799/ add null test * write an integration test around query results with empty rows * baldm0mma/issue5799/ add tests to mssql and postgres * remove use of apparently reserved keyword in mysql8 * baldm0mma/issue5799 * baldm0mma/issue5799/ update tests * baldm0mma/issue5799/ update test structs * baldm0mma/issue5799/ update annotation --------- Co-authored-by: Michael Mandrus <michael.mandrus@grafana.com>
This commit is contained in:
@ -312,9 +312,13 @@ func (e *DataSourceHandler) executeQuery(query backend.DataQuery, wg *sync.WaitG
|
||||
|
||||
frame.Meta.ExecutedQueryString = interpolatedQuery
|
||||
|
||||
// If no rows were returned, no point checking anything else.
|
||||
// If no rows were returned, clear any previously set `Fields` with a single empty `data.Field` slice.
|
||||
// Then assign `queryResult.dataResponse.Frames` the current single frame with that single empty Field.
|
||||
// This assures 1) our visualization doesn't display unwanted empty fields, and also that 2)
|
||||
// additionally-needed frame data stays intact and is correctly passed to our visulization.
|
||||
if frame.Rows() == 0 {
|
||||
queryResult.dataResponse.Frames = data.Frames{}
|
||||
frame.Fields = []*data.Field{}
|
||||
queryResult.dataResponse.Frames = data.Frames{frame}
|
||||
ch <- queryResult
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user