[英]How do I get granular LOAD DATA results from the golang MySQL package?
I am writing a Go program that interacts with a MySQL database.我正在编写一个与 MySQL 数据库交互的 Go 程序。 In MySQL, when you do a
LOAD DATA
query, in addition to the regular X rows affected
line you get a line with more granular information:在 MySQL 中,当您执行
LOAD DATA
查询时,除了常规的X rows affected
的行之外,您还会获得包含更详细信息的行:
mysql> LOAD DATA LOCAL INFILE 'many-lines.tsv' REPLACE INTO TABLE test_table (id, timestamp);
Query OK, 6 rows affected (0.01 sec)
Records: 3 Deleted: 3 Skipped: 0 Warnings: 0
As documented here under the section "Statement Result Information".如“声明结果信息”部分所述。
I would love to be able to access this from my Go program, but I cannot figure out how, or whether it's even possible.我希望能够从我的 Go 程序中访问它,但我不知道如何,甚至是否可能。
sql.DB.Exec()
returns a Result
, but that only has a RowsAffected
field . sql.DB.Exec()
返回一个Result
,但它只有一个RowsAffected
字段。 This contains a sum of rows written + rows deleted and ignores rows skipped, and is therefore ambiguous (write 3, delete 2 and skip 2 is the same as write 5, delete 0 and skip 0).这包含写入的行 + 删除的行的总和并忽略跳过的行,因此是模棱两可的(写入 3、删除 2 和跳过 2 与写入 5、删除 0 和跳过 0 相同)。
I looked through the documentation for the Go MySQL driver , but couldn't find anything there that does what I want.我查看了 Go MySQL 驱动程序的文档,但在那里找不到任何我想要的东西。
Is there a way to get access to this information?有没有办法访问这些信息?
The information is actually a ER_LOAD_INFO "error" (notionally info) message of the server.该信息实际上是服务器的ER_LOAD_INFO “错误”(名义上是信息)消息。
This gets communicated as an informational message in the OK response from the server.这在来自服务器的OK 响应中作为信息性消息进行通信。
Looking at the decoding of the OK packet in go , it isn't parsing out the info (human readable status information) .查看go 中 OK 数据包的解码,它没有解析出信息(人类可读状态信息) 。 When making the connection ensure that clientSessionTrack is part of the connection flags.
建立连接时,请确保clientSessionTrack是连接标志的一部分。
So a few small enhancements to the Go MySQL driver and you'll be able to access it.因此,对 Go MySQL 驱动程序进行一些小的改进,您就可以访问它了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.