@@ -131,14 +131,8 @@ type Session interface {
131131 DelLock (lockName string ) error
132132 // IterLocks iterates through all locks owned by this user
133133 IterLocks (cb func (name string ) error ) error
134- // SetLastQueryInfoInt sets session-level query info for the key given, applying to the query just executed.
135- SetLastQueryInfoInt (key string , value int64 )
136- // GetLastQueryInfoInt returns the session-level query info for the key given, for the query most recently executed.
137- GetLastQueryInfoInt (key string ) int64
138- // SetLastQueryInfoString sets session-level query info as a string for the key given, applying to the query just executed.
139- SetLastQueryInfoString (key string , value string )
140- // GetLastQueryInfoString returns the session-level query info as a string for the key given, for the query most recently executed.
141- GetLastQueryInfoString (key string ) string
134+ // GetLastQueryInfo returns session-level info for the most recently executed query.
135+ GetLastQueryInfo () * LastQueryInfo
142136 // GetTransaction returns the active transaction, if any
143137 GetTransaction () Transaction
144138 // SetTransaction sets the session's transaction
@@ -253,12 +247,21 @@ type (
253247 }
254248)
255249
256- const (
257- RowCount = "row_count"
258- FoundRows = "found_rows"
259- LastInsertId = "last_insert_id"
260- LastInsertUuid = "last_insert_uuid"
261- )
250+ type LastQueryInfo struct {
251+ RowCount atomic.Int64 // Session-level Row Count for the last executed query
252+ FoundRows atomic.Int64 // Session-level Found Rows for the last executed query
253+ LastInsertId atomic.Int64 // Session-level ID for the last executed insert query
254+ LastInsertUUID atomic.Value // Session-level UUID for the last executed insert query
255+ }
256+
257+ func defaultLastQueryInfo () * LastQueryInfo {
258+ ret := LastQueryInfo {}
259+ ret .RowCount .Store (0 )
260+ ret .FoundRows .Store (1 ) // this is kind of a hack -- it handles the case of `select found_rows()` before any select statement is issued
261+ ret .LastInsertId .Store (0 )
262+ ret .LastInsertUUID .Store ("" )
263+ return & ret
264+ }
262265
263266// Session ID 0 used as invalid SessionID
264267var autoSessionIDs uint32 = 1
@@ -703,19 +706,6 @@ func (i *spanIter) Close(ctx *Context) error {
703706 return i .iter .Close (ctx )
704707}
705708
706- func defaultLastQueryInfo () map [string ]* atomic.Value {
707- ret := make (map [string ]* atomic.Value )
708- ret [RowCount ] = & atomic.Value {}
709- ret [RowCount ].Store (int64 (0 ))
710- ret [FoundRows ] = & atomic.Value {}
711- ret [FoundRows ].Store (int64 (1 )) // this is kind of a hack -- it handles the case of `select found_rows()` before any select statement is issue)
712- ret [LastInsertId ] = & atomic.Value {}
713- ret [LastInsertId ].Store (int64 (0 ))
714- ret [LastInsertUuid ] = & atomic.Value {}
715- ret [LastInsertUuid ].Store ("" )
716- return ret
717- }
718-
719709// cc: https://dev.mysql.com/doc/refman/8.0/en/temporary-files.html
720710func GetTmpdirSessionVar () string {
721711 ret := os .Getenv ("TMPDIR" )
0 commit comments