This blog post is outdated. Meanwhile there are two Go SQL drivers available for SAP ASE:
Please don't hesitate to raise issue at https://github.com/SAP/go-ase/issues and https://github.com/SAP/cgo-ase/issues.
You will find similar examples like the one of this blog post in the documentation of the above repositories.
# as root
wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz
zypper in gcc
# as syb<sid>
setenv PATH "$PATH":/usr/local/go/bin
mkdir myGoProgram
cd myGoProgram
vi main.go
package main
import (
"database/sql"
"flag"
"fmt"
"os"
_ "github.com/SAP/go-ase/cgo"
"github.com/SAP/go-ase/libase/libdsn"
)
func main() {
var login string
flag.StringVar(&login, "login", "sa", "login you want to examine")
flag.Parse()
dsn := libdsn.NewDsnInfoFromEnv("")
db, err := sql.Open("ase", dsn.AsSimple())
if err != nil {
fmt.Fprintf(os.Stderr, "Could not open database: %v", err)
return
}
defer db.Close()
err = db.Ping()
if err != nil {
fmt.Fprintf(os.Stderr, "Could not ping database: %v", err)
return
}
rows, err := db.Query("select dbname from master..syslogins where name = '?'", login)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not query database: %v", err)
return
}
defer rows.Close()
var dbname string
for rows.Next() {
err := rows.Scan(&dbname)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not scan rows: %v", err)
return
}
fmt.Printf("Database of %s is %s.\n", login, dbname)
}
return
err = rows.Err()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return
}
}
go mod init myGoProgram
go mod tidy
setenv CGO_LDFLAGS "-L$SYBASE/OCS-16_0/lib -lsybct_r64 -lsybcs_r64"
go build
setenv ASE_HOST '<host>'
setenv ASE_PORT 4901
setenv ASE_USER sapsa
setenv ASE_PASS '<pass>'
./myGoProgram
Database of sa is master.
./myGoProgram -login sapsso
Database of sapsso is master.
./myGoProgram -login sapsa
Database of sapsa is saptools.
setenv ASE_USERSTOREKEY SAPSA
./myGoProgram
Database of sa is master.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
25 | |
13 | |
13 | |
12 | |
10 | |
9 | |
9 | |
8 | |
6 | |
6 |