MCPcopy Create free account
hub / github.com/actiontech/dtle / ListColumns

Function ListColumns

driver/mysql/sql/sqlutils.go:376–395  ·  view source on GitHub ↗
(db *gosql.DB, dbName, tableName string)

Source from the content-addressed store, hash-verified

374}
375
376func ListColumns(db *gosql.DB, dbName, tableName string) (columns []string, err error) {
377 // Get table columns name
378 query := "select COLUMN_NAME from information_schema.columns where table_schema=? and table_name=? order by ORDINAL_POSITION"
379 rows, err := db.Query(query, dbName, tableName)
380 if err != nil {
381 return columns, err
382 }
383 defer rows.Close()
384
385 // Read result
386 for rows.Next() {
387 var column gosql.NullString
388 err = rows.Scan(&column)
389 if err != nil {
390 return columns, err
391 }
392 columns = append(columns, column.String)
393 }
394 return columns, rows.Err()
395}
396
397func CloseDB(db *gosql.DB) error {
398 if db == nil {

Callers 1

listMySQLColumnsFunction · 0.92

Calls 2

ScanMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected