Skip to content

Commit

Permalink
Fix unescaped field in MSSQL query generation (sequelize#6686)
Browse files Browse the repository at this point in the history
* Fix unescaped field in MSSQL query generation

* Update changelog.md

* Update changelog.md
  • Loading branch information
Francesco Infante authored and mickhansen committed Oct 12, 2016
1 parent baa187d commit e608bb2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Future
- [FIXED] Issues with `createFunction` and `dropFunction` (PostgresSQL)
- [FIXED] Issue with belongsTo association and foreign keys [#6400](https://github.com/sequelize/sequelize/issues/6400)
- [FIXED] Issue with query generation in MSSQL, an identifier was not escaped [#6686] (https://github.com/sequelize/sequelize/pull/6686)

# 4.0.0-2
- [ADDED] include now supports string as an argument (on top of model/association), string will expand into an association matched literally from Model.associations
Expand Down
2 changes: 1 addition & 1 deletion lib/dialects/mssql/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ var QueryGenerator = {

// enums are a special case
template = attribute.type.toSql();
template += ' CHECK (' + attribute.field + ' IN(' + Utils._.map(attribute.values, function(value) {
template += ' CHECK (' + this.quoteIdentifier(attribute.field) + ' IN(' + Utils._.map(attribute.values, function(value) {
return this.escape(value);
}.bind(this)).join(', ') + '))';
return template;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sql/create-table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe(Support.getTestDialectTeaser('SQL'), function() {
sqlite: 'CREATE TABLE IF NOT EXISTS `foo.users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `mood` TEXT);',
postgres: 'CREATE TABLE IF NOT EXISTS "foo"."users" ("id" SERIAL , "mood" "foo"."enum_users_mood", PRIMARY KEY ("id"));',
mysql: "CREATE TABLE IF NOT EXISTS `foo.users` (`id` INTEGER NOT NULL auto_increment , `mood` ENUM('happy', 'sad'), PRIMARY KEY (`id`)) ENGINE=InnoDB;",
mssql: "IF OBJECT_ID('[foo].[users]', 'U') IS NULL CREATE TABLE [foo].[users] ([id] INTEGER NOT NULL IDENTITY(1,1) , [mood] VARCHAR(255) CHECK (mood IN(N'happy', N'sad')), PRIMARY KEY ([id]));"
mssql: "IF OBJECT_ID('[foo].[users]', 'U') IS NULL CREATE TABLE [foo].[users] ([id] INTEGER NOT NULL IDENTITY(1,1) , [mood] VARCHAR(255) CHECK ([mood] IN(N'happy', N'sad')), PRIMARY KEY ([id]));"
});
});
});
Expand Down

0 comments on commit e608bb2

Please sign in to comment.