-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix schema parse error when using reserved keys as table names (#881)
* bracketed name for reserved words as table name * add test * add tests * fix csx test * enable test only for csharp * fix TableNotPresentTest * revert GetUserTableIdAsync change * refactor GetUserTableIdAsync * comment out Java test * refactor code to use SqlObject
- Loading branch information
Showing
20 changed files
with
335 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Extensions.Sql; | ||
|
||
namespace DotnetIsolatedTests | ||
{ | ||
public static class ReservedTableNameTrigger | ||
{ | ||
/// <summary> | ||
/// Used in verification of the trigger function execution on table with reserved keys as name. | ||
/// </summary> | ||
[Function(nameof(ReservedTableNameTrigger))] | ||
public static void Run( | ||
[SqlTrigger("[dbo].[User]", "SqlConnectionString")] | ||
IReadOnlyList<SqlChange<User>> changes, | ||
FunctionContext context) | ||
{ | ||
ILogger logger = context.GetLogger("ReservedTableNameTrigger"); | ||
logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes)); | ||
} | ||
} | ||
|
||
public class User | ||
{ | ||
public string UserName { get; set; } | ||
public int UserId { get; set; } | ||
public string FullName { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj is User) | ||
{ | ||
var that = obj as User; | ||
return this.UserId == that.UserId && this.UserName == that.UserName && this.FullName == that.FullName; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DROP TABLE IF EXISTS [dbo].[User]; | ||
|
||
CREATE TABLE [dbo].[User] ( | ||
[UserId] [int] NOT NULL PRIMARY KEY, | ||
[UserName] [nvarchar](50) NOT NULL, | ||
[FullName] [nvarchar](max) NULL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Sql.Tests.Integration | ||
{ | ||
public static class ReservedTableNameTrigger | ||
{ | ||
/// <summary> | ||
/// Used in verification of the trigger function execution on table with reserved keys as name. | ||
/// </summary> | ||
[FunctionName(nameof(ReservedTableNameTrigger))] | ||
public static void Run( | ||
[SqlTrigger("[dbo].[User]", "SqlConnectionString")] | ||
IReadOnlyList<SqlChange<User>> changes, | ||
ILogger logger) | ||
{ | ||
// The output is used to inspect the trigger binding parameter in test methods. | ||
logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes)); | ||
} | ||
} | ||
|
||
public class User | ||
{ | ||
public string UserName { get; set; } | ||
public int UserId { get; set; } | ||
public string FullName { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj is User) | ||
{ | ||
var that = obj as User; | ||
return this.UserId == that.UserId && this.UserName == that.UserName && this.FullName == that.FullName; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/Integration/test-csx/ReservedTableNameTrigger/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "changes", | ||
"type": "sqlTrigger", | ||
"direction": "in", | ||
"tableName": "[dbo].[User]", | ||
"connectionStringSetting": "SqlConnectionString" | ||
} | ||
], | ||
"disabled": false | ||
} |
32 changes: 32 additions & 0 deletions
32
test/Integration/test-csx/ReservedTableNameTrigger/run.csx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#r "Newtonsoft.Json" | ||
#r "Microsoft.Azure.WebJobs.Extensions.Sql" | ||
|
||
using System.Net; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Primitives; | ||
using Newtonsoft.Json; | ||
using Microsoft.Azure.WebJobs.Extensions.Sql; | ||
|
||
public static void Run(IReadOnlyList<SqlChange<User>> changes, ILogger log) | ||
{ | ||
// The output is used to inspect the trigger binding parameter in test methods. | ||
log.LogInformation("SQL Changes: " + Microsoft.Azure.WebJobs.Extensions.Sql.Utils.JsonSerializeObject(changes)); | ||
} | ||
|
||
public class User | ||
{ | ||
public string UserName { get; set; } | ||
public int UserId { get; set; } | ||
public string FullName { get; set; } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (obj is User) | ||
{ | ||
var that = obj as User; | ||
return this.UserId == that.UserId && this.UserName == that.UserName && this.FullName == that.FullName; | ||
} | ||
|
||
return false; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test/Integration/test-java/src/main/java/com/function/Common/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.function.Common; | ||
|
||
public class User { | ||
private int UserId; | ||
private String UserName; | ||
private String FullName; | ||
|
||
public User(int userId, String userName, String fullName) { | ||
UserId = userId; | ||
UserName = userName; | ||
FullName = fullName; | ||
} | ||
|
||
public int getUserId() { | ||
return UserId; | ||
} | ||
|
||
public String getUserName() { | ||
return UserName; | ||
} | ||
|
||
public String getFullName() { | ||
return FullName; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/Integration/test-java/src/main/java/com/function/ReservedTableNameTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.function; | ||
|
||
import com.function.Common.User; | ||
import com.google.gson.Gson; | ||
import com.microsoft.azure.functions.ExecutionContext; | ||
import com.microsoft.azure.functions.annotation.FunctionName; | ||
import com.microsoft.azure.functions.sql.annotation.SQLTrigger; | ||
|
||
import java.util.logging.Level; | ||
|
||
public class ReservedTableNameTrigger { | ||
@FunctionName("ReservedTableNameTrigger") | ||
public void run( | ||
@SQLTrigger( | ||
name = "changes", | ||
tableName = "[dbo].[User]", | ||
connectionStringSetting = "SqlConnectionString") | ||
User[] changes, | ||
ExecutionContext context) throws Exception { | ||
|
||
context.getLogger().log(Level.INFO, "SQL Changes: " + new Gson().toJson(changes)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/Integration/test-js/ReservedTableNameTrigger/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "changes", | ||
"type": "sqlTrigger", | ||
"direction": "in", | ||
"tableName": "[dbo].[User]", | ||
"connectionStringSetting": "SqlConnectionString" | ||
} | ||
], | ||
"disabled": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
module.exports = async function (context, changes) { | ||
context.log(`SQL Changes: ${JSON.stringify(changes)}`) | ||
} |
Oops, something went wrong.