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

Autogenerated Primary Keys #3

Open
alphaville opened this issue Apr 27, 2010 · 1 comment
Open

Autogenerated Primary Keys #3

alphaville opened this issue Apr 27, 2010 · 1 comment
Labels

Comments

@alphaville
Copy link
Collaborator

There is an important issue with Prepared Statements in JDBC that inhibits us from assigning the DEFAULT values to null primary keys that are auto-generated. A reasonable approach would be to modify the table creation procedure to force the use of DEFAULT for AG primary keys. Let me give an example:

This is the table creation database statement:
CREATE TABLE ABC (PK INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, B INT);

And this is the corresponding Prepared Statement I suggest to use:
INSERT INTO ABC (A,B) VALUES (DEFAULT, ?);
which is equivalent to:
INSERT INTO ABC (B) VALUES (?);

Of course this would assign to the entry a primary key, that the user wouldn't be aware of upon registration. This naturally leads to the following modification of the interface for the method register() in Component:

public Component register(DeciBell db);

Where the returned value is a clone of the registered component, i.e. contains the value of the primary key assigned to the registered component. The same method interface can also cope with cases where the primary key is provided by the user and is not AG.

@alphaville
Copy link
Collaborator Author

Initial implementation needs to be tested.

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

1 participant