Commit 50898ecf authored by gwenn's avatar gwenn

Adds some tests.

parent 8661f631
......@@ -324,9 +324,9 @@ func (s *Stmt) BindParameterIndex(name string) int {
}
func (s *Stmt) Bind(args ...interface{}) os.Error {
rv := C.sqlite3_reset(s.stmt)
if rv != 0 {
return s.c.error(rv)
err := s.Reset()
if err != nil {
return err
}
n := s.BindParameterCount()
......@@ -335,6 +335,7 @@ func (s *Stmt) Bind(args ...interface{}) os.Error {
}
for i, v := range args {
var rv C.int
index := C.int(i + 1)
switch v := v.(type) {
case nil:
......@@ -393,6 +394,7 @@ func (s *Stmt) ColumnCount() int {
return int(C.sqlite3_column_count(s.stmt))
}
// The leftmost column is number 0.
func (s *Stmt) ColumnName(index int) string {
return C.GoString(C.sqlite3_column_name(s.stmt, C.int(index)))
}
......
package sqlite
import (
"strings"
"testing"
"os"
)
......@@ -25,6 +26,13 @@ func createTable(db *Conn, t *testing.T) {
}
}
func TestVersion(t *testing.T) {
v := Version()
if !strings.HasPrefix(v, "3") {
t.Fatalf("unexpected library version: %s", v)
}
}
func TestOpen(t *testing.T) {
db := open(t)
db.Close()
......@@ -51,8 +59,23 @@ func TestInsert(t *testing.T) {
}
}
lastId := db.LastInsertRowid()
if lastId != 1000 {
t.Errorf("last insert row id error: %d <> 1000", lastId)
}
cs, _ := db.Prepare("SELECT COUNT(*) FROM test")
defer cs.Finalize()
paramCount := cs.BindParameterCount()
if paramCount != 0 {
t.Errorf("bind parameter count error: %d <> 0", paramCount)
}
columnCount := cs.ColumnCount()
if columnCount != 1 {
t.Errorf("column count error: %d <> 1", columnCount)
}
if ok, err := cs.Next(); !ok {
if err != nil {
t.Fatalf("error preparing count: %s", err)
......@@ -82,6 +105,11 @@ func TestInsertWithStatement(t *testing.T) {
}
defer s.Finalize()
paramCount := s.BindParameterCount()
if paramCount != 3 {
t.Errorf("bind parameter count error: %d <> 3", paramCount)
}
for i := 0; i < 1000; i++ {
ierr := s.Exec(float64(i)*float64(3.14), i, "hello")
if ierr != nil {
......@@ -108,6 +136,15 @@ func TestInsertWithStatement(t *testing.T) {
}
rs, _ := db.Prepare("SELECT float_num, int_num, a_string FROM test ORDER BY int_num LIMIT 2")
columnCount := rs.ColumnCount()
if columnCount != 3 {
t.Errorf("column count error: %d <> 3", columnCount)
}
secondColumnName := rs.ColumnName(1)
if secondColumnName != "int_num" {
t.Errorf("column name error: %s <> 'int_num'", secondColumnName)
}
var fnum float64
var inum int64
var sstr string
......
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