Blame view

select_config.go 1.31 KB
ea858b8a7   Marko Tikvić   refactoring
1
  package webutility
39765a430   Marko Tikvić   added list and se...
2
3
4
5
6
7
8
9
10
11
12
13
14
  
  import (
  	"gopkg.in/rana/ora.v3"
  )
  
  type SelectConfig struct {
  	ListObjType string `json:"listObjectType"`
  	ObjType     string `json:"objectType"`
  	Type        string `json:"type"`
  	IdField     string `json:"idField"`
  	LabelField  string `json:"labelField"`
  	ValueField  string `json:"valueField"`
  }
e1fbb41f9   Marko Tikvić   added comments
15
  // GetSelectConfig returns select configuration slice for the given object type.
39765a430   Marko Tikvić   added list and se...
16
17
18
19
20
21
22
23
24
25
  func GetSelectConfig(db *ora.Ses, otype string) ([]SelectConfig, error) {
  	resp := make([]SelectConfig, 0)
  	var err error
  	var stmt *ora.Stmt
  	query := `SELECT a.LIST_OBJECT_TYPE, a.OBJECT_TYPE, a.ID_FIELD,
  		a.LABEL_FIELD, a.TYPE, b.FIELD
  		FROM LIST_SELECT_CONFIG a, LIST_VALUE_FIELD b
  		WHERE a.LIST_OBJECT_TYPE` + otype + `
  		AND b.LIST_TYPE = a.LIST_OBJECT_TYPE
  		AND b.OBJECT_TYPE = a.OBJECT_TYPE`
33fd58161   markotikvic   minor changes, sh...
26
  	stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S, ora.S, ora.S)
39765a430   Marko Tikvić   added list and se...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  	defer stmt.Close()
  	if err != nil {
  		return nil, err
  	}
  
  	rset, err := stmt.Qry()
  	if err != nil {
  		return nil, err
  	}
  	for rset.Next() {
  		resp = append(resp, SelectConfig{
  			ListObjType: rset.Row[0].(string),
  			ObjType: rset.Row[1].(string),
  			IdField: rset.Row[2].(string),
  			LabelField: rset.Row[3].(string),
  			Type: rset.Row[4].(string),
  			ValueField: rset.Row[5].(string),
  		})
  	}
  	if rset.Err != nil {
  		return nil, rset.Err
  	}
  
  	return resp, nil
39765a430   Marko Tikvić   added list and se...
51
  }