Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363710

Summary: Provide access to generated keys on SQL ADD operation
Product: z_Archived Reporter: Will Smythe <smythew>
Component: EDTAssignee: Joseph Vincens <jvincens>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: jspadea, jvincens, mheitz, svihovec, tww
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 365062    

Description Will Smythe CLA 2011-11-14 10:36:15 EST
@GeneratedValue is a nice addition (avoids custom SQL for ADD on tables that
have auto-generated fields), but developers need the ability to access the
ID(s) generated when a new record is added to the SQL data source. The "add"
statement correctly avoids trying to insert a value for @generatedvalue fields,
but this statement should either return (somehow) any generated keys OR - even
better - set them directly in the record that was the source record of the
action.

Example record:

record Customer type Entity { @table { name = "customer" } }
  id string{@id, @generatedvalue};
  name string?
end

Simple add code (works correctly):

a Customer { name = "My Company Name" };
add a to ds;

Database table after add:

| ID   | Name                     |
| 331  | My Company Name          |

Note record "a" still has 0 set as its ID

a.name = "Updated company name";

replace a to ds; /// PROBLEM: no easy way to update this record since it
doesn't have the correct ID set on it (probably still set to 0). Need for it to
get set to

======================

I think it is logical for the ADD statement to update the values of any
@generatedvalue fields in a record that was added. This way the record will
have the correct (generated) value set for its ID after the ADD statement
returns. 

Btw, see JDBC reference:
http://download.oracle.com/javase/1.4.2/docs/api/java/sql/Statement.html#getGeneratedKeys()
Collapse All Comments
Expand All
Comment 1 Will Smythe CLA 2011-11-14 10:37:10 EST
Setting importance to MAJOR because lack of this function makes it *very* difficult (if not impossible) to acquire a generated ID for a record added via the ADD.
Comment 2 Lisa Lasher CLA 2011-11-14 10:49:23 EST
changed from defect to Enhancement.  Set priority to P1 to indicate that this is a request to be implemented in 070.   We will need to evaluate for cost/risk.
Comment 3 Lisa Lasher CLA 2011-11-14 11:13:06 EST
Discussed with Brian & Jing - too late to add new enhancements for 070.  This would be functionality beyond what is in RBD, and in general we are deferring all such requests to 1.0.   Also, the developer who needs to implement this is out of the office this week.
Comment 4 Joseph Vincens CLA 2011-11-28 12:56:55 EST
Until this is implemented the following will return the generated values
		idRec annotatedTblRec ;
		get idRec.id from ds with
			#sql{
				select IDENTITY_VAL_LOCAL() from ANNOTATEDTBL
			} ;
Comment 5 Will Smythe CLA 2012-02-11 09:23:28 EST
This is a necessary capability. .. without it, developers have to play tricks/games in their code.
Comment 6 Brian Svihovec CLA 2012-03-02 15:34:26 EST
We will try to look at this one early in the FVT week for I3.
Comment 7 Joseph Vincens CLA 2012-03-05 11:48:56 EST
This will only work when a record/handler is specified, it will not work with scalars.
Comment 8 Lisa Lasher CLA 2012-03-30 18:33:30 EDT
close