func tsql() { runtime.GOMAXPROCS(util.CPU()) err := sql.AddDefault("mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local", 5, 8) if err != nil { fmt.Println(err.Error()) return } // time.Sleep(500 * time.Second) err = sql.AddDefault("mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local", 5, 8) if err != nil { fmt.Println(err.Error()) return } fmt.Println("add done...") rundb := func(v int) { fmt.Println("running->", v) iv, err := dbutil.DbQueryI(sql.Db(), "select 1") if err != nil { panic(err.Error()) } fmt.Println("done->", iv, v) } for { for i := 0; i < 5; i++ { go rundb(i) } time.Sleep(3 * time.Second) } fmt.Println("all done...") }
func tableColumnExist(db *sql.DB, table, column string) (bool, error) { dbname, err := dbutil.DbQueryStr(db, `SELECT DATABASE();`) if err != nil { return false, err } q := `SELECT count(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?` cnt, err := dbutil.DbQueryI(db, q, dbname, table, column) return cnt > 0, err }
func CheckDb(db *sql.DB) error { _, err := dbutil.DbQueryI(db, `SELECT COUNT(*) FROM EBS_BANK`) if err != nil { fmt.Println("table EBS_BANK not found") err = dbutil.DbExecScript(db, fsrv_sql) } db.Exec("alter table ebs_answer add column `paper_snapshot` longtext") db.Exec("alter table ebs_answer add column `analyze_snapshot` longtext") db.Exec("alter table ebs_answer add column `answer_snapshot` longtext") return err }
func (s *SQL_H) Ping(db interface{}) error { sdb := db.(*sql.DB) _, err := dbutil.DbQueryI(sdb, "select 1") return err }