You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing a Go program that interacts with a MySQL database. 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 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
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. sql.DB.Exec() returns a Result, but that only has a RowsAffected field. 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).
Issue description
This began life as a question on StackOverflow. Discussion is copied here for ease of access.
Question
I am writing a Go program that interacts with a MySQL database. In MySQL, when you do a
LOAD DATA
query, in addition to the regularX rows affected
line you get a line with more granular information: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.
sql.DB.Exec()
returns aResult
, but that only has aRowsAffected
field. 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).I looked through the documentation for the Go MySQL driver, but couldn't find anything there that does what I want.
Is there a way to get access to this information?
Answer
The information is actually a ER_LOAD_INFO "error" (notionally info) message of the server.
This gets communicated as an informational message in the OK response from the server.
Looking at the decoding of the OK packet in go, it isn't parsing out the info (human readable status information). When making the connection ensure that clientSessionTrack is part of the connection flags.
So a few small enhancements to the Go MySQL driver and you'll be able to access it.
Example code
N/A
Error log
N/A
Configuration
Driver version (or git SHA): v1.4.1
Go version:
Server version:
Server OS:
The text was updated successfully, but these errors were encountered: