dousong9729 2017-09-01 11:21
浏览 23
已采纳

命名查询无法解析地图

I have this code segement

query := `
        SELECT
            co_username as username,
            co_password as password
        FROM
            servers.co
        WHERE
            co_url = concat('https://', :co_url)
    `

    args := map[string]interface{}{
        "co_url": in.Url,
    }

    rows, err := collectorsConfig.Db.NamedQueryContext(ctx, query, args)
    if err != nil {
        msg := "Error getting co credentials for co '%s': %v"
        log.Error.Printf(msg, in.Url, err)
        return
    }

When runnig this snippet, I get an error like this:

Error getting co credentials for co 'some.random.fqdn': could not find name in map[string]interface {}{"co_url":"some.random.fqdn"}

But if I rework the snippet to be

in.Url = "https://" + in.Url

query := `
            SELECT
                co_username as username,
                co_password as password
            FROM
                servers.co
            WHERE
                co_url = :co_url
        `

Everything works. Is there a reason the named input is not working with the Concat function?

  • 写回答

1条回答 默认 最新

  • dongzuan4860 2017-09-01 15:24
    关注

    This would depend on what sql library you are using, but when using NamedQuery in many libraries, you must escape any other colons, which you will find how to do in its documentation. For example, sqlx requires you to escape a colon with two e.g.

    co_url = concat('https:://', :co_url)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码