func findRand(t *testing.T, conn *db.Connection, ch chan *vector.Vector) { stmt, sErr := conn.Prepare( "SELECT * FROM t WHERE i != ? ORDER BY RAND()") if sErr != nil { error(t, sErr, "Couldn't prepare") } rs, cErr := conn.Execute(stmt, rand.Int()) if cErr != nil { error(t, cErr, "Couldn't select") } vout := new(vector.Vector) for res := range rs.Iter() { if res.Error() != nil { error(t, res.Error(), "Couldn't fetch") } vout.Push(res.Data()) } if vout.Len() != len(tableT) { t.Error("Invalid length") } stmt.Close() ch <- vout }
func prepareTestTable(t *testing.T, conn *db.Connection) { stmt, sErr := conn.Prepare( "CREATE TEMPORARY TABLE t (i INT, s VARCHAR(100));") if sErr != nil { error(t, sErr, "Couldn't prepare statement") return } rs, cErr := conn.Execute(stmt) if cErr != nil { error(t, cErr, "Couldn't create temporary table test.t") return } rs.Close() stmt, sErr = conn.Prepare("INSERT INTO t (i, s) VALUES (?, ?)") if sErr != nil { error(t, sErr, "Couldn't prepare statement") return } for i, s := range tableT { rs, cErr = conn.Execute(stmt, i, s) if cErr != nil { error(t, cErr, "Couldn't insert into temporary table test.t") return } rs.Close() } stmt.Close() }
func prepareEmpty(t *testing.T, conn *db.Connection, ch chan int) { stmt, sErr := conn.Prepare( "SELECT * FROM t ORDER BY RAND()") if sErr != nil { error(t, sErr, "Couldn't prepare") } stmt.Close() ch <- 1 }