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

Fix panic in dialect. If FK Id is not referenced #5

Closed
wants to merge 1 commit into from
Closed

Fix panic in dialect. If FK Id is not referenced #5

wants to merge 1 commit into from

Conversation

NuVivo314
Copy link
Contributor

Hello,

Can you review this patch.
I'm not sure to make a side effect on this one...

panic: reflect: call of reflect.Value.Int on zero Value

goroutine 1 [running]:
reflect.Value.Int(0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /opt/golang/src/pkg/reflect/value.go:796 +0xd0
github.com/coocood/qbs.(*Sqlite3).SetModelValue(0xf84008c570, 0x4c47b0, 0xf8400a6270, 0x146, 0x4c6750, ...)
    [...]/github.com/coocood/qbs/sqlite3.go:51 +0x33c
github.com/coocood/qbs.(*Qbs).scanRows(0xf84008b280, 0x4c1e80, 0xf8400a06c0, 0x160, 0xf8400a4a80, ...)
    [...]/github.com/coocood/qbs/qbs.go:225 +0x83e
github.com/coocood/qbs.(*Qbs).doQueryRow(0xf84008b280, 0x4c1e70, 0xf8400a06c0, 0xf8400a7340, 0xf800000338, ...)
    [...]/github.com/coocood/qbs/qbs.go:167 +0x377
github.com/coocood/qbs.(*Qbs).Find(0xf84008b280, 0x4c1e70, 0xf8400a06c0, 0xf8400a06c0, 0x100000001, ...)
    [...]/github.com/coocood/qbs/qbs.go:139 +0x349

If Id in FK isn't on database.

Regards.

In other possible patch is:

diff --git a/qbs.go b/qbs.go
index 2fa4bfd..d6ca513 100644
--- a/qbs.go
+++ b/qbs.go
@@ -226,7 +226,7 @@ func (q *Qbs) scanRows(rowValue reflect.Value, rows *sql.Rows) (err error) {
                                subStruct.Set(reflect.New(subStruct.Type().Elem()))
                        }
                        subField := subStruct.Elem().FieldByName(snakeToUpperCamel(paths[1]))
-                       if subField.IsValid() {
+                       if subField.IsValid() && value.Elem().IsValid() {
                                err = q.Dialect.SetModelValue(value, subField)
                                if err != nil {
                                        return

@coocood
Copy link
Owner

coocood commented Feb 24, 2013

Thanks, your other possible patch above is good, but your patch in the commit break the test.
You should run test after make the patch.

@coocood coocood closed this Feb 24, 2013
@coocood
Copy link
Owner

coocood commented Feb 24, 2013

And for this issue, it is related to sqlite3 only. I'll fix it soon.

@coocood
Copy link
Owner

coocood commented Feb 24, 2013

Well, the patch in the commit is actually better, but you just omitted the "!" mark. XD
I fixed this issue.
commit

@NuVivo314
Copy link
Contributor Author

Yes, i'm just seeing...
So sorry.

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

Successfully merging this pull request may close these issues.

2 participants