package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/godror/godror"
)
type str_item struct {
item_cd string
item_nm string
}
type str_item_ls struct {
str_item []str_item
}
func (item_ls *str_item_ls) AddItem(item str_item) []str_item {
item_ls.str_item = append(item_ls.str_item, item)
return item_ls.str_item
}
func get_list(sql_str string, item_cnt int, item_list *str_item_ls, c chan bool) {
// 본인 계정에 맞는 접속 정보
db, err := sql.Open("godror", "db_account/db_password@db_name")
db.SetMaxOpenConns(5)
db.SetMaxIdleConns(3)
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
conn, err := db.Query(sql_str, item_cnt)
if err != nil {
fmt.Println(err)
return
}
defer conn.Close()
item := new(str_item)
var item_cd string
var item_nm string
for conn.Next() {
err := conn.Scan(&item_cd, &item_nm)
if err != nil {
log.Fatal(err)
}
item.item_cd = item_cd
item.item_nm = item_nm
item_list.AddItem(*item)
}
c <- true
}
func main() {
c := make(chan bool)
item_list := new(str_item_ls)
// 본인 DB 테이블 조회
go get_list("select tname,tabtype from tab where substr(tname,1,1) in ('A','B','C','D','E','F','G','H','I') and rownum <= :val", 6, item_list, c)
go get_list("select tname,tabtype from tab where substr(tname,1,1) in ('J','K','L','M','N','O','P','Q','R') and rownum <= :val", 6, item_list, c)
go get_list("select tname,tabtype from tab where substr(tname,1,1) in ('S','T','U','V','W','X','Y','Z') and rownum <= :val", 6, item_list, c)
for i := 0; i < 3; i++ {
fmt.Println(<-c)
}
for i, s := range item_list.str_item {
fmt.Println(s.item_cd, s.item_nm, i)
}
}
comments powered by Disqus