Example #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
}
Example #2
0
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
}
Example #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
}
Example #4
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()
}
Example #5
0
func GetTable(name string, c db.Connection) (t Table, err os.Error) {
	t.TableSchema, err = c.GetTable(name)
	return
}