Comments (13)
from odpi.
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.
Ok,
- r.data[i] = ((([maxArraySize]*C.dpiData)(unsafe.Pointer(&dataArr))))[:]
was the solution (I can convert only pointer types in Go) for the bad dpiData.
-
seems to be true
-
seems to start with 0
-
I must've read something wrong, now I increment bufferRowIndex only after reading out data, and seems to work.
from odpi.
@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.
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.
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.
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.
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.
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.
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.
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.
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.
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)
- XMLTYPE as "real" XML HOT 3
- Ability to set OCI_ATTR_LOBPREFETCH_SIZE HOT 7
- "ORA-03106: fatal two-task communication protocol error" when CLOB is fetched as strings and then lob locators HOT 3
- core dumps generated in libclntsh when timeouts are configured HOT 10
- Any plan to support Apple's M1 plat? HOT 1
- Is there a reference example dequeue message with message ID dequeue option HOT 9
- When ODPI tries to translate a variable to a temporary LOB, and there is inadequate TEMP tablespace, ODPI segfaults when the cursor is closed HOT 6
- M1 Mac issue ( incompatible architecture) HOT 2
- How to use ODPI-C with Oracle Times Ten? HOT 9
- Column Alias Error HOT 7
- Add an option to convert numbers between double and decimal in the same way as node.js, python3, ruby, rust or so HOT 5
- Oracle Rust driver HOT 2
- Option to get json float as float. It is got as double now. HOT 8
- Bytes after nul in members of dpiXid are zeroed. HOT 2
- Is DPI_TPC_END_SUSPEND an undocumented flag in the OCI manual? HOT 3
- dpiEnqOptions_setVisibility and dpiLob_getType are listed not in round_trips.rst HOT 2
- Get column name for position HOT 2
- `dpiStmt_execute` with `DPI_MODE_EXEC_PARSE_ONLY` will create a table. HOT 4
- Retrieving CLOB from an OUT parameter of an Store Procedure HOT 1
- ERROR: DPI-1047: Cannot locate a 32-bit Oracle Client library HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from odpi.