Ejemplo n.º 1
0
func main() {
	defer dbg.Trace(time.Now())
	a := 0
	for x := 0; x < 1000000000; x++ {
		a++
	}
}
func executa() {
	db, err := sql.Open("oci8", getDSN())
	if err != nil {
		fmt.Println(err)
		return
	}
	defer db.Close()

	times := 3

	selects := []string{"select uf_st_sigla, log_st_nome from mgglo.glo_logradouro",
		"select acaom_st_documento, lan_ch_tipocontab from mgglo.glo_acaomovimento",
		"select ref_st_tipo, org_tau_st_codigo from mgfin.fin_referenciafin"}
	queries := make([]*sql.Rows, 0, times)

	/*for x := 0; x < times; x++ {

		rows, err := db.Query(selects[x])
		if err != nil {
			fmt.Println(err)
		}
		rows.Next()
		queries = append(queries, rows)
	}*/

	defer dbg.Trace(time.Now())

	var wg sync.WaitGroup
	wg.Add(times)

	//var m sync.Mutex

	total := 0

	for x := 0; x < times; x++ {
		rows, err := db.Query(selects[x])
		if err != nil {
			fmt.Println(err)
		}
		queries = append(queries, rows)
		for {

			//m.Lock()
			if queries[x].Next() {
				var f1 string
				var f2 string
				queries[x].Scan(&f1, &f2)
				total++
				//fmt.Println(f1)
				if f1 == f2 {
				}
				//println(f1, f2)
				//m.Unlock()
			} else {
				//m.Unlock()
				break
			}

		}
		rows.Close()
		wg.Done()

		/*go func(rows *sql.Rows, wg *sync.WaitGroup) {

			for {
				//m.Lock()
				if rows.Next() {
					var f1 string
					var f2 string
					rows.Scan(&f1, &f2)
					//fmt.Println(f1)
					total++
					if f1 == f2 {
					}
					//println(f1, f2)
					//m.Unlock()
				} else {
					//m.Unlock()
					break
				}

			}
			wg.Done()
		}(queries[x], &wg)*/
	}
	wg.Wait()
	fmt.Println(total)

	/*if err != nil {
		fmt.Println(err)
	}
	defer rows.Close()

	for rows.Next() {
		var f1 string
		var f2 string
		rows.Scan(&f1, &f2)
		println(f1, f2)
	}*/
}