Open fishdemon opened 5 months ago
官方代码: package main
import ( "database/sql" "fmt" _ "github.com/taosdata/driver-go/v2/taosSql" "time" )
func main() { var taosuri = "root:taosdata/tcp(localhost:6030)/" taos, err := sql.Open("taosSql", taosuri) if err != nil { fmt.Println("failed to connect TDengine, err:", err) return } defer taos.Close() taos.Exec("create database if not exists test") taos.Exec("use test") taos.Exec("create table if not exists tb1 (ts timestamp, a int)") _, err = taos.Exec("insert into tb1 values(now, 0)(now+1s,1)(now+2s,2)(now+3s,3)") if err != nil { fmt.Println("failed to insert, err:", err) return } rows, err := taos.Query("select * from tb1") if err != nil { fmt.Println("failed to select from table, err:", err) return }
defer rows.Close()
for rows.Next() {
var r struct {
ts time.Time
a int
}
err := rows.Scan(&r.ts, &r.a)
if err != nil {
fmt.Println("scan error:\n", err)
return
}
fmt.Println(r.ts, r.a)
}
}
请问,你们自己的官方示例都无法通过么
涉及到了 C 库,不要交叉编译。比较麻烦。
采用的官方示例
自编译:
go build -o tdengine-sync main.go 报错 github.com/taosdata/driver-go/v2/wrapper ../../../../../go/pkg/mod/github.com/taosdata/driver-go/v2@v2.0.6/wrapper/stmt.go:46:58: could not determine kind of name for C.TAOS_BIND
交叉编译:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o tdengine-sync main.go 报错 github.com/taosdata/driver-go/v2/wrapper: build constraints exclude all Go files in /Users/aallenma/go/pkg/mod/github.com/taosdata/driver-go/v2@v2.0.6/wrapper
不论怎么编译都报错