// Select -- Get data from table or view
- Get data from table or view
// Select -- Get data from table or view
func (me *DBext) Select(id uint64, secured bool, rowPattern interface{}, name string, cacheName string, offset uint, count uint, params ...interface{}) (result []interface{}, code int, err error) {
	t0 := misc.NowUnixNano()
	defer func() {
		misc.LogProcessingTime(me.db.logFacility.Name(), "", id, `db.select "`+name+`(`+cacheName+`)"`, "", t0)
	}()
	if cacheName == "" {
		cacheName = name
	}
	rs, err := me.OpenRecordsetExtended(name, secured, offset, count, params...)
	if err != nil {
		return nil, http.StatusInternalServerError, err
	}
	defer rs.Close()
	var df *resultDef
	if rowPattern != nil {
		df = &resultDef{
			row: rowPattern,
		}
		df.fields, err = fieldsFromPattern(rowPattern)
	} else {
		exists := false
		resultDefCacheMutex.RLock()
		df, exists = resultDefCache[cacheName]
		resultDefCacheMutex.RUnlock()
		if !exists {
			df, err = makeRowPattern(rs)
			df.mutex = new(sync.Mutex)
			resultDefCacheMutex.Lock()
			resultDefCache[cacheName] = df
			resultDefCacheMutex.Unlock()
		}
	}
	if err != nil {
		return nil, http.StatusBadRequest, err
	}
	answer := []interface{}{}
	if df.mutex != nil {
		df.mutex.Lock()
	}
	for rs.Next() {
		err = rs.Scan(df.fields...)
		if err != nil {
			return nil, http.StatusInternalServerError, err
		}
		row := reflect.Indirect(reflect.ValueOf(df.row)).Interface()
		answer = append(answer, row)
	}
	if df.mutex != nil {
		df.mutex.Unlock()
	}
	return answer, http.StatusOK, nil
}
func ( me * DBext ) Select ( id uint64 , secured bool , rowPattern interface { } , name string , cacheName string , offset uint , count uint , params ... interface { } ) ( result [ ] interface { } , code int , err error ) { t0 := misc . NowUnixNano ( ) defer func ( ) { misc . LogProcessingTime ( me . db . logFacility . Name ( ) , " " , id , `db.select "` + name + `(` + cacheName + `)"` , " " , t0 ) } ( ) if cacheName == " " { cacheName = name } rs , err := me . OpenRecordsetExtended ( name , secured , offset , count , params ... ) if err != nil { return nil , http . StatusInternalServerError , err } defer rs . Close ( ) var df * resultDef if rowPattern != nil { df = & resultDef { row : rowPattern , } df . fields , err = fieldsFromPattern ( rowPattern ) } else { exists := false resultDefCacheMutex . RLock ( ) df , exists = resultDefCache [ cacheName ] resultDefCacheMutex . RUnlock ( ) if ! exists { df , err = makeRowPattern ( rs ) df . mutex = new ( sync . Mutex ) resultDefCacheMutex . Lock ( ) resultDefCache [ cacheName ] = df resultDefCacheMutex . Unlock ( ) } } if err != nil { return nil , http . StatusBadRequest , err } answer := [ ] interface { } { } if df . mutex != nil { df . mutex . Lock ( ) } for rs . Next ( ) { err = rs . Scan ( df . fields ... ) if err != nil { return nil , http . StatusInternalServerError , err } row := reflect . Indirect ( reflect . ValueOf ( df . row ) ) . Interface ( ) answer = append ( answer , row ) } if df . mutex != nil { df . mutex . Unlock ( ) } return answer , http . StatusOK , nil }
Get data from table or view
Get data from table or view
// Make a query // Get result definition // Prepare a list of fields from the pattern // Make row Pattern and fields // Save to cache for future use // Read data and prepare answer