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

Commit ea46b9c7 by Mick Hansen

Merge pull request #1691 from joshperry/1.7.0-describe-no-table-error

1.7 Error on empty result from table definition queries
2 parents 8cfd580b 87420b47
...@@ -31,7 +31,7 @@ module.exports = (function() { ...@@ -31,7 +31,7 @@ module.exports = (function() {
return tableName return tableName
} }
return this.quoteIdentifier(schema) + (!schemaDelimiter ? '.' : schemaDelimiter) + this.quoteIdentifier(tableName) return this.quoteIdentifier(schema + (!schemaDelimiter ? '.' : schemaDelimiter) + tableName)
}, },
createSchema: function() { createSchema: function() {
...@@ -325,7 +325,7 @@ module.exports = (function() { ...@@ -325,7 +325,7 @@ module.exports = (function() {
}, },
showIndexQuery: function(tableName) { showIndexQuery: function(tableName) {
var sql = "PRAGMA INDEX_LIST('<%= tableName %>')" var sql = "PRAGMA INDEX_LIST(<%= tableName %>)"
return Utils._.template(sql, { tableName: tableName }) return Utils._.template(sql, { tableName: tableName })
}, },
...@@ -345,7 +345,7 @@ module.exports = (function() { ...@@ -345,7 +345,7 @@ module.exports = (function() {
options.schema = schema || null options.schema = schema || null
options.schemaDelimiter = schemaDelimiter || null options.schemaDelimiter = schemaDelimiter || null
var sql = "PRAGMA TABLE_INFO('<%= tableName %>');" 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: tableName, options: options})})
}, },
...@@ -440,7 +440,8 @@ module.exports = (function() { ...@@ -440,7 +440,8 @@ module.exports = (function() {
* @return {String} The generated sql query. * @return {String} The generated sql query.
*/ */
getForeignKeysQuery: function(tableName, schemaName) { getForeignKeysQuery: function(tableName, schemaName) {
return "PRAGMA foreign_key_list(\"" + tableName + "\")" var sql = "PRAGMA foreign_key_list(<%= tableName %>)"
return Utils._.template(sql, { tableName: tableName })
} }
} }
......
...@@ -369,7 +369,14 @@ module.exports = (function() { ...@@ -369,7 +369,14 @@ module.exports = (function() {
} }
self.sequelize.query(sql, null, { raw: true }).success(function(data) { self.sequelize.query(sql, null, { raw: true }).success(function(data) {
emitter.emit('success', data) if(Utils._.isEmpty(data)) {
// If no data is returned from the query, then the table name may be wrong.
// Query generators that use information_schema for retrieving table info will just return an empty result set,
// it will not throw an error like built-ins do (e.g. DESCRIBE on MySql).
emitter.emit('error', 'No description found for "' + tableName + '" table. Check the table name and schema; remember, they _are_ case sensitive.')
} else {
emitter.emit('success', data)
}
}).error(function(err) { }).error(function(err) {
emitter.emit('error', err) emitter.emit('error', err)
}).on('sql', function(sql) { }).on('sql', function(sql) {
......
...@@ -1504,7 +1504,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1504,7 +1504,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(UserSpecial.indexOf('INSERT INTO "special"."UserSpecials"')).to.be.above(-1) expect(UserSpecial.indexOf('INSERT INTO "special"."UserSpecials"')).to.be.above(-1)
expect(UserPublic.indexOf('INSERT INTO "UserPublics"')).to.be.above(-1) expect(UserPublic.indexOf('INSERT INTO "UserPublics"')).to.be.above(-1)
} else if (dialect === "sqlite") { } else if (dialect === "sqlite") {
expect(self.UserSpecialSync.getTableName()).to.equal('`special`.`UserSpecials`'); expect(self.UserSpecialSync.getTableName()).to.equal('`special.UserSpecials`');
expect(UserSpecial.indexOf('INSERT INTO `special.UserSpecials`')).to.be.above(-1) expect(UserSpecial.indexOf('INSERT INTO `special.UserSpecials`')).to.be.above(-1)
expect(UserPublic.indexOf('INSERT INTO `UserPublics`')).to.be.above(-1) expect(UserPublic.indexOf('INSERT INTO `UserPublics`')).to.be.above(-1)
} else { } else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!