18 October 2007

SQL Server 2000 IDENTITY_INSERT

SQL Server has got identity for primary keys( see this article ) that was preventing me from inserting into a table with EO.

To get by this you can just set the identity insert to on with:

EOUtilities.rawRowsForSQL( ec, modleName, "SET IDENTITY_INSERT tableName ON", NSArray.EmptyArray );

Note that you might need to get the new primary key( identity ) yourself, ex.:

NSArray rawRows = EOUtilities.rawRowsForSQL( ec, modleName, "SELECT MAX(idenityColumnName) as NR FROM tableName", NSArray.EmptyArray );
NSDictionary rowWithPK = (NSDictionary)rawRows.objectAtIndex(0);
Object maxPK = rowWithPK.objectForKey("NR");
int primaryKey = (new Integer(maxPK.toString())).intValue();

No comments: