rana / ora

An Oracle database driver in Go.
MIT License
271 stars 65 forks source link

Stored Procedure with standard database/sql interface? #145

Open asaf opened 7 years ago

asaf commented 7 years ago

Hey,

Is there any way to return values from stored procedures using the standard database/sql API?

We're using packages such sqlx that expects the standard sql interface,

Thanks.

tgulacsi commented 7 years ago

AFAIK no. database/sql has very strict rules about the values drivers can return.

Please weigh in in https://github.com/golang/go/issues/18415 and https://github.com/golang/go/issues/18417 !

asaf commented 7 years ago

@tgulacsi yea I know, I was wondering if I have an instance of sql.DB I can cast it back or use its underline connection to use this package's API without re-opening another session / connection to perform the PrepAndExe call,

Another question, I have a map of fields, is it possible to bind fields by name instead of by position ?

Thanks.

tgulacsi commented 7 years ago

I've investigated this topic thoroughly, and database/sql protects the underlying connection through two levels of unexported indirection - so only unsafe methods could surface the underlying connection.

Fields by name: check out Go 1.8, the "v4" branch should work with Go 1.8beta2 (or master), and should provide that functionality - if not, please report as bug!

Asaf Shakarzy notifications@github.com ezt írta (időpont: 2017. jan. 6., P, 10:53):

@tgulacsi https://github.com/tgulacsi yea I know, I was wondering if I have an instance of sql.DB I can cast it back or use its underline connection to use this package's API without re-opening another session / connection to perform the PrepAndExe call,

Another question, I have a map of fields, is it possible to bind fields by name instead of by position ?

Thanks.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/rana/ora/issues/145#issuecomment-270868680, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPoSjvRrt22sNYKoNFAYXzpjk9zOY0uks5rPg76gaJpZM4LcP5z .

asaf commented 7 years ago

@tgulacsi Thanks,

I'll try 1.8beta2, should it support fields by name in with the OUT parameters of a stored procedure call? if I bind an output parameter by name, would I expect the corresponding key of the provided map to be overridden with the OUT param value?

Thanks, Asaf/

tgulacsi commented 7 years ago

No, OUT parameters are restricted just the same. If you want to ease your queries with lots of parameters, you can try https://godoc.org/github.com/tgulacsi/go/orahlp#MapToSlice

Asaf Shakarzy notifications@github.com ezt írta (időpont: 2017. jan. 6., P, 11:31):

@tgulacsi https://github.com/tgulacsi Thanks,

I'll try 1.8beta2, should it support fields by name in with the OUT parameters of a stored procedure call? if I bind an output parameter by name, would I expect the corresponding key of the provided map to be overridden with the OUT param value?

Thanks, Asaf/

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/rana/ora/issues/145#issuecomment-270876176, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPoSndlQhviDO84mCVvShefHlLjPU2Rks5rPhgFgaJpZM4LcP5z .

asaf commented 7 years ago

@tgulacsi many thanks,

I guess we'll have to wait for go1.9 to for a more robust, enterprise-ready SQL API :-)

tgulacsi commented 7 years ago

Thats just 8 months!

So please contact @kardianos and write on those issues, as these are the forums and now is the time to form that future API!

Asaf Shakarzy notifications@github.com ezt írta (időpont: 2017. jan. 6., P 12:07):

@tgulacsi https://github.com/tgulacsi many thanks,

I guess we'll have to wait for go1.9 to for a more robust, enterprise-ready SQL API :-)

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/rana/ora/issues/145#issuecomment-270882648, or mute the thread https://github.com/notifications/unsubscribe-auth/AAPoSj7XF3xiQ6oT07-F8ByCeMeeIOhoks5rPiBqgaJpZM4LcP5z .

asaf commented 7 years ago

Will do, thanks!

kardianos commented 7 years ago

Support for OUTPUT params and custom types, and passing options into queries will be supported in go1.9 (already merged into master).

tgulacsi commented 7 years ago

@kardianos where shall we discuss how to use those sql.Out NamedArg Values? It's not clear from the docs yet.