tgulacsi / goracle

cx_Oracle translation for Oracle access
Other
47 stars 16 forks source link

ORA-01458: invalid length inside variable character string #17

Closed viney closed 10 years ago

viney commented 10 years ago
func TestCURD(t *testing.T) {
    // open
    db, err := sql.Open("goracle", "xxxxxxxxxxx")
    if err != nil {
        t.Fatal("Open: ", err)
        return
    }
    defer db.Close()

    // drop
    if _, err = db.Exec(`drop table tb_test`); err != nil {
        t.Fatal("Drop: ", err)
        return
    }

    // create
    if _, err = db.Exec(`create table tb_test(userid number(16) not null)`); err != nil {
        t.Fatal("Create: ", err)
        return
    }

    // TODO: error(ORA-01458: invalid length inside variable character string)
    // length is 12, ok(123456789012)
    // length is more than 12, fail(1234567890123)
    var userid uint64 = 1234567890123
    // insert
    if _, err = db.Exec(`insert into tb_test(userid) values(:1)`, userid); err != nil {
        t.Fatal("Insert: ", err)
        return
    }

    // select
    row := db.QueryRow(`select userid from tb_test where userid = :1`, userid)

    var id uint64
    if err = row.Scan(&id); err != nil {
        t.Fatal("Select: ", err)
        return
    }

    fmt.Println(id)
}
tgulacsi commented 10 years ago

big.Int or NumersAsStrings?

qqiao commented 10 years ago

Ran into this issue as well. What I noticed is that the problem seems to lie in param processing. E.g.:

if you have IDs 1, 2 1234567890123

SELECT * FROM tb will return all results

SELECT * FROM tb WHERE ID = :1 and if you put 1234567890123 as the param, it fails.

tgulacsi commented 10 years ago

What is the type of tb.id ? string or number?

2014-11-03 17:43 GMT+01:00 Qian Qiao notifications@github.com:

Ran into this issue as well. What I noticed is that the problem seems to lie in param processing. E.g.:

if you have IDs 1, 2 1234567890123

SELECT FROM tb will return all results

SELECT FROM tb WHERE ID = :1 and if you put 1234567890123 as the param, it fails.

— Reply to this email directly or view it on GitHub https://github.com/tgulacsi/goracle/issues/17#issuecomment-61507078.

qqiao commented 10 years ago

Sry, forgot to mention, it's number

tgulacsi commented 10 years ago

I can reproduce it with in-memory tables: https://github.com/tgulacsi/goracle/blob/ora-1458/oracle/cursors_test.go#L24

qqiao commented 10 years ago

Just tested ora-1458 branch using number 22544687786605, which is something I have in one of my production systems that broke master, the fix works like a charm.

Thanks for the prompt reply and fix!