The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
252748371

切片如何转数组?

  •  
  •   252748371 · Sep 25, 2019 · 4875 views
    This topic created in 2596 days ago, the information mentioned may be changed or developed.

    切片如何转数组? gorm 的 in 查询不支持切片

    9 replies  •  2019-11-15 17:24:12 +08:00
    codehz
    codehz
    Sep 25, 2019
    1
    首先必须长度固定,然后
    var target[5]int
    copy(target[:], source)
    252748371
    252748371
    OP
    Sep 25, 2019
    2
    @codehz
    问题是长度不知道啊
    codehz
    codehz
    Sep 25, 2019
    3
    那就
    target := make([]int, n)
    copy(target[:], source)
    chotow
    chotow
    Sep 25, 2019
    4
    gorm 的 in 查询是支持切片的: http://gorm.io/docs/query.html#Plain-SQL
    xorm 不支持(吐血)
    252748371
    252748371
    OP
    Sep 25, 2019
    6
    @chotow
    哥 帮我看看
    sql: converting argument $4 type: unsupported type []string, a slice of string
    252748371
    252748371
    OP
    Sep 25, 2019
    7
    解决了
    原来不能传指针!
    chotow
    chotow
    Sep 27, 2019
    8
    @kedadiannao220 #5
    xorm Raw SQL 查询的时候,怎么实现 in 传值呢?
    我试了下:db.SQL("select * from test").In("id", []uint64{1, 2, 3}).Find(&ret)
    这样子并不可以
    kedadiannao220
    kedadiannao220
    Nov 15, 2019
    9
    @chotow
    使用 raw sql,就不用再使用 In、where 这些函数了;
    db.SQL("select * from test where id in xxxx"),这样会存在 sql 注入的风险
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1550 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:05 · PVG 02:05 · LAX 10:05 · JFK 13:05
    ♥ Do have faith in what you're doing.