Skip to content

maxLookup index out of range on update #54

Open

Description

@lgonzalez-silen

Hi,

Upon adding a new column to a table that was already large I started experiencing index out of range at

https://github.com/mgutz/dat/blob/v1/update.go#L178

It seems the condition that triggers hand off between preallocated parameter conversions and ad hoc conversions may be off by one. If I change i < maxLookup to i < maxLookup - 1 everything works fine but not sure if that's right, as the last element in equalsPlaceholderTab will not be used. Also, is it right that equalsPlaceholderTab starts with $0?

I wrote a little snippet to test for various values of maxLookup (https://github.com/mgutz/dat/blob/v1/init.go#L19):

type TestStruct struct {
	ID     int64  `db:"id"`
	Field1 string `db:"field1"`
	Field2 string `db:"field2"`
}

func TestBreak() {
	DB.SQL(`CREATE TABLE testtable (id serial, field1 text, field2 text);`).Exec()
	DB.SQL(`INSERT INTO testtable (field1, field2, field3) VALUES ('a', 'b');`).Exec()

	record := TestStruct{}
	_, err := DB.
		Update("testtable").
		SetWhitelist(record, "*").
		Where("id = $1", 1).
		Exec()
	if err != nil {
		panic(err)
	}

	DB.SQL(`DROP TABLE testtable;`).Exec()
}

This breaks for maxLookup <= 3 but works for larger values.

Cheers,

Luis

Activity

  1. added 2 commits that reference this issue on Feb 13, 2017
  2. mgutz commented on Mar 17, 2017

    @mgutz
    Owner

    Not ignoring this. I'm in a bit of time crunch right now.

  3. lgonzalez-silen commented on Mar 17, 2017

    @lgonzalez-silen
    ContributorAuthor

    np! thanks

  4. lgonzalez-silen commented on Mar 17, 2017

    @lgonzalez-silen
    ContributorAuthor

    See the open PR referenced above. Since we use our large table extensively, it might still be good to update maxLookup for us (although probably very marginally), but in general the PR fixes the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions