2018-12-22 15:56:43 +01:00
|
|
|
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
|
|
|
|
}
|
2019-01-11 22:49:42 +01:00
|
|
|
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
|
|
|
|
}
|