-
Notifications
You must be signed in to change notification settings - Fork 84
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
Insert into Table with Active Trigger #21
Comments
Current workaround: Replace // node_modules/loopback-connector-mssql/lib/mssql.js:157
var sql = "INSERT INTO " + tblName + " (" + fieldsAndData.fields + ")" + MsSQL.newline;
sql += "OUTPUT INSERTED." + modelPKID + " AS insertId" + MsSQL.newline;
sql += "VALUES (" + fieldsAndData.paramPlaceholders + ");"; with (use select scope_identity() instead of OUTPUT INSERTED) // node_modules/loopback-connector-mssql/lib/mssql.js:157
var sql = "INSERT INTO " + tblName + " (" + fieldsAndData.fields + ")" + MsSQL.newline;
sql += MsSQL.newline;
sql += "VALUES (" + fieldsAndData.paramPlaceholders + ");SELECT SCOPE_IDENTITY() AS insertId;"; |
What's going to happen if the PK is not an identity, for example, some sort of uuid? |
In my schema the IDENTITY is always the ID. Can this be provided as a configuration option instead to handle these caveats: when triggers are enabled on a table or when your PK is not the IDENTITY on the table? Or can you extend the SCOPE_IDENTITY to return the PK by selecting the row with that ID after an insert (I'd be concerned about performance on this option)? |
+1 |
+1 Switched to @idosh s fork for the time being and all seems to work perfectly. Big thumbs up! |
Hello All, I have the same issue however mssql.js which I have seems to be completely different and I am not sure how resolve error "The target table 'dbo.Test' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause"....... For an instance I've below code in my mssql.js where Output is inserted MsSQL.prototype.buildInsertInto = function(model, fields, options,callback) { |
mssql.js which i have is different than one in this repo.....please suggest a workaround......otherwise we can not go live on production......Thanks in advance |
@raymondfeng Can you do the code review and merge? |
… column data type instead of varchar. loopbackio#21
#21 Fix for Insert into Table with Active Trigger
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
The text was updated successfully, but these errors were encountered: