33 lines
765 B
Go
33 lines
765 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
_ "github.com/denisenkom/go-mssqldb"
|
|
)
|
|
|
|
func getColumnNames(tableName string) (string, error) {
|
|
ctx := context.Background()
|
|
checkIsDatabaseAlive()
|
|
tsql := "SELECT * FROM " + tableName
|
|
rows, _ := db.QueryContext(ctx, tsql)
|
|
collection, _ := rows.Columns()
|
|
var toReturn string
|
|
for _, element := range collection {
|
|
toReturn += element + "."
|
|
}
|
|
return toReturn, nil
|
|
}
|
|
func getColumnTypes(tableName string) (string, error) {
|
|
ctx := context.Background()
|
|
checkIsDatabaseAlive()
|
|
tsql := "SELECT * FROM " + tableName
|
|
rows, _ := db.QueryContext(ctx, tsql)
|
|
collection, _ := rows.ColumnTypes()
|
|
var toReturn string
|
|
for _, element := range collection {
|
|
toReturn += element.DatabaseTypeName() + "."
|
|
}
|
|
return toReturn, nil
|
|
}
|