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

exec operation #14

Open
firstguo opened this issue Sep 29, 2019 · 1 comment
Open

exec operation #14

firstguo opened this issue Sep 29, 2019 · 1 comment

Comments

@firstguo
Copy link

Why only Exec don't call w.argsIn function to deal with "IN"

image

@fifsky
Copy link
Member

fifsky commented Oct 8, 2019

type Users struct {
	Id          int            `form:"id" json:"id" db:"id"`
	Name        string         `form:"name" json:"name" db:"name"`
	Status      int            `form:"status" json:"status" db:"status"`
	SuccessTime sql.NullString `form:"-" json:"success_time" db:"success_time"`
	CreatedAt   time.Time      `form:"-" json:"created_at" db:"created_at" time_format:"2006-01-02 15:04:05"`
	UpdatedAt   time.Time      `form:"-" json:"updated_at" db:"updated_at" time_format:"2006-01-02 15:04:05"`
}

When the struct field used driver.Valuer such as sql.NullString, sqlx.In reflect will painc

https://github.com/jmoiron/sqlx/blob/d161d7a76b/bind.go#L119-L123

Because the filed value is nil, can't call v.Type()

------> 0 2019-10-08 11:08:27.983139 +0800 CST m=+0.047751226
------> 1 1
------> 2 test1
------> 3 1
------> 4 <nil>
2019/10/08 11:08:27 
        Query: INSERT INTO `users` (`created_at`,`id`,`name`,`status`,`success_time`,`updated_at`) VALUES(?,?,?,?,?,?);
        Args:  []interface {}{time.Time{wall:0xbf5f1d4afa9982b8, ext:47751226, loc:(*time.Location)(0x163d6e0)}, 1, "test1", 1, sql.NullString{String:"", Valid:false}, time.Time{wall:0xbf5f1d4afa999258, ext:47755583, loc:(*time.Location)(0x163d6e0)}}
        Time:  0.00010s

--- FAIL: TestQueryxIn (0.05s)
panic: reflect: call of reflect.Value.Type on zero Value [recovered]
        panic: reflect: call of reflect.Value.Type on zero Value

goroutine 39 [running]:
testing.tRunner.func1(0xc00017c100)
        /usr/local/go/src/testing/testing.go:874 +0x3a3
panic(0x13463a0, 0xc000170340)
        /usr/local/go/src/runtime/panic.go:679 +0x1b2
reflect.Value.Type(0x0, 0x0, 0x0, 0x3, 0x3)
        /usr/local/go/src/reflect/value.go:1877 +0x166
github.com/jmoiron/sqlx.In(0xc000088150, 0x68, 0xc000146280, 0x6, 0x8, 0x15, 0x0, 0x0, 0x0, 0x15, ...)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/vendor/github.com/jmoiron/sqlx/bind.go:126 +0x281
github.com/ilibs/gosql/v2.(*Wrapper).argsIn(0xc0000ba270, 0xc000088150, 0x68, 0xc000146280, 0x6, 0x8, 0x0, 0x0, 0x10cf404, 0xc0000b6680, ...)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/wrapper.go:55 +0x63
github.com/ilibs/gosql/v2.(*Wrapper).Exec(0xc0000ba270, 0xc000088150, 0x68, 0xc000146280, 0x6, 0x8, 0x0, 0x0, 0x0, 0x0)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/wrapper.go:89 +0x469
github.com/ilibs/gosql/v2.(*Builder).Create(0xc000127c08, 0xc0000ba270, 0x4, 0x13b299c)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/builder.go:207 +0x1dd
github.com/ilibs/gosql/v2.insert(0x1)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/builder_test.go:147 +0x18e
github.com/ilibs/gosql/v2.TestQueryxIn.func1(0xc00017c100)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/wrapper_test.go:219 +0x3c
github.com/ilibs/gosql/v2.RunWithSchema(0xc00017c100, 0x13bc790)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/builder_test.go:123 +0x43e
github.com/ilibs/gosql/v2.TestQueryxIn(0xc00017c100)
        /Users/fifsky/wwwroot/go/library/github.com/ilibs/gosql/wrapper_test.go:218 +0x37
testing.tRunner(0xc00017c100, 0x13bc798)
        /usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:960 +0x350
exit status 2
FAIL    github.com/ilibs/gosql/v2       0.068s

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