Closed nyabutid closed 7 years ago
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) { var stmt = this.invokeSuper('buildInsertInto', model, fields, options); var idName = this.idName(model); if (idName) { stmt.merge(MsSQL.newline + 'OUTPUT INSERTED.' + this.columnEscaped(model, idName) + ' AS insertId'); } return stmt; };
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?
https://github.com/strongloop/loopback-connector-mssql/pull/70
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 CODEOWNERS
file at the top-level of this repository.