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

Commit fa784c59 by Matt Broadstone

fixed a few more failing cases

  - missed a case for addLimitAndOffset for subqueries with a single model
  - formatResults should return undefined if there is no data
  - there are a few possible error messages in an invalid connection scenario
1 parent 03845fa5
......@@ -1236,10 +1236,16 @@ module.exports = (function() {
if (options.order) {
if (Array.isArray(options.order)) {
options.order.forEach(function(t) {
if (isSubQuery && !(t[0] instanceof Model) && !(t[0].model instanceof Model)) {
subQueryOrder.push(this.quote(t, model));
if (!Array.isArray(t)) {
if (isSubQuery && !(t instanceof Model) && !(t.model instanceof Model)) {
subQueryOrder.push(this.quote(t, model));
}
} else {
if (isSubQuery && !(t[0] instanceof Model) && !(t[0].model instanceof Model)) {
subQueryOrder.push(this.quote(t, model));
}
mainQueryOrder.push(this.quote(t, model));
}
mainQueryOrder.push(this.quote(t, model));
}.bind(this));
} else {
mainQueryOrder.push(options.order);
......
......@@ -113,40 +113,37 @@ module.exports = (function() {
*/
Query.prototype.formatResults = function(data) {
var result = this.callee;
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
}
if (data) {
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
} else if (this.isShowTableQuery()) {
result = this.handleShowTableQuery(data);
} else if (this.isShowOrDescribeQuery()) {
result = data;
if (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0) {
result = {};
data.forEach(function(_result) {
if (_result.Default)
_result.Default = _result.Default.replace('(\'','').replace('\')','').replace(/'/g,'');
result[_result.Name] = {
type: _result.Type.toUpperCase(),
allowNull: (_result.IsNull === 'YES' ? true : false),
defaultValue: _result.Default
};
});
} else if (this.isShowIndexesQuery()) {
result = this.handleShowIndexesQuery(data);
}
} else if (this.isSelectQuery()) {
result = this.handleSelectQuery(data);
} else if (this.isCallQuery()) {
result = data[0];
} else if (this.isBulkUpdateQuery()) {
result = data.length;
} else if (this.isBulkDeleteQuery()){
result = data[0].AFFECTEDROWS;
}
} else if (!result) {
if (this.isShowTableQuery()) {
result = this.handleShowTableQuery(data);
} else if (this.isShowOrDescribeQuery()) {
result = data;
if (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0) {
result = {};
data.forEach(function(_result) {
if (_result.Default)
_result.Default = _result.Default.replace('(\'','').replace('\')','').replace(/'/g,'');
result[_result.Name] = {
type: _result.Type.toUpperCase(),
allowNull: (_result.IsNull === 'YES' ? true : false),
defaultValue: _result.Default
};
});
} else if (this.isShowIndexesQuery()) {
result = this.handleShowIndexesQuery(data);
}
} else if (this.isSelectQuery()) {
result = this.handleSelectQuery(data);
} else if (this.isCallQuery()) {
result = data[0];
} else if (this.isBulkUpdateQuery()) {
result = data.length;
} else if (this.isBulkDeleteQuery()){
result = data[0].AFFECTEDROWS;
}
return result;
......
......@@ -113,23 +113,26 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
.authenticate()
.complete(function(err, result) {
if (dialect === 'mariadb') {
expect(err.message).to.match(/Access denied for user/)
expect(err.message).to.match(/Access denied for user/);
} else if (dialect === 'postgres') {
expect(
err.message.match(/connect ECONNREFUSED/) ||
err.message.match(/invalid port number/)
).to.be.ok
).to.be.ok;
} else if (dialect === 'mssql'){
expect(err.message.match(/ConnectionError: Login failed for user/)).to.be.ok
expect(
err.message.match(/ConnectionError: Login failed for user/) ||
err.message.match(/RangeError: Port should be > 0 and < 65536/)
).to.be.ok;
} else {
expect(err.message).to.match(/connect ECONNREFUSED/)
}
done()
done();
})
})
})
});
});
});
describe('with invalid credentials', function() {
beforeEach(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!