Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder.BuildInsert 生成的sql 报错了 #20

Closed
tangwy01 opened this issue Jul 21, 2018 · 3 comments
Closed

builder.BuildInsert 生成的sql 报错了 #20

tangwy01 opened this issue Jul 21, 2018 · 3 comments

Comments

@tangwy01
Copy link

cond, vals, err := builder.BuildInsert("testTable", data)
if nil != err {
	return 0, err
}
result, err := db.Exec(cond, vals...)

最后执行 db.Exec(cond, vals...)的时候有错误产生 我用的是mysql

data:<*errors.errorString>
s:"sql: converting argument $1 type: unsupported type []map[string]...+28 more"

@caibirdme
Copy link
Contributor

方便贴一下你的data的值是什么吗,顺便把cond 和vals也贴一下下谢谢

@caibirdme
Copy link
Contributor

@vstTang 看起来应该是你data里的值有问题,这个gendry目前没有帮你做检查。
data需要类似这样才行:

data = []map[string]interface{}{
  map[string]interface{}{
    "foo": intValue,
    "bar": stringValue,
    "baz": floatValue,
  },
  map[string]interface{}{
    "foo": intValue,
    "bar": stringValue,
    "baz": floatValue,
  },
}

map的值必须是值类型,不能是复杂类型,下面这种是不合法的

data = []map[string]interface{}{
  map[string]interface{}{
    "foo": mapValue,
    "bar": arrayValue,
    "baz": structValue,
  },
}

@caibirdme
Copy link
Contributor

如果没有其它问题的话,我暂时先关闭这个issue了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants