Git Product home page Git Product logo

Comments (9)

tgulacsi avatar tgulacsi commented on May 30, 2024

I think LastInsertID is just undefined for Oracle, so the existing code is just a hack.
I'd delete it and document the undefinedness of LastInsertID and the usage of the "RETURNING" statement.
(We could use ROWID as LastInsertID, iff that'd fit in int64, but it's 10 bytes (http://www.orafaq.com/wiki/ROWID), so this temptation can be resisted :))

from ora.

MichaelS11 avatar MichaelS11 commented on May 30, 2024

Cool, thank you :)

from ora.

tgulacsi avatar tgulacsi commented on May 30, 2024

I'll wait for an amen from Rana Ian...

from ora.

rana avatar rana commented on May 30, 2024

Hi Michael, Tamás,

The design of the &lastInsertId is to intentionally support the Go Result interface method LastInsertId() in the database/sql package.

The LastInsertId() (int64, error) method returns an int64. So the driver supports the interface with &lastInsertId. Some compromises needed to be made to bridge the Oracle database and Go libraries. This was one such compromise.

You are correct that Oracle SQL syntax allows returning multiple variables of any type and that the current driver doesn't support it. It wasn't clear to me that anyone uses that feature. I think the majority of use cases is to support a numeric identity column updated with an Oracle sequence. The driver does have Oracle-only features in the driver which are not accessible from the database/sql package. I'm fine with adding this feature while still supporting the existing functionality.

What do you think?

Thank you,

Rana

from ora.

MichaelS11 avatar MichaelS11 commented on May 30, 2024

Sounds good to me. I am not using it at the moment, just thought you should know. Thank you for your help. :)

Just to note it does not seem like the LastInsertId is working as of now.

from ora.

tgulacsi avatar tgulacsi commented on May 30, 2024

@rana see https://github.com/mattn/go-oci8/blob/master/oci8.go#L1103 and https://github.com/go-goracle/goracle/blob/v1/driver.go#L198 : they're just return an error for LastInsertID, as it is impossible to implement it without severe flaws.

I'm suggesting you to do the same, and remove this functionality - add some documentation and return an errors.New("not implemented - use RETURNING statement") or sth like that.

from ora.

C-Pro avatar C-Pro commented on May 30, 2024

@tgulacsi please, leave it as it is :)
We can not use returning statement through database/sql, and as far as I know, this hack is the only way to get last inserted Id now! (except not using database/sql)

from ora.

tgulacsi avatar tgulacsi commented on May 30, 2024

Maybe some clarification in the docs, and marking the value for LastInsertID as such:

if strings.Contains(sqlEnd, "RETURNING") && strings.Contains(sqlEnd, "lastInsertID") {
params[len(params)-1] = &lastInsertId
}

So iff "RETURNING xx lastInsertID" will treat the last param as the lastInsertId.

This way if you want lastInsertID, you can have it, but this won't interfere with other RETURNING use cases.
?

from ora.

rana avatar rana commented on May 30, 2024

Go for it, if you can reach the functionality in an improved way, or
document it that's fine

On Thu, Dec 17, 2015, 2:35 AM Tamás Gulácsi [email protected]
wrote:

Maybe some clarification in the docs, and marking the value for
LastInsertID as such:

if strings.Contains(sqlEnd, "RETURNING") && strings.Contains(sqlEnd,
"lastInsertID") {
params[len(params)-1] = &lastInsertId
}

So iff "RETURNING xx lastInsertID" will treat the last param as the
lastInsertId.

This way if you want lastInsertID, you can have it, but this won't
interfere with other RETURNING use cases.
?


Reply to this email directly or view it on GitHub
https://github.com/rana/ora/issues/43#issuecomment-165414294.

from 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.