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

type error in parameter puts the driver in an inconsistent state #8

Closed
andybalholm opened this issue Apr 5, 2012 · 2 comments
Closed

Comments

@andybalholm
Copy link
Contributor

When I send a query parameter that is the wrong type, I get an (expected) error message like "invalid input syntax for integer". But then any queries I run after that return errors too: usually something like "pq: unexpected parse response: '3'"

So apparently when the driver receives an "invalid input syntax" error, it needs to read some more messages before returning—or just close the connection and open a new one.

I'm using PostgreSQL 9.1alpha2

Sample program that exhibits this error:

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/bmizerany/pq"
)

func main() {
    db, err := sql.Open("postgres", "user=postgres dbname=postgres sslmode=disable")
    if err != nil {
        fmt.Println(err)
        return
    }

    _, err = db.Exec("create table test (i integer)")
    if err != nil {
        fmt.Println(err)
        return
    }

    _, err = db.Query("select * from test where i=$1", "hhh")
    fmt.Println(err)

    _, err = db.Query("select * from test where i=$1", 1)
    fmt.Println(err)
}
@bmizerany
Copy link
Contributor

OK. That should do it. Thank you for reporting this.

@andybalholm
Copy link
Contributor Author

On Apr 6, 2012, at 3:22 PM, Blake Mizerany wrote:

OK. That should do it. Thank you for reporting this.

It works now. Thanks for the quick fix.

Andy Balholm
(509) 276-2065
andy@balholm.com

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