On 02/07/2014 4:09 AM, Noel Grandin wrote:


On 2014-07-02 08:22 AM, Gili wrote:
permission has a single IDENTITY column. I am expecting SCOPE_IDENTITY() to return the inserted ID in the second
statement. Any ideas why this is not happening?


Do you have a standalone test case?

This is working for me:

create table permission(id identity);
create table users(version int, permission_id int, foreign key (permission_id) references permission(id));
insert into permission values();
insert into users values (0, scope_identity())

Hi Noel,

Let me know if this works for you:

CREATE TABLE permission (id IDENTITY);
CREATE TABLE users (id IDENTITY, version INT NOT NULL, last_modified TIMESTAMP NOT NULL,
    insert_permission_id BIGINT NOT NULL);
INSERT INTO permission VALUES();
INSERT INTO users (version, last_modified, insert_permission_id) VALUES (0, NOW(), SCOPE_IDENTITY());

PS: Replacing SCOPE_IDENTITY() with IDENTITY() fixes the problem but it's not clear why.

And a follow-up question: SCOPE_IDENTITY() says "changes [...] within Java functions are ignored". What are "Java functions" in this context? I am only aware of triggers.

Thanks,
Gili

--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to