Example #1
0
File: db.go Project: dgdn/goutil
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
}
Example #2
0
File: db.go Project: dgdn/goutil
func tableExist(db *sql.DB, table string) (bool, error) {
	str, err := dbutil.DbQueryStr(db, `show tables like ?`, table)
	return str != "", err
}