-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Get treats json.RawMessage like db.RawBytes #197
Comments
I believe this is a Go issue and I've submitted an issue for it. That ticket describes the problem in more detail; rest assured that this problem exists with Here's a test for func TestIssue197(t *testing.T) {
type mybyte []byte
type Var struct{ Raw json.RawMessage }
type Var2 struct{ Raw []byte }
type Var3 struct{ Raw mybyte }
RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T) {
var err error
var v, q Var
if err = db.Get(&v, `SELECT '{"a": "b"}' AS raw`); err != nil {
t.Fatal(err)
}
fmt.Printf("%s: v %s\n", db.DriverName(), v.Raw)
if err = db.Get(&q, `SELECT 'null' AS raw`); err != nil {
t.Fatal(err)
}
fmt.Printf("%s: v %s\n", db.DriverName(), v.Raw)
var v2, q2 Var2
if err = db.Get(&v2, `SELECT '{"a": "b"}' AS raw`); err != nil {
t.Fatal(err)
}
fmt.Printf("%s: v2 %s\n", db.DriverName(), v2.Raw)
if err = db.Get(&q2, `SELECT 'null' AS raw`); err != nil {
t.Fatal(err)
}
fmt.Printf("%s: v2 %s\n", db.DriverName(), v2.Raw)
var v3, q3 Var3
if err = db.QueryRow(`SELECT '{"a": "b"}' AS raw`).Scan(&v3.Raw); err != nil {
t.Fatal(err)
}
fmt.Printf("v3 %s\n", v3.Raw)
if err = db.QueryRow(`SELECT '{"c": "d"}' AS raw`).Scan(&q3.Raw); err != nil {
t.Fatal(err)
}
fmt.Printf("v3 %s\n", v3.Raw)
t.Fail()
})
} Output:
|
I'm going to close this issue because it's not an sqlx issue, however it does make some things in |
Okay thanks for shedding light on this. In the meanwhile I am explicitly using |
…failing and a comment about why it fails
@jmoiron Are you sure the warnings are appropriate for types that implement Scanner? It would seem they are always passed driver memory and are expected to copy the |
You're right, the |
Cool. If you haven't, see my comment on golang/go#13905 for a workaround on scanning types that are convertible to |
FYI - I submitted @jmoiron's patch, which has been included in Go 1.7, so you should be safe against this problem if you are using it! |
I have a struct where one of the fields is a json.RawMessage. When I use
DB.Get()
to populate it, the field is volatile and changes with more calls toDB.Get()
.Here is a simple program to reproduce it.
The output I get is:
The text was updated successfully, but these errors were encountered: