Skip to content

Commit

Permalink
Mssql update query generates invalid syntax (#1777)
Browse files Browse the repository at this point in the history
* Updated mssql update compiler with correct syntax

* Updated failing mssql test

* Updated failing tests to add from

* Third times the charm tests
  • Loading branch information
Ruben Slabbert authored and rhys-vdw committed Dec 6, 2016
1 parent 9e7b57e commit 0ae4f3e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dialects/mssql/query/compiler.js
Expand Up @@ -86,8 +86,8 @@ assign(QueryCompiler_MSSQL.prototype, {
const { returning } = this.single;
return {
sql: this.with() + `update ${top ? top + ' ' : ''}${this.tableName}` +
(join ? ` ${join}` : '') +
' set ' + updates.join(', ') +
(join ? ` from ${this.tableName} ${join}` : '') +
(returning ? ` ${this._returning('update', returning)}` : '') +
(where ? ` ${where}` : '') +
(order ? ` ${order}` : '') +
Expand Down
4 changes: 2 additions & 2 deletions test/unit/query/builder.js
Expand Up @@ -2630,7 +2630,7 @@ describe("QueryBuilder", function() {
bindings: ['foo', 'bar', 1]
},
mssql: {
sql: 'update [users] inner join [orders] on [users].[id] = [orders].[user_id] set [email] = ?, [name] = ? where [users].[id] = ?;select @@rowcount',
sql: 'update [users] set [email] = ?, [name] = ? from [users] inner join [orders] on [users].[id] = [orders].[user_id] where [users].[id] = ?;select @@rowcount',
bindings: ['foo', 'bar', 1]
},
postgres: {
Expand Down Expand Up @@ -3032,7 +3032,7 @@ describe("QueryBuilder", function() {
bindings: ['Boonesville', 1, 5]
},
mssql: {
sql: 'update [tblPerson] inner join [tblPersonData] on [tblPersonData].[PersonId] = [tblPerson].[PersonId] set [tblPerson].[City] = ? where [tblPersonData].[DataId] = ? and [tblPerson].[PersonId] = ?;select @@rowcount',
sql: 'update [tblPerson] set [tblPerson].[City] = ? from [tblPerson] inner join [tblPersonData] on [tblPersonData].[PersonId] = [tblPerson].[PersonId] where [tblPersonData].[DataId] = ? and [tblPerson].[PersonId] = ?;select @@rowcount',
bindings: ['Boonesville', 1, 5]
},
postgres: {
Expand Down

0 comments on commit 0ae4f3e

Please sign in to comment.