Blame view

select_config.go 1.34 KB
8bc396eb9   Marko Tikvić   reverted changes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  package webutility
  
  import "gopkg.in/rana/ora.v4"
  
  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"`
  }
  
  // GetSelectConfig returns select configuration slice for the given object type.
  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`
  
  	stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S, ora.S, ora.S)
  	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
  }