不要怂,就是干,撸起袖子干!

Commit 4fe4b37b by Mick Hansen

fix(query-interface/generator): make sure index queries are properly escapes (closes #1943)

1 parent ce7865c0
......@@ -258,15 +258,15 @@ module.exports = (function() {
return Utils._.compact([
'CREATE', options.indicesType, 'INDEX', options.indexName,
(options.indexType ? ('USING ' + options.indexType) : undefined),
'ON', tableName, '(' + transformedAttributes.join(', ') + ')',
'ON', this.quoteIdentifiers(tableName), '(' + transformedAttributes.join(', ') + ')',
(options.parser ? 'WITH PARSER ' + options.parser : undefined)
]).join(' ');
},
showIndexQuery: function(tableName, options) {
var sql = 'SHOW INDEX FROM `<%= tableName %>`<%= options %>';
var sql = 'SHOW INDEX FROM <%= tableName %> <%= options %>';
return Utils._.template(sql)({
tableName: tableName,
tableName: this.quoteIdentifiers(tableName),
options: (options || {}).database ? ' FROM `' + options.database + '`' : ''
});
},
......@@ -279,7 +279,7 @@ module.exports = (function() {
indexName = Utils._.underscored(tableName + '_' + indexNameOrAttributes.join('_'));
}
return Utils._.template(sql)({ tableName: tableName, indexName: indexName });
return Utils._.template(sql)({ tableName: this.quoteIdentifiers(tableName), indexName: indexName });
},
attributesToSQL: function(attributes) {
......
......@@ -307,7 +307,7 @@ module.exports = (function() {
showIndexQuery: function(tableName) {
var sql = "PRAGMA INDEX_LIST(<%= tableName %>)";
return Utils._.template(sql, { tableName: tableName });
return Utils._.template(sql, { tableName: this.quoteIdentifiers(tableName) });
},
removeIndexQuery: function(tableName, indexNameOrAttributes) {
......@@ -318,7 +318,7 @@ module.exports = (function() {
indexName = Utils._.underscored(tableName + '_' + indexNameOrAttributes.join('_'));
}
return Utils._.template(sql, { tableName: tableName, indexName: indexName });
return Utils._.template(sql, { tableName: this.quoteIdentifiers(tableName), indexName: indexName });
},
describeTableQuery: function(tableName, schema, schemaDelimiter) {
......@@ -328,7 +328,7 @@ module.exports = (function() {
options.quoted = false;
var sql = "PRAGMA TABLE_INFO(<%= tableName %>);";
return Utils._.template(sql, { tableName: this.addSchema({tableName: tableName, options: options})});
return Utils._.template(sql, { tableName: this.addSchema({tableName: this.quoteIdentifiers(tableName), options: options})});
},
removeColumnQuery: function(tableName, attributes) {
......
......@@ -68,8 +68,8 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
describe('indexes', function() {
beforeEach(function(done) {
var self = this
this.queryInterface.dropTable('Users').success(function() {
self.queryInterface.createTable('Users', {
this.queryInterface.dropTable('Group').success(function() {
self.queryInterface.createTable('Group', {
username: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN,
from: DataTypes.STRING
......@@ -82,19 +82,19 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
it('adds, reads and removes an index to the table', function(done) {
var self = this
this.queryInterface.addIndex('Users', ['username', 'isAdmin']).complete(function(err) {
this.queryInterface.addIndex('Group', ['username', 'isAdmin']).complete(function(err) {
expect(err).to.be.null
self.queryInterface.showIndex('Users').complete(function(err, indexes) {
self.queryInterface.showIndex('Group').complete(function(err, indexes) {
expect(err).to.be.null
var indexColumns = _.uniq(indexes.map(function(index) { return index.name }))
expect(indexColumns).to.include('users_username_is_admin')
expect(indexColumns).to.include('group_username_is_admin')
self.queryInterface.removeIndex('Users', ['username', 'isAdmin']).complete(function(err) {
self.queryInterface.removeIndex('Group', ['username', 'isAdmin']).complete(function(err) {
expect(err).to.be.null
self.queryInterface.showIndex('Users').complete(function(err, indexes) {
self.queryInterface.showIndex('Group').complete(function(err, indexes) {
expect(err).to.be.null
indexColumns = _.uniq(indexes.map(function(index) { return index.name }))
......@@ -107,14 +107,10 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
})
})
it('does not fail on reserved keywords', function (done) {
this.queryInterface.addIndex('Users', ['from']).done(function(err) {
expect(err).to.be.null
done()
})
})
})
it('does not fail on reserved keywords', function () {
return this.queryInterface.addIndex('Group', ['from']);
});;
});
describe('describeTable', function() {
it('reads the metadata of the table', function(done) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!