Esempio n. 1
0
func getData(db *core.DB, req *sqlDataRequest) (interface{}, error) {
	queries := strings.Split(req.Query, ";")

	data := dataStruct{}
	data.Results = make([]resultsStruct, 1)
	data.Results[0].Series = make([]seriesStruct, 0)

	for i := range queries {
		if queries[i] == "" {
			continue
		}

		rows, err := db.Query(queries[i])
		if err != nil {
			return nil, err
		}
		defer rows.Close()

		name := fmt.Sprintf("table_%d", i+1)
		series, err := arrangeResult(rows, name)
		if err != nil {
			return nil, err
		}
		data.Results[0].Series = append(data.Results[0].Series, series.(seriesStruct))
	}

	return data, nil
}
Esempio n. 2
0
func query2(db *core.DB, sqlStr string, params ...interface{}) (resultsSlice []map[string]string, err error) {
	s, err := db.Prepare(sqlStr)
	if err != nil {
		return nil, err
	}
	defer s.Close()
	rows, err := s.Query(params...)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	return rows2Strings(rows)
}