Coder Social home page Coder Social logo

Help using ODPI-C about odpi HOT 13 CLOSED

oracle avatar oracle commented on August 15, 2024
Help using ODPI-C

from odpi.

Comments (13)

tgulacsi avatar tgulacsi commented on August 15, 2024 1

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024 1

Finally I could manage to fix it - the error was using dpiData_setBytes instead of dpiVar_setFromBytes - this resulted in a pointer being in the LOB data.
The current code (a3c3f2eefd217882aedf9097eb9be48ee24af9d8 at rana/ora@a3c3f2e) passes the tests, both when I INSERT a []byte, and when I INSERT a Lob (from a Reader).

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024

Ok,

  1. r.data[i] = ((([maxArraySize]*C.dpiData)(unsafe.Pointer(&dataArr))))[:]

was the solution (I can convert only pointer types in Go) for the bad dpiData.

  1. seems to be true

  2. seems to start with 0

  3. I must've read something wrong, now I increment bufferRowIndex only after reading out data, and seems to work.

from odpi.

cjbj avatar cjbj commented on August 15, 2024

@tgulacsi I'll let @anthony-tuininga comment on the code (and decide what doc & sample improvements can be made).

During design & implementation of ODPI-C, @anthony-tuininga created an (unreleased) basic Go driver that uses ODPI-C. Our plans were to get ODPI-C and cx_Oracle 6 in production, get node-oracledb V2 out, and then review the state of Go drivers. The decision to be made is whether to contribute to an existing driver, or release & enhance our prototype. This would depend on the technical direction of the current Go drivers, and what their (your) communities think is best.

It seems you are already heading down the rewrite path, which is great. We'd love to discuss this more and see how we can assist you. Do you want to drop me an email?

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024

Ok, another question:

I want to bind a slice of int64s

        if C.dpiConn_newVar(
            st.conn.dpiConn, typ, natTyp, C.uint32_t(dataSliceLen),
            bufSize, 1,
            isArray, nil,
            &st.vars[i], &dataArr,
        ) == C.DPI_FAILURE {
            return st.getError()
        }
        st.data[i] = (*((*[maxArraySize]*C.dpiData)(unsafe.Pointer(&dataArr))))[:dataSliceLen]
        fmt.Printf("%d. dpiConn_newVar(dpiConn=%p, typ=%d, natTyp=%d, arraySize=%d, bufSize=%d,
isBytes=%d, isArray=%d, obj=%p, *dpiVar=%p, *dataArr=%p): %#v\n",
            i, st.conn.dpiConn, typ, natTyp, dataSliceLen, bufSize, 1, isArray, nil, &st.vars[i]
, &dataArr, st.data[i])

result:

! go install && go test -run=Exec
0. dpiConn_newVar(dpiConn=0xb05eb0, typ=2010, natTyp=3000, arraySize=1000, bufSize=0, isBytes=1, isArray=0, obj=%!p(<nil>), *dpiVar=0xc42000e070, *dataArr=0xc42000e078): []*ora._Ctype_struct_dpiData{(*ora._Ctype_struct_dpiData)(0xb7be50), (*ora._Ctype_struct_dpiData)(0x827d90), (*ora._Ctype_struct_dpiData)(nil), (*ora._Ctype_struct_dpiData)(nil), (*ora._Ctype_struct_dpiData)(nil), (*ora._Ctype_struct_dpiData)(nil), (*ora._Ctype_struct_dpiData)(nil), (*ora._Ctype_str...

only 2 elements of the returned dpiData array is not nil, and even the second looks suspicious (&ora._Ctype_struct_dpiData{isNull:537608192, _:[4]uint8{0xc4, 0x0, 0x0, 0x0}, value:[24]uint8{0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0xf3, 0x57, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}),
and the C.dpiData_setInt64 results in SIGSEGV.

What am I doing wrong?

from odpi.

anthony-tuininga avatar anthony-tuininga commented on August 15, 2024

The dataArr value that is returned is an array of dpiData structures -- not an array of pointers to dpiData structures. It looks like that might be the source of your difficulties?

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024

For the record, the correct conversion from *C.dpiData to []C.dpiData is:

var p *C.dpiData
...
((*[1<<30]C.dpiData)(unsafe.Pointer(p)))[:arraySize:arraySize]

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024

Ok, next question:
What combinations of OracleType-NativeType pairs are accepted?
I get "DPI-1014: conversion between Oracle type 2010 and native type 3002 is not implemented" for binding float64 to NUMBER column.
And I got "ORA-01722: invalid number" for binding string to number column
(INSERT INTO table (F_num NUMBER) values (:1)).

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024

What are dpiVar_setFrom... (dpiVar_setFromLOB) for? What is the difference with dpiData_setLOB ?
When to use which?
I'm asking this because I use dpiConn_newVar, then dpiData_setLOB on the dpiData returned with the var by newVar, and though I can write the LOB (tempLob), I get "ORA-22275: invalid LOB locator specified" for dpiStmt_execute.

from odpi.

anthony-tuininga avatar anthony-tuininga commented on August 15, 2024

What combinations of OracleType-NativeType pairs are accepted?

That should be documented. I'll take care of that. In the meantime, though, you can look here: https://github.com/oracle/odpi/blob/master/src/dpiOracleType.c. That gives you the default native type for each Oracle type. Then you can look here: https://github.com/oracle/odpi/blob/master/src/dpiVar.c#L1412-L1438 for the non-default native types supported for each Oracle type.

And I got "ORA-01722: invalid number" for binding string to number column
(INSERT INTO table (F_num NUMBER) values (:1)).

I'd need more information to know why that was happening. It might in fact be an invalid number! :-)

What are dpiVar_setFrom... (dpiVar_setFromLOB) for? What is the difference with dpiData_setLOB ?
When to use which?

dpiVar_setFromLob() is intended when using variables. It manages the references and ensures things are copied internally. dpiData_setLOB() should only be used when managing attributes of Oracle objects, not for variables. I'll take a look at the documentation for these methods and ensure that is made clear.

from odpi.

tgulacsi avatar tgulacsi commented on August 15, 2024

Thanks!

Trying to bind a "0" into a NUMBER column, I got
z_test.go:113: 1. {Name:f_num Value:[0]}: dpiStmt_execute(mode=32 arrLen=1): ORA-01722: invalid number
As I see, this is allowed, so I missed something.

My other question was: I can read and write LOBs, but when I try to INSERT into a [BC]LOB from a string (VARCHAR), the result is some garbage in the database.

When I wrote these down, it struck me that maybe these correlate, and I do the VARCHAR binding simply wrong...

And that was the case: I used dpiData_setBytes, but here I have to use dpiVar_setFromBytes.
Just as with LOBs.

So I suggest writing this somewhere in the documentation:
"If there's a setter on the dpiVar for something, you have to use that, and not the same function on dpiData."

from odpi.

anthony-tuininga avatar anthony-tuininga commented on August 15, 2024

Trying to bind a "0" into a NUMBER column, I got
z_test.go:113: 1. {Name:f_num Value:[0]}: dpiStmt_execute(mode=32 arrLen=1): ORA-01722: invalid number
As I see, this is allowed, so I missed something.

Can you provide the full code for this test case? I can take a look at that and your Go driver code and let you know if something isn't happening correctly -- and clarify documentation further, if needed!

So I suggest writing this somewhere in the documentation:
"If there's a setter on the dpiVar for something, you have to use that, and not the same function on dpiData."

Agreed. I'll add a note to each of the functions as well.

from odpi.

anthony-tuininga avatar anthony-tuininga commented on August 15, 2024

I have updated the documentation as suggested to include information on data types and provide warnings about the use of the dpiData functions here for example.

from odpi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.