Skip to content

Commit c90f044

Browse files
authored
Merge pull request #398 from danrzeppa/dan-mssqlconcat
Override for Microsoft SQL Server concatenation operator.
2 parents 08940f9 + 845e4cc commit c90f044

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

lib/dialect/mssql.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Mssql.prototype.visitBinary = function(binary) {
4848
return [text];
4949
}
5050

51+
if(binary.operator === '||'){
52+
return ['(' + this.visit(binary.left) + ' + ' + this.visit(binary.right) + ')'];
53+
}
54+
5155
if (!isRightSideArray(binary)){
5256
return Mssql.super_.prototype.visitBinary.call(this, binary);
5357
}

test/dialects/value-expression-tests.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,46 @@ Harness.test({
114114
query: post.select(post.id).where(post.content.equals(new Buffer('test'))),
115115
pg: {
116116
text : 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = $1)',
117-
string: 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = \'\\x74657374\')',
117+
string: 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = \'\\x74657374\')'
118118
},
119119
sqlite: {
120120
text : 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = $1)',
121-
string: 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = x\'74657374\')',
121+
string: 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = x\'74657374\')'
122122
},
123123
mysql: {
124124
text : 'SELECT `post`.`id` FROM `post` WHERE (`post`.`content` = ?)',
125-
string: 'SELECT `post`.`id` FROM `post` WHERE (`post`.`content` = x\'74657374\')',
125+
string: 'SELECT `post`.`id` FROM `post` WHERE (`post`.`content` = x\'74657374\')'
126126
},
127127
oracle: {
128128
text : 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = :1)',
129-
string: 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = utl_raw.cast_to_varchar2(hextoraw(\'74657374\')))',
129+
string: 'SELECT "post"."id" FROM "post" WHERE ("post"."content" = utl_raw.cast_to_varchar2(hextoraw(\'74657374\')))'
130130
},
131131
params: [new Buffer('test')]
132132
});
133133

134+
// concat tests
135+
Harness.test({
136+
query: post.select(post.content.concat(post.tags)),
137+
pg: {
138+
text : 'SELECT ("post"."content" || "post"."tags") FROM "post"',
139+
string: 'SELECT ("post"."content" || "post"."tags") FROM "post"'
140+
},
141+
sqlite: {
142+
text : 'SELECT ("post"."content" || "post"."tags") FROM "post"',
143+
string: 'SELECT ("post"."content" || "post"."tags") FROM "post"'
144+
},
145+
mysql: {
146+
text : 'SELECT (`post`.`content` || `post`.`tags`) FROM `post`',
147+
string: 'SELECT (`post`.`content` || `post`.`tags`) FROM `post`'
148+
},
149+
mssql: {
150+
text : 'SELECT ([post].[content] + [post].[tags]) FROM [post]',
151+
string: 'SELECT ([post].[content] + [post].[tags]) FROM [post]'
152+
},
153+
oracle: {
154+
text : 'SELECT ("post"."content" || "post"."tags") FROM "post"',
155+
string: 'SELECT ("post"."content" || "post"."tags") FROM "post"'
156+
},
157+
params: []
158+
});
159+

0 commit comments

Comments
 (0)