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

Commit 56bbf926 by Mick Hansen

Merge pull request #1686 from joshperry/pg-describe-notable-error

Error on empty result from table definition queries
2 parents 1fa99b9d 7cc4f96b
...@@ -302,7 +302,7 @@ module.exports = (function() { ...@@ -302,7 +302,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 })
}, },
...@@ -319,10 +319,11 @@ module.exports = (function() { ...@@ -319,10 +319,11 @@ module.exports = (function() {
describeTableQuery: function(tableName, schema, schemaDelimiter) { describeTableQuery: function(tableName, schema, schemaDelimiter) {
var options = {} var options = {}
options.schema = schema || null options.schema = schema
options.schemaDelimiter = schemaDelimiter || null options.schemaDelimiter = schemaDelimiter
options.quoted = false;
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})})
}, },
...@@ -369,11 +370,11 @@ module.exports = (function() { ...@@ -369,11 +370,11 @@ module.exports = (function() {
}) })
}, },
startTransactionQuery: function(options) { startTransactionQuery: function() {
return "BEGIN TRANSACTION;" return "BEGIN TRANSACTION;"
}, },
setAutocommitQuery: function(value) { setAutocommitQuery: function() {
return "-- SQLite does not support SET autocommit." return "-- SQLite does not support SET autocommit."
}, },
...@@ -409,7 +410,8 @@ module.exports = (function() { ...@@ -409,7 +410,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 })
} }
} }
......
...@@ -286,7 +286,16 @@ module.exports = (function() { ...@@ -286,7 +286,16 @@ module.exports = (function() {
var sql = this.QueryGenerator.describeTableQuery(tableName, schema, schemaDelimiter) var sql = this.QueryGenerator.describeTableQuery(tableName, schema, schemaDelimiter)
return this.sequelize.query(sql, null, { raw: true }) return this.sequelize.query(sql, null, { raw: true }).then(function(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).
if(Utils._.isEmpty(data)) {
return Promise.reject('No description found for "' + tableName + '" table. Check the table name and schema; remember, they _are_ case sensitive.')
} else {
return Promise.resolve(data)
}
})
} }
QueryInterface.prototype.addColumn = function(tableName, attributeName, dataTypeOrOptions) { QueryInterface.prototype.addColumn = function(tableName, attributeName, dataTypeOrOptions) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!