Skip to content

Commit 1bf9ae1

Browse files
committed
- Changed the parameter placeholder from ? to @xxx where xxx is the index of the parameter (1 based). The .NET SQL Server adaptor does not support the question mark.
1 parent 0370025 commit 1bf9ae1

15 files changed

Lines changed: 50 additions & 46 deletions

lib/dialect/sqlserver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SqlServer.prototype._quoteCharacter = '[';
2222
SqlServer.prototype._arrayAggFunctionName = '';
2323

2424
SqlServer.prototype._getParameterPlaceholder = function(index, value) {
25-
return '?';
25+
return '@' + index;
2626
};
2727

2828
SqlServer.prototype.visitBinary = function(binary) {

test/dialects/alias-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Harness.test({
3939
string: 'SELECT (`customer`.`name` + `customer`.`age`) AS `nameAndAge` FROM `customer` WHERE ((`customer`.`age` > 10) AND (`customer`.`age` < 20))'
4040
},
4141
sqlserver: {
42-
text : 'SELECT ([customer].[name] + [customer].[age]) AS [nameAndAge] FROM [customer] WHERE (([customer].[age] > ?) AND ([customer].[age] < ?))',
42+
text : 'SELECT ([customer].[name] + [customer].[age]) AS [nameAndAge] FROM [customer] WHERE (([customer].[age] > @1) AND ([customer].[age] < @2))',
4343
string: 'SELECT ([customer].[name] + [customer].[age]) AS [nameAndAge] FROM [customer] WHERE (([customer].[age] > 10) AND ([customer].[age] < 20))'
4444
},
4545
params: [10, 20]
@@ -60,7 +60,7 @@ Harness.test({
6060
string: 'SELECT (`customer`.`age` BETWEEN 10 AND 20) AS `ageBetween` FROM `customer`'
6161
},
6262
sqlserver: {
63-
text : 'SELECT ([customer].[age] BETWEEN ? AND ?) AS [ageBetween] FROM [customer]',
63+
text : 'SELECT ([customer].[age] BETWEEN @1 AND @2) AS [ageBetween] FROM [customer]',
6464
string: 'SELECT ([customer].[age] BETWEEN 10 AND 20) AS [ageBetween] FROM [customer]'
6565
},
6666
params: [10, 20]

test/dialects/binary-clause-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Harness.test({
4040
string: 'SELECT (`post`.`content` + \'!\') FROM `post` WHERE (`post`.`userId` IN (SELECT `customer`.`id` FROM `customer`))'
4141
},
4242
sqlserver: {
43-
text : 'SELECT ([post].[content] + ?) FROM [post] WHERE ([post].[userId] IN (SELECT [customer].[id] FROM [customer]))',
43+
text : 'SELECT ([post].[content] + @1) FROM [post] WHERE ([post].[userId] IN (SELECT [customer].[id] FROM [customer]))',
4444
string: 'SELECT ([post].[content] + \'!\') FROM [post] WHERE ([post].[userId] IN (SELECT [customer].[id] FROM [customer]))'
4545
},
4646
params: ['!']
@@ -61,7 +61,7 @@ Harness.test({
6161
string: 'SELECT ((`post`.`id` + \': \') + `post`.`content`) FROM `post` WHERE (`post`.`userId` NOT IN (SELECT `customer`.`id` FROM `customer`))'
6262
},
6363
sqlserver: {
64-
text : 'SELECT (([post].[id] + ?) + [post].[content]) FROM [post] WHERE ([post].[userId] NOT IN (SELECT [customer].[id] FROM [customer]))',
64+
text : 'SELECT (([post].[id] + @1) + [post].[content]) FROM [post] WHERE ([post].[userId] NOT IN (SELECT [customer].[id] FROM [customer]))',
6565
string: 'SELECT (([post].[id] + \': \') + [post].[content]) FROM [post] WHERE ([post].[userId] NOT IN (SELECT [customer].[id] FROM [customer]))'
6666
},
6767
params: [': ']

test/dialects/cast-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Harness.test({
106106
string: 'SELECT `customer`.`name` FROM `customer` WHERE ((CAST(`customer`.`age` AS int) + 100) = 150)'
107107
},
108108
sqlserver: {
109-
text : 'SELECT [customer].[name] FROM [customer] WHERE ((CAST([customer].[age] AS int) + ?) = ?)',
109+
text : 'SELECT [customer].[name] FROM [customer] WHERE ((CAST([customer].[age] AS int) + @1) = @2)',
110110
string: 'SELECT [customer].[name] FROM [customer] WHERE ((CAST([customer].[age] AS int) + 100) = 150)'
111111
},
112112
params: [100, 150]

test/dialects/clause-ordering-tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Harness.test({
4444
string: 'SELECT `user`.`id` FROM `user` WHERE (`user`.`name` = \'\')'
4545
},
4646
sqlserver: {
47-
text : 'SELECT [user].[id] FROM [user] WHERE ([user].[name] = ?)',
47+
text : 'SELECT [user].[id] FROM [user] WHERE ([user].[name] = @1)',
4848
string: 'SELECT [user].[id] FROM [user] WHERE ([user].[name] = \'\')'
4949
},
5050
params: ['']
@@ -71,7 +71,7 @@ Harness.test({
7171
string: 'SELECT `user`.`name`, `post`.`content` FROM `user` INNER JOIN `post` ON (`user`.`id` = `post`.`userId`) WHERE (`user`.`name` = \'\')'
7272
},
7373
sqlserver: {
74-
text : 'SELECT [user].[name], [post].[content] FROM [user] INNER JOIN [post] ON ([user].[id] = [post].[userId]) WHERE ([user].[name] = ?)',
74+
text : 'SELECT [user].[name], [post].[content] FROM [user] INNER JOIN [post] ON ([user].[id] = [post].[userId]) WHERE ([user].[name] = @1)',
7575
string: 'SELECT [user].[name], [post].[content] FROM [user] INNER JOIN [post] ON ([user].[id] = [post].[userId]) WHERE ([user].[name] = \'\')'
7676
},
7777
params: ['']
@@ -95,7 +95,7 @@ Harness.test({
9595
string: 'SELECT `user`.`id` FROM `user` WHERE (`user`.`name` = \'\')'
9696
},
9797
sqlserver: {
98-
text : 'SELECT [user].[id] FROM [user] WHERE ([user].[name] = ?)',
98+
text : 'SELECT [user].[id] FROM [user] WHERE ([user].[name] = @1)',
9999
string: 'SELECT [user].[id] FROM [user] WHERE ([user].[name] = \'\')'
100100
},
101101
params: ['']

test/dialects/delete-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Harness.test({
1818
string: 'DELETE FROM `post` WHERE (`post`.`content` = \'hello\'\'s world\')'
1919
},
2020
sqlserver: {
21-
text : 'DELETE FROM [post] WHERE ([post].[content] = ?)',
21+
text : 'DELETE FROM [post] WHERE ([post].[content] = @1)',
2222
string: "DELETE FROM [post] WHERE ([post].[content] = 'hello''s world')"
2323
},
2424
params: ["hello's world"]
@@ -41,7 +41,7 @@ Harness.test({
4141
string: 'DELETE FROM `post` WHERE (`post`.`content` = \'\')'
4242
},
4343
sqlserver: {
44-
text : 'DELETE FROM [post] WHERE ([post].[content] = ?)',
44+
text : 'DELETE FROM [post] WHERE ([post].[content] = @1)',
4545
string: "DELETE FROM [post] WHERE ([post].[content] = '')"
4646
},
4747
params: ['']
@@ -64,7 +64,7 @@ Harness.test({
6464
string: 'DELETE FROM `post` WHERE (`post`.`content` = \'\')'
6565
},
6666
sqlserver: {
67-
text : 'DELETE FROM [post] WHERE ([post].[content] = ?)',
67+
text : 'DELETE FROM [post] WHERE ([post].[content] = @1)',
6868
string: "DELETE FROM [post] WHERE ([post].[content] = '')"
6969
},
7070
params: ['']
@@ -87,7 +87,7 @@ Harness.test({
8787
string: 'DELETE FROM `post` WHERE ((`post`.`content` = \'\') OR (`post`.`content` IS NULL))'
8888
},
8989
sqlserver: {
90-
text : 'DELETE FROM [post] WHERE (([post].[content] = ?) OR ([post].[content] IS NULL))',
90+
text : 'DELETE FROM [post] WHERE (([post].[content] = @1) OR ([post].[content] IS NULL))',
9191
string: "DELETE FROM [post] WHERE (([post].[content] = '') OR ([post].[content] IS NULL))"
9292
},
9393
params: ['']

test/dialects/having-tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Harness.test({
1818
string: 'SELECT `post`.`userId`, COUNT(`post`.`content`) AS `content_count` FROM `post` GROUP BY `post`.`userId` HAVING (`post`.`userId` > 10)'
1919
},
2020
sqlserver : {
21-
text : 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > ?)',
21+
text : 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > @1)',
2222
string: 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > 10)'
2323
},
2424
params: [10]
@@ -39,7 +39,7 @@ Harness.test({
3939
string: 'SELECT `post`.`userId`, COUNT(`post`.`content`) AS `content_count` FROM `post` GROUP BY `post`.`userId` HAVING (`post`.`userId` > 10) AND (`post`.`userId` < 100)'
4040
},
4141
sqlserver : {
42-
text : 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > ?) AND ([post].[userId] < ?)',
42+
text : 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > @1) AND ([post].[userId] < @2)',
4343
string: 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > 10) AND ([post].[userId] < 100)'
4444
},
4545
params: [10, 100]
@@ -60,7 +60,7 @@ Harness.test({
6060
string: 'SELECT `post`.`userId`, COUNT(`post`.`content`) AS `content_count` FROM `post` GROUP BY `post`.`userId` HAVING (`post`.`userId` > 10) AND (`post`.`userId` < 100)'
6161
},
6262
sqlserver : {
63-
text : 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > ?) AND ([post].[userId] < ?)',
63+
text : 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > @1) AND ([post].[userId] < @2)',
6464
string: 'SELECT [post].[userId], COUNT([post].[content]) AS [content_count] FROM [post] GROUP BY [post].[userId] HAVING ([post].[userId] > 10) AND ([post].[userId] < 100)'
6565
},
6666
params: [10, 100]

test/dialects/namespace-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Harness.test({
6464
string: 'SELECT `u`.`name` FROM `user` AS `u` INNER JOIN `post` AS `p` ON ((`u`.`id` = `p`.`userId`) AND (`p`.`id` = 3))'
6565
},
6666
sqlserver: {
67-
text : 'SELECT [u].[name] FROM [user] AS [u] INNER JOIN [post] AS [p] ON (([u].[id] = [p].[userId]) AND ([p].[id] = ?))',
67+
text : 'SELECT [u].[name] FROM [user] AS [u] INNER JOIN [post] AS [p] ON (([u].[id] = [p].[userId]) AND ([p].[id] = @1))',
6868
string: 'SELECT [u].[name] FROM [user] AS [u] INNER JOIN [post] AS [p] ON (([u].[id] = [p].[userId]) AND ([p].[id] = 3))'
6969
},
7070
params: [3]

test/dialects/shortcut-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Harness.test({
4141
string: 'SELECT * FROM `user` WHERE (`user`.`name` = 3)'
4242
},
4343
sqlserver: {
44-
text : 'SELECT * FROM [user] WHERE ([user].[name] = ?)',
44+
text : 'SELECT * FROM [user] WHERE ([user].[name] = @1)',
4545
string: 'SELECT * FROM [user] WHERE ([user].[name] = 3)'
4646
},
4747
params: [3]
@@ -62,7 +62,7 @@ Harness.test({
6262
string: 'SELECT * FROM `user` WHERE ((`user`.`name` = 3) AND (`user`.`id` = 1))'
6363
},
6464
sqlserver: {
65-
text : 'SELECT * FROM [user] WHERE (([user].[name] = ?) AND ([user].[id] = ?))',
65+
text : 'SELECT * FROM [user] WHERE (([user].[name] = @1) AND ([user].[id] = @2))',
6666
string: 'SELECT * FROM [user] WHERE (([user].[name] = 3) AND ([user].[id] = 1))'
6767
},
6868
params: [3, 1]
@@ -105,7 +105,7 @@ Harness.test({
105105
string: 'SELECT `post`.`content` FROM `post` WHERE (`post`.`userId` = 1)'
106106
},
107107
sqlserver: {
108-
text : 'SELECT [post].[content] FROM [post] WHERE ([post].[userId] = ?)',
108+
text : 'SELECT [post].[content] FROM [post] WHERE ([post].[userId] = @1)',
109109
string: 'SELECT [post].[content] FROM [post] WHERE ([post].[userId] = 1)'
110110
},
111111
params: [1]
@@ -130,7 +130,7 @@ Harness.test({
130130
string: 'SELECT * FROM `post` WHERE (((`post`.`content` IS NULL) OR (`post`.`content` = \'\')) AND (`post`.`userId` = 1))'
131131
},
132132
sqlserver: {
133-
text : 'SELECT * FROM [post] WHERE ((([post].[content] IS NULL) OR ([post].[content] = ?)) AND ([post].[userId] = ?))',
133+
text : 'SELECT * FROM [post] WHERE ((([post].[content] IS NULL) OR ([post].[content] = @1)) AND ([post].[userId] = @2))',
134134
string: 'SELECT * FROM [post] WHERE ((([post].[content] IS NULL) OR ([post].[content] = \'\')) AND ([post].[userId] = 1))'
135135
},
136136
params: ['', 1]

test/dialects/subquery-tests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Harness.test({
2323
text : '(`user`.`name` IN (SELECT `customer`.`name` FROM `customer` WHERE (`user`.`name` IN (SELECT `customer`.`name` FROM `customer` WHERE (`user`.`name` LIKE ?)))))',
2424
string: '(`user`.`name` IN (SELECT `customer`.`name` FROM `customer` WHERE (`user`.`name` IN (SELECT `customer`.`name` FROM `customer` WHERE (`user`.`name` LIKE \'%HELLO%\')))))'
2525
},
26+
sqlserver: {
27+
text : '([user].[name] IN (SELECT [customer].[name] FROM [customer] WHERE ([user].[name] IN (SELECT [customer].[name] FROM [customer] WHERE ([user].[name] LIKE @1)))))',
28+
string: '([user].[name] IN (SELECT [customer].[name] FROM [customer] WHERE ([user].[name] IN (SELECT [customer].[name] FROM [customer] WHERE ([user].[name] LIKE \'%HELLO%\')))))'
29+
},
2630
params: ['%HELLO%']
2731
});
2832

0 commit comments

Comments
 (0)