如何使用Scan方法

huangapple go评论79阅读模式
英文:

How to use the Scan method

问题

我必须使用scan方法来获取并存储我的ID,但程序无法编译。

第一次尝试:

query := "INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id".scan(&id)

id".scan未定义(未命名类型字符串没有scan字段或方法)

然后我按照文档进行了尝试,但是没有效果...

query := db.QueryRow("INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id").scan(&id)

scan未定义(*sql.Row类型没有scan字段或方法,但有Scan)

对问题有什么想法吗?

英文:

I have to use the scan method for get en store my id but the program does not want to compile.

The first time I tried:

	query := "INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id".scan(&id)

> id".scan undefined (type untyped string has no field or method scan)

Then I apply the documentation but nothing...

query := db.QueryRow("INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id").scan(&id)

> scan undefined (type *sql.Row has no field or method scan, but does have Scan)

An idea of ​​the problem?

答案1

得分: 1

只需阅读错误消息:

> scan未定义(类型*sql.Row没有scan字段或方法,但有Scan)

scan未定义,但Scan是存在的。在您的第二个示例中,将.scan替换为.Scan

英文:

Just read the error message:

> scan undefined (type *sql.Row has no field or method scan, but does
> have Scan)

scan is undefined but Scan is not. Replace .scan by .Scan in your second example

huangapple
  • 本文由 发表于 2021年6月8日 20:14:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/67886721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定