Commit 75ce7b1c authored by gwenn's avatar gwenn

Add BindParameterName method.

parent f6df9a69
...@@ -21,7 +21,7 @@ Conn#Begin/BeginTransaction(type)/Commit/Rollback ...@@ -21,7 +21,7 @@ Conn#Begin/BeginTransaction(type)/Commit/Rollback
Conn#GetAutocommit Conn#GetAutocommit
Stmt#ExecUpdate Stmt#ExecUpdate
Stmt#BindParameterCount/BindParameterIndex Stmt#BindParameterCount/BindParameterIndex/BindParameterName
Stmt#ClearBindings Stmt#ClearBindings
Stmt#ColumnCount/ColumnIndex(name)/ColumnName(index)/ColumnType Stmt#ColumnCount/ColumnIndex(name)/ColumnName(index)/ColumnType
......
...@@ -406,6 +406,13 @@ func (s *Stmt) BindParameterIndex(name string) int { ...@@ -406,6 +406,13 @@ func (s *Stmt) BindParameterIndex(name string) int {
return int(C.sqlite3_bind_parameter_index(s.stmt, cname)) return int(C.sqlite3_bind_parameter_index(s.stmt, cname))
} }
// The first host parameter has an index of 1, not 0.
// Calls http://sqlite.org/c3ref/bind_parameter_name.html
func (s *Stmt) BindParameterName(i int) string {
return C.GoString(C.sqlite3_bind_parameter_name(s.stmt, C.int(i)))
}
// Calls sqlite3_bind_parameter_count and sqlite3_bind_(blob|double|int|int64|null|text) depending on args type. // Calls sqlite3_bind_parameter_count and sqlite3_bind_(blob|double|int|int64|null|text) depending on args type.
// http://sqlite.org/c3ref/bind_blob.html // http://sqlite.org/c3ref/bind_blob.html
func (s *Stmt) Bind(args ...interface{}) os.Error { func (s *Stmt) Bind(args ...interface{}) os.Error {
......
...@@ -168,7 +168,7 @@ func TestInsertWithStatement(t *testing.T) { ...@@ -168,7 +168,7 @@ func TestInsertWithStatement(t *testing.T) {
db := open(t) db := open(t)
defer db.Close() defer db.Close()
createTable(db, t) createTable(db, t)
s, serr := db.Prepare("INSERT INTO test (float_num, int_num, a_string) VALUES (?, ?, ?)") s, serr := db.Prepare("INSERT INTO test (float_num, int_num, a_string) VALUES (:f, :i, :s)")
if serr != nil { if serr != nil {
t.Fatalf("prepare error: %s", serr) t.Fatalf("prepare error: %s", serr)
} }
...@@ -181,6 +181,14 @@ func TestInsertWithStatement(t *testing.T) { ...@@ -181,6 +181,14 @@ func TestInsertWithStatement(t *testing.T) {
if paramCount != 3 { if paramCount != 3 {
t.Errorf("bind parameter count error: %d <> 3", paramCount) t.Errorf("bind parameter count error: %d <> 3", paramCount)
} }
firstParamName := s.BindParameterName(1)
if firstParamName != ":f" {
t.Errorf("bind parameter name error: %s <> ':f'", firstParamName)
}
lastParamIndex := s.BindParameterIndex(":s")
if lastParamIndex != 3 {
t.Errorf("bind parameter name error: %d <> 3", lastParamIndex)
}
db.Begin() db.Begin()
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
......
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