Commit c9dd3f26 authored by gwenn's avatar gwenn

Change #Prepare method to optionnaly Bind.

parent efc5245d
...@@ -220,7 +220,7 @@ type Stmt struct { ...@@ -220,7 +220,7 @@ type Stmt struct {
cols map[string]int // cached columns index by name cols map[string]int // cached columns index by name
} }
func (c *Conn) Prepare(cmd string) (*Stmt, os.Error) { func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, os.Error) {
if c == nil || c.db == nil { if c == nil || c.db == nil {
return nil, os.NewError("nil sqlite database") return nil, os.NewError("nil sqlite database")
} }
...@@ -236,7 +236,14 @@ func (c *Conn) Prepare(cmd string) (*Stmt, os.Error) { ...@@ -236,7 +236,14 @@ func (c *Conn) Prepare(cmd string) (*Stmt, os.Error) {
if tail != nil && C.strlen(tail) > 0 { if tail != nil && C.strlen(tail) > 0 {
t = C.GoString(tail) t = C.GoString(tail)
} }
return &Stmt{c: c, stmt: stmt, tail: t}, nil s := &Stmt{c: c, stmt: stmt, tail: t}
if len(args) > 0 {
err := s.Bind(args)
if err != nil {
return s, err
}
}
return s, nil
} }
// Don't use it with SELECT or anything that returns data. // Don't use it with SELECT or anything that returns data.
......
...@@ -135,7 +135,7 @@ func TestInsertWithStatement(t *testing.T) { ...@@ -135,7 +135,7 @@ func TestInsertWithStatement(t *testing.T) {
t.Errorf("count should be 1000, but it is %d", i) t.Errorf("count should be 1000, but it is %d", i)
} }
rs, _ := db.Prepare("SELECT float_num, int_num, a_string FROM test ORDER BY int_num LIMIT 2") rs, _ := db.Prepare("SELECT float_num, int_num, a_string FROM test where a_string like ? ORDER BY int_num LIMIT 2", "hel%")
columnCount := rs.ColumnCount() columnCount := rs.ColumnCount()
if columnCount != 3 { if columnCount != 3 {
t.Errorf("column count error: %d <> 3", columnCount) t.Errorf("column count error: %d <> 3", columnCount)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment