Giter VIP home page Giter VIP logo

Comments (9)

cjbj avatar cjbj commented on August 27, 2024 2

I read about this type it is actually stored as a blob.

Prior to 21c, JSON could be stored as VARCHAR, CLOB, or BLOB types by specifying the AS JSON clause at table creation. At some stage an extra attribute was added so that client apps could differentiate from other VARCHAR, CLOB or BLOBS columns. We only just found this out and added support in eg python-oracledb, see the release notes and ODPI-C commit.

From 21c there is an explicit JSON datatype that can/should be used in preference to the above, older table creation syntax.

from go-ora.

sijms avatar sijms commented on August 27, 2024 1

sorry for late I will test the data type and its network representation and update the package

from go-ora.

sijms avatar sijms commented on August 27, 2024 1

I find the solution i will add it to next release
thanks to oracle-db python driver

&go_ora.ParameterInfo{Name:"JSON_VAL", TypeName:"", SchemaName:"", DomainSchema:"", DomainName:"", Direction:0, IsNull:false, AllowNull:true, IsJson:true, ColAlias:"", DataType:113, IsXmlType:false, Flag:0x0, Precision:0x0, Scale:0x0, MaxLen:4000, MaxCharLen:0, MaxNoOfArrayElements:0, ContFlag:0, ToID:[]uint8(nil), Version:0, CharsetID:0, CharsetForm:0, BValue:[]uint8(nil), Value:driver.Value(nil), iPrimValue:driver.Value(nil), oPrimValue:driver.Value(nil), OutputVarPtr:interface {}(nil), getDataFromServer:true, oaccollid:0, cusType:(*go_ora.customType)(nil), Annotations:map[string]string(nil)}
&go_ora.ParameterInfo{Name:"BLOB_VAL", TypeName:"", SchemaName:"", DomainSchema:"", DomainName:"", Direction:0, IsNull:false, AllowNull:true, IsJson:false, ColAlias:"", DataType:113, IsXmlType:false, Flag:0x0, Precision:0x0, Scale:0x0, MaxLen:4000, MaxCharLen:0, MaxNoOfArrayElements:0, ContFlag:0, ToID:[]uint8(nil), Version:0, CharsetID:0, CharsetForm:0, BValue:[]uint8(nil), Value:driver.Value(nil), iPrimValue:driver.Value(nil), oPrimValue:driver.Value(nil), OutputVarPtr:interface {}(nil), getDataFromServer:true, oaccollid:0, cusType:(*go_ora.customType)(nil), Annotations:map[string]string(nil)}

from go-ora.

sijms avatar sijms commented on August 27, 2024 1

fixed in v2.7.21
you can test json column with field ParameterInfo.IsJson

from go-ora.

sijms avatar sijms commented on August 27, 2024

I read about this type it is actually stored as a blob. its support started from oracle 21c so you can pass go_ora.Blob parameter
older version of oracle will show its blob origin

create table customers (
    id integer not null primary key,
    json_data blob check (json_data is json)
);

from go-ora.

viplifes avatar viplifes commented on August 27, 2024

Thank you for your attention to this issue.

Unfortunately, our service cannot know the type of the returned field.

We look at DatabaseTypeName() to understand that the field type is json (not original BLOB) and convert json.Unmarshal to a map.

Here is the code that shows that in godror it was possible to understand that the field type is JSON.

package main

import (
	"database/sql"
	"fmt"

	_ "github.com/godror/godror"
	go_ora "github.com/sijms/go-ora/v2"
)

func main() {

	connOra, err := sql.Open("oracle", go_ora.BuildUrl("127.0.0.1", 1521, "ORCLPDB1", "SYS", "pass", nil))
	if err != nil {
		panic(err)
	}
	defer connOra.Close()
	run(connOra)
	// print
	// OCIBlobLocator OCIBlobLocator

	connGodror, err := sql.Open("godror", `user="SYS" sysdba="1" password="pass" connectString="127.0.0.1:1521/ORCLPDB1"`)
	if err != nil {
		panic(err)
	}
	defer connGodror.Close()
	run(connGodror)
	// print
	// BLOB JSON
}

func run(conn *sql.DB) {
	conn.Exec(`GRANT CREATE SESSION TO SYS`)
	conn.Exec(`DROP TABLE IF EXISTS types_test`)
	conn.Exec(`CREATE TABLE types_test (myblob BLOB NULL, myjson JSON NULL)`)
	conn.Exec(`INSERT INTO types_test (myblob, myjson)VALUES(UTL_RAW.CAST_TO_RAW('blobval - not json'), json('{"foo": "bar"}'))`)

	rows, err := conn.Query(`SELECT * FROM types_test`)
	if err != nil {
		panic(err)
	}
	cTypes, _ := rows.ColumnTypes()
	fmt.Println(cTypes[0].DatabaseTypeName(), cTypes[1].DatabaseTypeName())
}

from go-ora.

sijms avatar sijms commented on August 27, 2024

sorry for late. these days i am so busy but soon i will fix this issue

from go-ora.

sijms avatar sijms commented on August 27, 2024

till now I check the columns attribs for Blob and Blob with json constraint and I find no difference

&go_ora.ParameterInfo{Name:"JSON_VAL", TypeName:"", Direction:0, IsNull:false, AllowNull:true, ColAlias:"", DataType:113, IsXmlType:false, Flag:0x0, Precision:0x0, Scale:0x0, MaxLen:4000, MaxCharLen:0, MaxNoOfArrayElements:0, ContFlag:0, ToID:[]uint8(nil), Version:0, CharsetID:0, CharsetForm:0, BValue:[]uint8(nil), Value:driver.Value(nil), iPrimValue:driver.Value(nil), oPrimValue:driver.Value(nil), OutputVarPtr:interface {}(nil), getDataFromServer:true, oaccollid:0, cusType:(*go_ora.customType)(nil)}
&go_ora.ParameterInfo{Name:"BLOB_VAL", TypeName:"", Direction:0, IsNull:false, AllowNull:true, ColAlias:"", DataType:113, IsXmlType:false, Flag:0x0, Precision:0x0, Scale:0x0, MaxLen:4000, MaxCharLen:0, MaxNoOfArrayElements:0, ContFlag:0, ToID:[]uint8(nil), Version:0, CharsetID:0, CharsetForm:0, BValue:[]uint8(nil), Value:driver.Value(nil), iPrimValue:driver.Value(nil), oPrimValue:driver.Value(nil), OutputVarPtr:interface {}(nil), getDataFromServer:true, oaccollid:0, cusType:(*go_ora.customType)(nil)}

the information about json column is store in table all_constraints which can be queried for json constraint.

May be there are network calls that return more advanced information about the columns where we can find the difference

from go-ora.

sijms avatar sijms commented on August 27, 2024

I will test the code with oracle server 21c and see the difference

from go-ora.

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.