Skip to content

Detect if a system variable scope was explicitly specified or not#302

Merged
fulghum merged 4 commits intomainfrom
fulghum/max_allowed_packet
Jan 17, 2024
Merged

Detect if a system variable scope was explicitly specified or not#302
fulghum merged 4 commits intomainfrom
fulghum/max_allowed_packet

Conversation

@fulghum
Copy link

@fulghum fulghum commented Jan 17, 2024

Changes the VarScope function so that it returns whether a scope was explicitly specified, or if one has been inferred.

This is needed because some tooling (e.g. the official MySQL .NET Connector library) will query system variables (e.g. SELECT @@max_allowed_packet) and then will look up the returned value in the result set using the expected column name (@@max_allowed_packet). Currently, from the way we parse the system variable, this was always returned with the scope present, but to match MySQL's behavior, the column name needs to match the requested name.

Related GMS PR: dolthub/go-mysql-server#2266

@fulghum fulghum requested a review from zachmu as a code owner January 17, 2024 19:10
… explicitly specified, or if one has been inferred.
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

// specify a variable (returns SetScope_None), then it is recommended to use the original non-broken string, as this
// will always only return the last part. `[]string{"my_db", "my_tbl", "my_col"}` will return "my_col" with SetScope_None.
func VarScope(nameParts ...string) (string, SetScope, error) {
func VarScope(nameParts ...string) (string, SetScope, bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a little cleaner to add this as a new field on SetScope rather than as a bool here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. SetScope is currently just an alias for a string, so we'd need to turn it into a struct. Might not be worth it right this minute, but I'll take a closer look.

@fulghum fulghum merged commit 55b8c7b into main Jan 17, 2024
@Hydrocharged Hydrocharged deleted the fulghum/max_allowed_packet branch February 7, 2024 13:44
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

Successfully merging this pull request may close these issues.

2 participants