Azure 逻辑应用中 SQL 列名称的 URI 编码
URI encoding for SQL column names in Azure Logic Apps
我有许多从根本上执行以下操作的逻辑应用程序:
在时间触发器上,一组 SQL 存储过程被调用,然后是一系列 Select 语句 运行,这些被传送到 CSV table 然后通过电子邮件发送给报告收件人。
该过程在一个问题上运行良好 - SQL 中的许多列中都有空格。
当我在 SQL 中 运行 a select [column 1] from table
时,它工作正常。
当我从逻辑应用程序中 运行 相同 select - 输出已修改为我相信 URI 编码示例:
Column_x0020_1
result1
result2
result3
etc.
当我 运行 调试时,我看到这是在执行 SQL 查询的输出中生成的,而不是在 CSV table 的创建中生成的,我没有看不到任何选项来转义空格以使它们不以 URI 格式编码或以编程方式将 URI 编码列 names/data 更改为 'normal' 编码。
所以请帮忙?
您可以使用下面的表达式将URI编码的列名转换为普通格式
replace(string(body('Execute_a_SQL_query_(V2)')),'_x0020_',' ')
这里是示例输出以供参考
- 使用 compose 将 URI 编码的列名称移除为普通名称
正在更新逻辑应用程序代码:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@json(replace(string(body('Execute_a_SQL_query_(V2)')),'_x0020_',' '))",
"runAfter": {
"Execute_a_SQL_query_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Create_CSV_table": {
"inputs": {
"format": "CSV",
"from": "@variables('array')"
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Table"
},
"Execute_a_SQL_query_(V2)": {
"inputs": {
"body": {
"query": "select [column 1] from [dbo].[test]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['sql_1']['connectionId']"
}
},
"method": "post",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/query/sql"
},
"runAfter": {},
"type": "ApiConnection"
},
"For_each": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "array",
"value": "@body('Parse_JSON')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "@body('Parse_JSON')?['ResultSets']?['Table1']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "array",
"type": "array"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@outputs('Compose')",
"schema": {
"properties": {
"OutputParameters": {
"properties": {},
"type": "object"
},
"ResultSets": {
"properties": {
"Table1": {
"items": {
"properties": {
"column 1": {
"type": "string"
}
},
"required": [
"column 1"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "Recurrence"
}
}
},
"parameters": {
"$connections": {
"value": {
"sql_1": {
"connectionId": "/subscriptions/<subscription-id>/resourceGroups/<resource gourp >/providers/Microsoft.Web/connections/sql-9",
"connectionName": "sql-9",
"id": "/subscriptions/<subscription-id>/providers/Microsoft.Web/locations/northcentralus/managedApis/sql"
}
}
}
}
}
我有许多从根本上执行以下操作的逻辑应用程序:
在时间触发器上,一组 SQL 存储过程被调用,然后是一系列 Select 语句 运行,这些被传送到 CSV table 然后通过电子邮件发送给报告收件人。
该过程在一个问题上运行良好 - SQL 中的许多列中都有空格。
当我在 SQL 中 运行 a select [column 1] from table
时,它工作正常。
当我从逻辑应用程序中 运行 相同 select - 输出已修改为我相信 URI 编码示例:
Column_x0020_1
result1
result2
result3
etc.
当我 运行 调试时,我看到这是在执行 SQL 查询的输出中生成的,而不是在 CSV table 的创建中生成的,我没有看不到任何选项来转义空格以使它们不以 URI 格式编码或以编程方式将 URI 编码列 names/data 更改为 'normal' 编码。
所以请帮忙?
您可以使用下面的表达式将URI编码的列名转换为普通格式
replace(string(body('Execute_a_SQL_query_(V2)')),'_x0020_',' ')
这里是示例输出以供参考
- 使用 compose 将 URI 编码的列名称移除为普通名称
正在更新逻辑应用程序代码:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@json(replace(string(body('Execute_a_SQL_query_(V2)')),'_x0020_',' '))",
"runAfter": {
"Execute_a_SQL_query_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Create_CSV_table": {
"inputs": {
"format": "CSV",
"from": "@variables('array')"
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Table"
},
"Execute_a_SQL_query_(V2)": {
"inputs": {
"body": {
"query": "select [column 1] from [dbo].[test]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['sql_1']['connectionId']"
}
},
"method": "post",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/query/sql"
},
"runAfter": {},
"type": "ApiConnection"
},
"For_each": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "array",
"value": "@body('Parse_JSON')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "@body('Parse_JSON')?['ResultSets']?['Table1']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "array",
"type": "array"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@outputs('Compose')",
"schema": {
"properties": {
"OutputParameters": {
"properties": {},
"type": "object"
},
"ResultSets": {
"properties": {
"Table1": {
"items": {
"properties": {
"column 1": {
"type": "string"
}
},
"required": [
"column 1"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "Recurrence"
}
}
},
"parameters": {
"$connections": {
"value": {
"sql_1": {
"connectionId": "/subscriptions/<subscription-id>/resourceGroups/<resource gourp >/providers/Microsoft.Web/connections/sql-9",
"connectionName": "sql-9",
"id": "/subscriptions/<subscription-id>/providers/Microsoft.Web/locations/northcentralus/managedApis/sql"
}
}
}
}
}