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

WherePri possible error #3330

Closed
oldme-git opened this issue Feb 25, 2024 · 2 comments · Fixed by #3339
Closed

WherePri possible error #3330

oldme-git opened this issue Feb 25, 2024 · 2 comments · Fixed by #3339
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@oldme-git
Copy link
Member

v2.6.3

There is a unique index in the table of PgSQL, WherePri identify probably an error primary key.

Please put the code in contrib/drivers/pgsql/pgsql_z_unit_model_test.go. In the way, you can debug it directly.

func Test_Model_WherePri(t *testing.T) {
	var (
		table      = fmt.Sprintf(`%s_%d`, TablePrefix+"test", gtime.TimestampNano())
		uniqueName = fmt.Sprintf(`%s_%d`, TablePrefix+"test_unique", gtime.TimestampNano())
	)
	if _, err := db.Exec(ctx, fmt.Sprintf(`
		CREATE TABLE %s (
		   	id bigserial  NOT NULL,
		   	passport varchar(45) NOT NULL,
		   	password varchar(32) NOT NULL,
		   	nickname varchar(45) NOT NULL,
		   	create_time timestamp NOT NULL,
		   	PRIMARY KEY (id),
			CONSTRAINT %s unique ("password")
		) ;`, table, uniqueName,
	)); err != nil {
		gtest.Fatal(err)
	}
	defer dropTable(table)

	gtest.C(t, func(t *gtest.T) {
		data := g.Map{
			"id":          1,
			"passport":    "pp1",
			"password":    "pw1",
			"nickname":    "n1",
			"create_time": "2016-06-06",
		}
		_, err := db.Model(table).Data(data).Insert()
		t.AssertNil(err)
		one, err := db.Model(table).WherePri(1).One()
		t.AssertNil(err)
		t.Assert(one["passport"], data["passport"])
		t.Assert(one["password"], data["password"])
		t.Assert(one["nickname"], "n1")
	})
}

Probably , it will fail.

[ASSERT] EXPECT  == pp1
@oldme-git oldme-git added the bug It is confirmed a bug, but don't worry, we'll handle it. label Feb 25, 2024
oldme-git added a commit to oldme-git/gf that referenced this issue Feb 29, 2024
@Henriqu331
Copy link

I'll look for the answer ok

oldme-git added a commit to oldme-git/gf that referenced this issue Mar 1, 2024
@oldme-git
Copy link
Member Author

@oldme-git Thank you for your work. But this issue alreay have answer.

@gqcn gqcn closed this as completed in #3339 Mar 6, 2024
gqcn pushed a commit that referenced this issue Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants