func (t *DBTest) TestTypeString(c *C) { src := "hello\000" var dst string _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?", src) c.Assert(err, IsNil) c.Assert(dst, Equals, "hello") }
func (t *DBTest) TestTypeIntArray(c *C) { src := []int{1, 2, 3} var dst []int _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?::int[]", []int{1, 2, 3}) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) }
func (t *DBTest) TestTypeStringArray(c *C) { src := []string{"foo \n", "bar", "hello {}", "'\\\""} var dst []string _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?::text[]", src) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) }
func (t *DBTest) TestTypeBytes(c *C) { src := []byte("hello world\000") var dst []byte _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?::bytea", src) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) }
func (t *DBTest) TestTypeHstore(c *C) { src := map[string]string{"foo =>": "bar =>", "hello": "world", "'\\\"": "'\\\""} dst := make(map[string]string) _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?", src) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) }
func (t *DBTest) TestTypeDate(c *C) { src := time.Now().UTC() var dst time.Time _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?::date", src) c.Assert(err, IsNil) c.Assert(dst.Location(), Equals, time.UTC) c.Assert(dst.Format("2006-01-02"), Equals, dst.Format("2006-01-02")) }
func (t *DBTest) TestTypeStmtEmptyStringArray(c *C) { stmt, err := t.db.Prepare("SELECT $1::text[]") c.Assert(err, IsNil) var dst []string _, err = stmt.QueryOne(pg.LoadInto(&dst), []string{}) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, []string{}) }
func (t *DBTest) TestTypeEmptyIntArray(c *C) { var dst []int _, err := t.db.QueryOne( pg.LoadInto(&dst), "SELECT ?::int[]", []int{}, ) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, []int{}) }
func (t *DBTest) TestTypeStmtHstore(c *C) { stmt, err := t.db.Prepare("SELECT $1::hstore") c.Assert(err, IsNil) src := map[string]string{"foo =>": "bar =>", "hello": "world", "'\\\"": "'\\\""} dst := make(map[string]string) _, err = stmt.QueryOne(pg.LoadInto(&dst), src) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) }
func (t *DBTest) TestTypeStmtString(c *C) { stmt, err := t.db.Prepare("SELECT $1::text") c.Assert(err, IsNil) src := "hello\000" var dst string _, err = stmt.QueryOne(pg.LoadInto(&dst), src) c.Assert(err, IsNil) c.Assert(dst, Equals, "hello") }
func (t *DBTest) TestTypeStmtIntArray(c *C) { stmt, err := t.db.Prepare("SELECT $1::int[]") c.Assert(err, IsNil) src := []int{1, 2, 3} var dst []int _, err = stmt.QueryOne(pg.LoadInto(&dst), src) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) }
func ExampleDB_Prepare() { stmt, err := db.Prepare("SELECT $1::text, $2::text") if err != nil { panic(err) } var s1, s2 string _, err = stmt.QueryOne(pg.LoadInto(&s1, &s2), "foo", "bar") fmt.Println(s1, s2, err) // Output: foo bar <nil> }
func (t *DBTest) TestTypeStmtBytes(c *C) { stmt, err := t.db.Prepare("SELECT $1::bytea") c.Assert(err, IsNil) src := []byte("hello world\000") var dst []byte _, err = stmt.QueryOne(pg.LoadInto(&dst), src) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, src) c.Assert(stmt.Close(), IsNil) }
func (t *DBTest) TestTypeTimestamp(c *C) { src := time.Now().UTC() var dst time.Time _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?::timestamp", src) c.Assert(err, IsNil) c.Assert(dst.Location(), Equals, time.UTC) c.Assert( dst.Format("2006-01-02 15:04:05.9999"), Equals, src.Format("2006-01-02 15:04:05.9999"), ) }
func (t *PoolTest) TestTimeoutAndCancelRequest(c *C) { _, err := t.db.Exec("SELECT pg_sleep(60)") c.Assert(err.(net.Error).Timeout(), Equals, true) c.Assert(t.db.Pool().Size(), Equals, 0) c.Assert(t.db.Pool().Len(), Equals, 0) // Unreliable check that previous query was cancelled. var count int _, err = t.db.QueryOne(pg.LoadInto(&count), "SELECT COUNT(*) FROM pg_stat_activity") c.Assert(err, IsNil) c.Assert(count, Equals, 1) }
func (t *DBTest) TestQueryOneValue(c *C) { var v int _, err := t.db.QueryOne(pg.LoadInto(&v), "SELECT 1 AS num") c.Assert(err, IsNil) c.Assert(v, Equals, 1) }
func ExampleLoadInto() { var s1, s2 string _, err := db.QueryOne(pg.LoadInto(&s1, &s2), "SELECT ?, ?", "foo", "bar") fmt.Println(s1, s2, err) // Output: foo bar <nil> }
func (t *DBTest) TestTypeEmptyStringArray(c *C) { var dst []string _, err := t.db.QueryOne(pg.LoadInto(&dst), "SELECT ?::text[]", []string{}) c.Assert(err, IsNil) c.Assert(dst, DeepEquals, []string{}) }