sijms / go-ora

Pure go oracle client
MIT License
771 stars 169 forks source link

New issue with REF CURSOR #468

Closed oheurtel closed 8 months ago

oheurtel commented 8 months ago

I have a new issue while testing REF CURSOR with the following code :

/*
There is no error handling in this test case.

Create the following table for the test case :

  create table t as select rownum n from dual connect by level <= 100;

*/

package main

import (
  "fmt"
  "database/sql"
  _ "github.com/sijms/go-ora/v2"
)

func main() {

  db, _ := sql.Open("oracle", "oracle://xxx:xxx*@localhost:1521/xxx") // **masked**

  var (
    n1 int32
    rc sql.Rows
    n2 int32
  )

  // Will fetch only 25 lines (over 100)
  rows, _ := db.Query("select n,cursor(select t.n from dual) from t order by n")
  for rows.Next() {
    rows.Scan(&n1,&rc)
    fmt.Print(fmt.Sprintf("%3d - ",n1))
    for rc.Next() {
      rc.Scan(&n2)
      fmt.Print(fmt.Sprintf("%3d",n2))
    }
    rc.Close()
    fmt.Println()
  }
  rows.Close()

  fmt.Println()

  // Will fetch 50 lines (OK) but REF CURSOR fetches no line after 25 lines
  rows, _ = db.Query("select n,cursor(select t.n from dual) from t where n > 50 order by n")
  for rows.Next() {
    rows.Scan(&n1,&rc)
    fmt.Print(fmt.Sprintf("%3d - ",n1))
    for rc.Next() {
      rc.Scan(&n2)
      fmt.Print(fmt.Sprintf("%3d",n2))
    }
    rc.Close()
    fmt.Println()
  }
  rows.Close()

  db.Close()
}

Result : 
  **// Fetch only 25 lines (over 100)**
  1 -   1
  2 -   2
  3 -   3
  4 -   4
  5 -   5
  6 -   6
  7 -   7
  8 -   8
  9 -   9
 10 -  10
 11 -  11
 12 -  12
 13 -  13
 14 -  14
 15 -  15
 16 -  16
 17 -  17
 18 -  18
 19 -  19
 20 -  20
 21 -  21
 22 -  22
 23 -  23
 24 -  24
 25 -  25

 **// Fetch 50 lines (OK) but REF CURSOR fetches no line after 25 lines**
 51 -  51
 52 -  52
 53 -  53
 54 -  54
 55 -  55
 56 -  56
 57 -  57
 58 -  58
 59 -  59
 60 -  60
 61 -  61
 62 -  62
 63 -  63
 64 -  64
 65 -  65
 66 -  66
 67 -  67
 68 -  68
 69 -  69
 70 -  70
 71 -  71
 72 -  72
 73 -  73
 74 -  74
 75 -  75
 76 - 
 77 - 
 78 - 
 79 - 
 80 - 
 81 - 
 82 - 
 83 - 
 84 - 
 85 - 
 86 - 
 87 - 
 88 - 
 89 - 
 90 - 
 91 - 
 92 - 
 93 - 
 94 - 
 95 - 
 96 - 
 97 - 
 98 - 
 99 - 
100 - 

I am using go version go1.21.4 darwin/amd64 and go-ora/v2 2.7.23.

sijms commented 8 months ago

fixed in next release

sijms commented 8 months ago

Fixed in v2.7.24