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

Commit 18114445 by Mick Hansen

Merge pull request #2925 from mbroadst/show-table-query-type

add QueryTypes.SHOWTABLES
2 parents 263ddba0 7b8d0b76
...@@ -123,11 +123,11 @@ module.exports = (function() { ...@@ -123,11 +123,11 @@ module.exports = (function() {
} }
}; };
AbstractQuery.prototype.isShowTableQuery = function() { AbstractQuery.prototype.isShowTablesQuery = function() {
return (this.sql.toLowerCase().indexOf('show tables') === 0); return this.options.type === QueryTypes.SHOWTABLES;
}; };
AbstractQuery.prototype.handleShowTableQuery = function(results) { AbstractQuery.prototype.handleShowTablesQuery = function(results) {
return Utils._.flatten(results.map(function(resultSet) { return Utils._.flatten(results.map(function(resultSet) {
return Utils._.values(resultSet); return Utils._.values(resultSet);
})); }));
......
...@@ -123,8 +123,8 @@ module.exports = (function() { ...@@ -123,8 +123,8 @@ module.exports = (function() {
} }
} }
if (this.isShowTableQuery()) { if (this.isShowTablesQuery()) {
result = this.handleShowTableQuery(data); result = this.handleShowTablesQuery(data);
} else if (this.isShowOrDescribeQuery()) { } else if (this.isShowOrDescribeQuery()) {
result = data; result = data;
if (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0) { if (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0) {
...@@ -157,10 +157,6 @@ module.exports = (function() { ...@@ -157,10 +157,6 @@ module.exports = (function() {
return result; return result;
}; };
Query.prototype.isShowTableQuery = function() {
return (this.sql.toLowerCase().indexOf('select name from sys.tables') === 0);
};
Query.prototype.formatError = function (err) { Query.prototype.formatError = function (err) {
var match; var match;
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'. The duplicate key value is \((.*)\)./); match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'. The duplicate key value is \((.*)\)./);
......
...@@ -75,8 +75,8 @@ module.exports = (function() { ...@@ -75,8 +75,8 @@ module.exports = (function() {
if (this.isSelectQuery()) { if (this.isSelectQuery()) {
result = this.handleSelectQuery(data); result = this.handleSelectQuery(data);
} else if (this.isShowTableQuery()) { } else if (this.isShowTablesQuery()) {
result = this.handleShowTableQuery(data); result = this.handleShowTablesQuery(data);
} else if (this.isShowOrDescribeQuery()) { } else if (this.isShowOrDescribeQuery()) {
result = data; result = data;
......
...@@ -286,11 +286,11 @@ module.exports = (function() { ...@@ -286,11 +286,11 @@ module.exports = (function() {
var self = this; var self = this;
options = Utils._.extend({ options = Utils._.extend({
transaction: null, transaction: null,
raw: true raw: true,
type: QueryTypes.SHOWTABLES
}, options || {}); }, options || {});
var showTablesSql = self.QueryGenerator.showTablesQuery(); var showTablesSql = self.QueryGenerator.showTablesQuery();
return self.sequelize.query(showTablesSql, null, options).then(function(tableNames) { return self.sequelize.query(showTablesSql, null, options).then(function(tableNames) {
return Utils._.flatten(tableNames); return Utils._.flatten(tableNames);
}); });
......
...@@ -6,5 +6,6 @@ module.exports = { ...@@ -6,5 +6,6 @@ module.exports = {
BULKUPDATE: 'BULKUPDATE', BULKUPDATE: 'BULKUPDATE',
BULKDELETE: 'BULKDELETE', BULKDELETE: 'BULKDELETE',
UPSERT: 'UPSERT', UPSERT: 'UPSERT',
VERSION: 'VERSION' VERSION: 'VERSION',
SHOWTABLES: 'SHOWTABLES'
}; };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!