Azure 逻辑应用中 SQL 列名称的 URI 编码

魔王

我有许多逻辑应用程序从根本上执行以下操作:

在时间触发器上,调用一组 SQL 存储过程,然后运行一系列 Select 语句,这些语句通过管道传输到 CSV 表,然后通过电子邮件发送给报告收件人。

该过程在一个问题上运行良好 - SQL 中的许多列中都有空格。

当我select [column 1] from table在 SQL 中运行 a时,它工作正常。

当我从逻辑应用程序中运行相同的选择时 - 输出已修改为我相信 URI 编码示例:

Column_x0020_1  
result1  
result2  
result3  
etc.

当我运行调试时,我看到这是在执行 SQL 查询的输出中生成的,而不是在 CSV 表的创建中生成的,而且我没有看到任何可以对空格进行转义以便它们不编码的选项URI 格式或以编程方式将 URI 编码的列名称/数据更改为“正常”编码的内容。

所以请帮忙?

文卡特什·多达-MT

您可以使用以下表达式将带有 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"
                }
            }
        }
    }
}

参考问答文章

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章