Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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()
}
Exemplo n.º 3
0
func execute(t *testing.T, conn *db.Connection, stmt *db.Statement, ch chan int) {
	rs, cErr := conn.Execute(*stmt, rand.Int())
	if cErr != nil {
		error(t, cErr, "Couldn't select")
	}
	for res := range rs.Iter() {
		if res.Error() != nil {
			error(t, res.Error(), "Couldn't fetch")
		}
	}
	ch <- 1
}