MSSQL columnInfo() had hard coded schema name (#1585)

* MSSQL columnInfo() had hard coded schema name

* Change let to const for columnInfo bindings array
This commit is contained in:
Nick Whiteley 2016-07-26 09:00:57 +01:00 committed by wubzz
parent 54563dc8e0
commit f969d5236a
2 changed files with 14 additions and 6 deletions

View File

@ -158,11 +158,19 @@ assign(QueryCompiler_MSSQL.prototype, {
// Compiles a `columnInfo` query.
columnInfo() {
const column = this.single.columnInfo;
const sql =
`select * from information_schema.columns where table_name = ? and table_schema = 'dbo'`;
let sql =`select * from information_schema.columns where table_name = ? and table_catalog = ?`;
const bindings = [this.single.table, this.client.database()];
if (this.single.schema) {
sql += ' and table_schema = ?';
bindings.push(this.single.schema);
} else {
sql += ` and table_schema = 'dbo'`;
}
return {
sql,
bindings: [this.single.table],
bindings: bindings,
output(resp) {
const out = resp.reduce(function(columns, val) {
columns[val.COLUMN_NAME] = {

View File

@ -121,8 +121,8 @@ module.exports = function(knex) {
}
);
tester('mssql',
'select * from information_schema.columns where table_name = ? and table_schema = \'dbo\'',
['datatype_test'], {
'select * from information_schema.columns where table_name = ? and table_catalog = ? and table_schema = \'dbo\'',
['datatype_test', 'knex_test'], {
"enum_value": {
"defaultValue": null,
"maxLength": 100,
@ -173,7 +173,7 @@ module.exports = function(knex) {
}
);
tester('mssql',
'select * from information_schema.columns where table_name = ? and table_schema = \'dbo\'',
'select * from information_schema.columns where table_name = ? and table_catalog = ? and table_schema = \'dbo\'',
null, {
"defaultValue": null,
"maxLength": null,