Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fmt.Stringer.String() called on nil pointer #1075

Closed
wants to merge 0 commits into from
Closed

Fix fmt.Stringer.String() called on nil pointer #1075

wants to merge 0 commits into from

Conversation

wilhelmliao
Copy link

Summary

got error when call bind() using parameter (*fmt.Stringer)(nil).

var v *json.Number  // fmt.Stringer
query := "SELECT ?"
params := []interface{}{
v,
}
sql, err := bindPositional(time.UTC, query, params...)
fmt.Println(sql)

want

SELECT NULL

got

panic: value method encoding/json.Number.String called using nil *Number pointer

Checklist

Delete items not relevant to your PR:

  • [v ] Unit and integration tests covering the common scenarios were added

bind_test.go Outdated Show resolved Hide resolved
@CLAassistant
Copy link

CLAassistant commented Sep 1, 2023

CLA assistant check
All committers have signed the CLA.

@jkaflik
Copy link
Contributor

jkaflik commented Sep 13, 2023

@wilhelmliao could you remove conflicts?

@wilhelmliao
Copy link
Author

I fixed the conflicts, but the patched codes seem missing.

https://github.com/wilhelmliao/clickhouse-go/blob/main/bind.go#L308:313

	case fmt.Stringer:
		rv := reflect.ValueOf(v)
		if rv.Kind() == reflect.Pointer {
			if rv.IsNil() {
				return "NULL", nil
			}
		}
		return quote(v.String()), nil

@jkaflik
Copy link
Contributor

jkaflik commented Sep 14, 2023

@wilhelmliao yes, there was a PR improving bind - #1092.

Thanks for your effort!

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.

3 participants