Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Converting Booleans to varchar2(1) Oracle with Valuer Interface using go-ora/v2 v2.7.11 #420

Closed
schackoa opened this issue Aug 4, 2023 · 2 comments
Labels

Comments

@schackoa
Copy link

schackoa commented Aug 4, 2023

Hey there,

I'm currently working on a project where I need to convert boolean values to varchar2(1) in Oracle. These values should be represented as "J" for true (similar to "yes") and "N" for false (akin to "no").

For this task, I'm using the go-ora/v2 v2.7.11 library. In my code, I have defined a type called OracleBool, which is essentially a boolean with a custom Valuer interface:

type OracleBool bool

func (b OracleBool) Value() (driver.Value, error) {
    if b {
        return "J", nil
    }
    return "N", nil
}

Now, the challenge arises when I try to execute the insert operation using the defined OracleBool type:

func Insert(...) {
    var b OracleBool = true
    result, err := t.tx.ExecContext(ctx, `INSERT INTO sometable (bool_col) VALUES (:myBool)`, b)
}

However, I'm encountering an issue with the error message: strconv.ParseFloat: parsing "n": invalid syntax.

After some investigation, I suspect that this error might be related to the type detection in the library's code, particularly this section (you can find it here):

I think this could be the reason (https://github.com/sijms/go-ora/blob/master/v2/parameter_encode.go#L264C2-L264C45)

func tNumber(input reflect.Type) bool {
	return tInteger(input) || tFloat(input) || input.Kind() == reflect.Bool
}

I'm reaching out for assistance in resolving this hiccup. Any insights or guidance would be highly appreciated.

Thanks for your awesome work!

Best regards,
Andy

@schackoa schackoa changed the title Issue with Converting Booleans to varchar2(1) with Valuer Interface Oracle using go-ora/v2 v2.7.11 Issue with Converting Booleans to varchar2(1) Oracle with Valuer Interface using go-ora/v2 v2.7.11 Aug 4, 2023
@sijms
Copy link
Owner

sijms commented Aug 5, 2023

I do change in the above code replacing input.Kind() == reflect.Bool when I add new type PLSQL Boolean
I will also test you code before make the release

@sijms sijms added the fixed label Aug 11, 2023
@sijms
Copy link
Owner

sijms commented Aug 12, 2023

fixed in v2.7.12

@sijms sijms closed this as completed Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants