Skip to content

Columns

Columns 方法用于返回列名。如果关闭 Rows,则列返回错误。

函数语法

func (s *Rows) Columns() ([]string, error)

示例

package main

import (
   _ "./go-driver-xugusql"
   "database/sql"
   “log”
)
func main() {
   db, _ := sql.Open("xugusql", "IP=192.168.78.130;DB=SYSTEM;User=SYSDBA;"
       + "PWD=SYSDBA;Port=5138;AUTO_COMMIT=on;CHAR_SET=UTF8")
   stmt, _ := db.Prepare(“select * from go_test where id = ?;”)
   rows, err := stmt.Query(3)
   if err != nil {
       log.Fatal(err)
   }
   var cols []string 
   cols, err = rows.Columns()
   if err != nil {
       log.Fatal(err)
   }
   for _, name := range cols {
       fmt.Printf(“%s\t”, name)
   }
   fmt.Printf(“\n”)
   rows.Close()
   stmt.Close()
   db.Close()
}