Beispiel #1
0
func (db *TestDatabase) populate(t *testing.T, table *sqlite3.Table) {
	switch table.Name {
	case "foo":
		db.runQuery(t, "INSERT INTO foo values (1, 'this is a test')")
		db.runQuery(t, "INSERT INTO foo values (?, ?)", 2, "holy moly")
		if c, _ := table.Rows((*sqlite3.Database)(db)); c != 2 {
			t.Fatal("Failed to populate %v", table.Name)
		}
	case "bar":
		db.runQuery(t, "INSERT INTO bar values (1, 'this is a test')")
		db.runQuery(t, "INSERT INTO bar values (?, ?)", 2, "holy moly")
		db.runQuery(t, "INSERT INTO bar values (?, ?)", 3, TwoItems{"holy moly", "guacomole"})
		if c, _ := table.Rows((*sqlite3.Database)(db)); c != 3 {
			t.Fatal("Failed to populate %v", table.Name)
		}
	}
}
Beispiel #2
0
func (db *TestDatabase) stepThroughRows(t *testing.T, table *sqlite3.Table) (c int) {
	var e error
	sql := fmt.Sprintf("SELECT * from %v;", table.Name)
	c, e = (*sqlite3.Database)(db).Execute(sql, func(st *sqlite3.Statement, values ...interface{}) {
		data := values[1]
		switch data := data.(type) {
		case *gob.Decoder:
			blob := &TwoItems{}
			data.Decode(blob)
			t.Logf("BLOB =>   %v: %v, %v: %v\n", sqlite3.ResultColumn(0).Name(st), sqlite3.ResultColumn(0).Value(st), st.ColumnName(1), blob)
		default:
			t.Logf("TEXT => %v: %v, %v: %v\n", sqlite3.ResultColumn(0).Name(st), sqlite3.ResultColumn(0).Value(st), st.ColumnName(1), st.Column(1))
		}
	})
	fatalOnError(t, e, "%v failed on step %v", sql, c)
	if rows, _ := table.Rows((*sqlite3.Database)(db)); rows != c {
		t.Fatalf("%v: %v rows expected, %v rows found", table.Name, rows, c)
	}
	return
}