Closed dzwvip closed 1 year ago
there is an error return from rows.Scan(cache...)
fixed in next release
If RefCursor can be directly converted to sqlrows, it can be directly scan to map and struct using gorm; The type of driver.rows used by the output cursor of the Godror library; You can use the godror.WrapRows function to convert to sql.rows
fixed in next release
tested ,ok
mapping RefCursor to sql.Rows is supported please return to docs and this example
Just the implicit conversion that occurs internally when the cursor returned by the query function, and how to convert if the cursor returned by the stored procedure is executed
I define a new function WrapRefCursor
in last commit same as WrapRows
that convert *RefCursor
into *sql.Rows
I don't see this function in the latest v2.7.16
last commit still not release. it will be release in v2.7.17
released
func queryCursor(crows goora.RefCursor) (list []map[string]interface{}, n int) { srows, err := crows.Query() if err != nil { } defer srows.Close() defer crows.Close() columns := srows.Columns() //转换Oracle列名 小写 for i := 0; i < len(columns); i++ { columns[i] = strings.ToLower(columns[i]) } columnLength := len(columns) cache := make([]interface{}, columnLength) //临时存储每行数据地址 for index := range cache { //为每一列初始化一个指针 var a interface{} cache[index] = &a } n = 0 //scan to map for srows.Next() { _ = srows.Scan(cache...) item := make(map[string]interface{}) for i, data := range cache { item[columns[i]] = data.(*interface{}) //取实际类型 } list = append(list, item) n++ }
result is nil