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

memory database with binary column cannot be updated #1497

Open
yuhangm000 opened this issue Dec 22, 2022 · 2 comments
Open

memory database with binary column cannot be updated #1497

yuhangm000 opened this issue Dec 22, 2022 · 2 comments

Comments

@yuhangm000
Copy link

when I try to update a table contains a binary column, the result is
comparing uncomparable type []uint8
this issue is similar as issues/361, but when I read code, I found that update will check unique key, it will compare the new value and the old value, and that cause the error

// Update the given row from the table.
func (t *tableEditor) Update(ctx *sql.Context, oldRow sql.Row, newRow sql.Row) error {

	...

	// Throw a unique key error if any unique indexes are defined
	for _, cols := range t.uniqueIdxCols {
		if hasNullForAnyCols(newRow, cols) {
			continue
		}
		existing, found, err := t.ea.GetByCols(newRow, cols)  // this
		if err != nil {
			return err
		}

		if found {
			return sql.NewUniqueKeyErr(formatRow(newRow, cols), false, existing)
		}
	}

in GetByCols

func columnsMatch(colIndexes []int, row sql.Row, row2 sql.Row) bool {
	for _, i := range colIndexes {
		if row[i] != row2[i] {
			return false
		}
	}
	return true
}

Please help to confirm the problem~

@fulghum
Copy link
Contributor

fulghum commented Dec 27, 2022

Hey @yuhangm000, thanks for reporting an issue. I tried to repro this with SQL commands directly against go-mysql-server, but I wasn't able to repro it that way. If you can share some simple repro code, we'll be happy to dig in and see what we can help figure out.

@yuhangm000
Copy link
Author

@fulghum you can try this sql

CREATE TABLE `zt_test`(
  `id` BIGINT unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `instance_id` VARBINARY(20) NOT NULL,
  UNIQUE KEY `uniq_instance` (`instance_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='test';

type TestStruct struct {
	ID         uint64 `gorm:"column:id"`
	InstanceID string `gorm:"column:instance_id"`
}

and execute create before update

Hey @yuhangm000, thanks for reporting an issue. I tried to repro this with SQL commands directly against go-mysql-server, but I wasn't able to repro it that way. If you can share some simple repro code, we'll be happy to dig in and see what we can help figure out.

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

No branches or pull requests

2 participants