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

MapScan replaces underlying string pointer with a string #264

Open
dkropachev opened this issue Sep 16, 2024 · 0 comments
Open

MapScan replaces underlying string pointer with a string #264

dkropachev opened this issue Sep 16, 2024 · 0 comments
Labels

Comments

@dkropachev
Copy link
Collaborator

func TestMapScanWithRefMap2(t *testing.T) {
	session := createSession(t)
	defer session.Close()
	if err := createTable(session, `CREATE TABLE gocql_test.scan_map_ref_table (
			testtext       text PRIMARY KEY,
			testint        int,
		)`); err != nil {
		t.Fatal("create table:", err)
	}
	m := make(map[string]interface{})
	m["testtext"] = "testtext"
	m["testint"] = 100

	if err := session.Query(`INSERT INTO scan_map_ref_table (testtext, testint) values (?,?)`,
		m["testtext"], m["testint"]).Exec(); err != nil {
		t.Fatal("insert:", err)
	}

	var testText string
	ret := map[string]interface{}{
		"testtext": &testText,
		// testint is not set here.
	}
	iter := session.Query(`SELECT * FROM scan_map_ref_table`).Iter()
	if ok := iter.MapScan(ret); !ok {
		t.Fatal("select:", iter.Close())
	}

	if ret["testtext"].(*string) != &testText {
		t.Fatal("returned testtext is not the same string")
	}

	iter = session.Query(`SELECT * FROM scan_map_ref_table`).Iter()
	if ok := iter.MapScan(ret); !ok {
		t.Fatal("select:", iter.Close())
	}
}

Ends up with:

=== RUN   TestMapScanWithRefMap2
--- FAIL: TestMapScanWithRefMap2 (0.08s)
panic: interface conversion: interface {} is string, not *string [recovered]
	panic: interface conversion: interface {} is string, not *string
@dkropachev dkropachev added the bug label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant