0
package main

import (
        "fmt"
        "database/sql"
        _ "github.com/go-sql-driver/mysql"

)

type Tag struct {
        Table_name string `json:"table_name"`
}

func main() {
        db, err := sql.Open("mysql", "root:roadrunner@tcp(172.31.16.82:10002)/quote_data")
        if err != nil {
                //panic.(err.Error())
                fmt.Println("Connected Fail")
        }
        fmt.Println("Connected")
        defer db.Close()
        result, err1 := db.Query("SELECT table_name FROM information_schema.tables WHERE table_type = 'base table' AND table_schema='quote_data'")
        if err1 != nil {
                panic(err1.Error())
        }
        fmt.Println("Showing Tables",result)
        for results.Next() {
                var tag Tag
                err1 = results.Scan(&tag.Table_name)
                if err1 != nil {
                        panic(err.Error())
                }
                log.Printf(tag.Table_name)
        }
}
2
  • 4
    Welcome to stackoverflow, what is your question? Could you provide more details about your idea? Commented Apr 6, 2022 at 11:14
  • The database information_schema is not case insensitive, so change table_type = 'base table' to table_type = 'BASE TABLE'. Commented Apr 6, 2022 at 16:23

1 Answer 1

2

you must add type db with table_name to initialize database table

type Tag struct {
        Table_name string `db:"table_name" json:"table_name"`
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.