Issue Details (XML | Word | Printable)

Key: TORQUE-86
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: CG Monroe
Reporter: Will Glass-Husain
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Torque

MSSQL data inserts with with IDENTITY key require IDENTITY_INSERT property to be on

Created: 09/Mar/07 11:25 PM   Updated: 26/Oct/07 06:04 PM
Return to search
Component/s: Generator
Affects Version/s: 3.2
Fix Version/s: 3.3-RC3

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works mssql_row.patch 2007-03-09 11:34 PM Will Glass-Husain 0.9 kB

Resolution Date: 19/Oct/07 11:03 PM


 Description  « Hide
For Microsoft SQL Server, if a primary key is of type IDENTITY (autoincrement), then you will not be able to insert a record containing a primary key.

For example, the following line will give an error if field WEB_APP_ID is a primary key.

INSERT INTO WEB_APP (WEB_APP_ID,WEB_APP_NAME,ROOT_PATH,BASE_URL,IS_PRO,ALLOW_NATIVE_VENSIM)
    VALUES (1,'Broadcast','c:/www/sims','http://localhost/sims/',1,1);

The global property IDENTITY_INSERT can prevent this error. However, if your dataset has a mix of tables, some with autoincrement and some without then you will not be able to set this globally.

The solution is to check to see if the primary key is has the auto_increment property, and to wrap the insert with an IDENTITY_INSERT setting if so. Example:

SET IDENTITY_INSERT WEB_APP ON;
INSERT INTO WEB_APP (WEB_APP_ID,WEB_APP_NAME,ROOT_PATH,BASE_URL,IS_PRO,ALLOW_NATIVE_VENSIM)
    VALUES (1,'Broadcast','c:/www/sims','http://localhost/sims/',1,1);
SET IDENTITY_INSERT WEB_APP OFF;

I've attached a patch to the templates which implements this.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.