From 1d0f615536520bf32f1acd061f7acf4a367e9bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Thu, 25 May 2017 12:24:07 +0200 Subject: [PATCH] can't fetch clob --- auth_utility.go | 2 +- json_utility.go | 47 +++++++++++++++++++++-------------------------- list_config.go | 49 +++++++++++++++++++++++++------------------------ select_config.go | 9 ++++----- 4 files changed, 51 insertions(+), 56 deletions(-) diff --git a/auth_utility.go b/auth_utility.go index 59ccdc2..9ea6fca 100644 --- a/auth_utility.go +++ b/auth_utility.go @@ -30,7 +30,7 @@ type TokenClaims struct { jwt.StandardClaims } -// CredentialsStruct is an instace of username/password values. +// CredentialsStruct is an instace of username/password values. type CredentialsStruct struct { Username string `json:"username"` Password string `json:"password"` diff --git a/json_utility.go b/json_utility.go index b4b53b8..cb09fd5 100644 --- a/json_utility.go +++ b/json_utility.go @@ -1,13 +1,16 @@ package webutility import ( + "fmt" "net/http" "encoding/json" "errors" - "gopkg.in/rana/ora.v3" "io" - "io/ioutil" + //"io/ioutil" "sync" + + //"gopkg.in/rana/ora.v3" + "gopkg.in/rana/ora.v4" ) var mu = &sync.Mutex{} @@ -140,10 +143,14 @@ func correlations(ptype string) []CorrelationField { // InitTables loads all payloads in the payloads variable. // Returns an error if it fails. func InitTables(db *ora.Ses, project string) error { - jsonbuf, _ := fetchJSON(db, EqualQuotes(project)) + jsonbuf, err := fetchJSON(db, project) + if err != nil { + return err + } + mu.Lock() defer mu.Unlock() - json.Unmarshal(jsonbuf, &payloads) + json.Unmarshal([]byte(jsonbuf), &payloads) if len(payloads) == 0 { return errors.New("tables config is corrupt") } @@ -152,39 +159,27 @@ func InitTables(db *ora.Ses, project string) error { // fetchJSON returns a byte slice of JSON configuration file from TABLES_CONFIG table. // Returns an error if it fails. -func fetchJSON(db *ora.Ses, project string) ([]byte, error) { - stmt, err := db.Prep(`SELECT - JSON_CLOB - FROM TABLES_CONFIG - WHERE PROJEKAT` + project, ora.S) +func fetchJSON(db *ora.Ses, project string) (string, error) { + stmt, err := db.Prep(`SELECT JSON_CLOB FROM TABLES_CONFIG WHERE PROJEKAT` + EqualQuotes(project), ora.S) defer stmt.Close() - if err != nil { - return nil, err + return "", err } + fmt.Println("prep passes") rset, err := stmt.Qry() if err != nil { - return nil, err + fmt.Println(err) + return "", err } + fmt.Println("query passes") - bytes := make([]byte, 0) + var data string if rset.Next() { - lob := rset.Row[0].(io.Reader) - if lob != nil { - bytes, err = ioutil.ReadAll(lob) - if err != nil { - // TODO: Find a fix for this. - // Some weird streaming read/write LOB error. - // Ignore for now. - //return nil, err - } - } else { - return nil, errors.New("json config is null") - } + data = rset.Row[0].(string) } - return bytes, nil + return data, nil } // DecodeJSON decodes JSON data from r to v. diff --git a/list_config.go b/list_config.go index 68008d9..ef2c302 100644 --- a/list_config.go +++ b/list_config.go @@ -1,6 +1,7 @@ package webutility -import "gopkg.in/rana/ora.v3" +//import "gopkg.in/rana/ora.v3" +import "gopkg.in/rana/ora.v4" type ListOptions struct { GlobalFilter bool `json:"globalFilter"` @@ -139,7 +140,7 @@ func GetListConfigObjectIDField(db *ora.Ses, otype string) string { resp = rset.Row[0].(string) } - if rset.Err != nil { + if rset.Err() != nil { return "" } @@ -207,8 +208,8 @@ func setListParams(db *ora.Ses, list *ListConfig, objType string) error { list.LazyLoad = rset.Row[2].(uint32) != 0 list.InlineEdit = rset.Row[3].(uint32) != 0 } - if rset.Err != nil { - return rset.Err + if rset.Err() != nil { + return rset.Err() } return nil } @@ -246,8 +247,8 @@ func getListNavigation(db *ora.Ses, listObjType string) ([]ListNavNode, error) { // RB is ignored }) } - if rset.Err != nil { - return nil, rset.Err + if rset.Err() != nil { + return nil, rset.Err() } return resp, nil @@ -283,8 +284,8 @@ func getListActions(db *ora.Ses, objType string) (ListActions, error) { resp.Print = rset.Row[4].(uint32) != 0 resp.Graph = rset.Row[5].(uint32) != 0 } - if rset.Err != nil { - return ListActions{}, rset.Err + if rset.Err() != nil { + return ListActions{}, rset.Err() } return resp, nil } @@ -344,8 +345,8 @@ func getFilterFieldsAndPosition(db *ora.Ses, objType string) (map[string]uint32, for rset.Next() { filtersField[rset.Row[0].(string)] = rset.Row[1].(uint32) } - if rset.Err != nil { - return nil, rset.Err + if rset.Err() != nil { + return nil, rset.Err() } return filtersField, nil } @@ -383,8 +384,8 @@ func getFiltersByFilterField(db *ora.Ses, filtersField string) ([]_filter, error DefaultValues: rset.Row[2].(string), }) } - if rset.Err != nil { - return resp, rset.Err + if rset.Err() != nil { + return resp, rset.Err() } return resp, nil } @@ -415,8 +416,8 @@ func getFilterDropdownConfig(db *ora.Ses, filtersField string) (Dropdown, error) resp.IDField = rset.Row[2].(string) resp.LabelField = rset.Row[3].(string) } - if rset.Err != nil { - return resp, rset.Err + if rset.Err() != nil { + return resp, rset.Err() } return resp, nil } @@ -467,8 +468,8 @@ func getListGraph(db *ora.Ses, objType string) ([]ListGraph, error) { Label: rset.Row[4].(string), }) } - if rset.Err != nil { - return resp, rset.Err + if rset.Err() != nil { + return resp, rset.Err() } return resp, nil } @@ -505,8 +506,8 @@ func getListOptions(db *ora.Ses, objType string) (ListOptions, error) { resp.Detail = rset.Row[6].(uint32) != 0 resp.Total = rset.Row[7].(uint32) != 0 } - if rset.Err != nil { - return ListOptions{}, rset.Err + if rset.Err() != nil { + return ListOptions{}, rset.Err() } return resp, nil } @@ -538,8 +539,8 @@ func getListParent(db *ora.Ses, objType string) ([]ListParentNode, error) { FilterField: rset.Row[2].(string), }) } - if rset.Err != nil { - return nil, rset.Err + if rset.Err() != nil { + return nil, rset.Err() } return resp, nil @@ -573,8 +574,8 @@ func getListPivot(db *ora.Ses, objType string) ([]ListPivot, error) { Value: rset.Row[3].(string), }) } - if rset.Err != nil { - return nil, rset.Err + if rset.Err() != nil { + return nil, rset.Err() } return resp, nil @@ -606,8 +607,8 @@ func getListDetails(db *ora.Ses, objType string) (ListDetails, error) { resp.ParentFilterField = rset.Row[2].(string) resp.SingleDetail = rset.Row[3].(uint32) != 0 } - if rset.Err != nil { - return resp, rset.Err + if rset.Err() != nil { + return resp, rset.Err() } return resp, nil diff --git a/select_config.go b/select_config.go index 792959b..271bcf3 100644 --- a/select_config.go +++ b/select_config.go @@ -1,8 +1,7 @@ package webutility -import ( - "gopkg.in/rana/ora.v3" -) +//import "gopkg.in/rana/ora.v3" +import "gopkg.in/rana/ora.v4" type SelectConfig struct { ListObjType string `json:"listObjectType"` @@ -45,8 +44,8 @@ func GetSelectConfig(db *ora.Ses, otype string) ([]SelectConfig, error) { ValueField: rset.Row[5].(string), }) } - if rset.Err != nil { - return nil, rset.Err + if rset.Err() != nil { + return nil, rset.Err() } return resp, nil -- 1.8.1.2