https://github.com/ganl/go-dm
达梦 Go 驱动源码 针对版本 DM8
https://github.com/ganl/go-dm
dm dm8 drivers golang sql
Last synced: 9 months ago
JSON representation
达梦 Go 驱动源码 针对版本 DM8
- Host: GitHub
- URL: https://github.com/ganl/go-dm
- Owner: ganl
- Created: 2023-03-01T14:35:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T15:29:42.000Z (about 3 years ago)
- Last Synced: 2025-02-09T10:30:59.105Z (about 1 year ago)
- Topics: dm, dm8, drivers, golang, sql
- Language: Go
- Homepage:
- Size: 473 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Security: security/zy.go
Awesome Lists containing this project
README
# go-dm
达梦官方 Go 驱动源码
DM 8.0+
Go 1.13+
源码来源于官方安装包,驱动包的路径: `dmdbms/drivers/go/dm-go-driver.zip` , 详见说明: [Go 数据库接口](https://eco.dameng.com/document/dm/zh-cn/app-dev/go-go.html)
## DataSourceName
```
dm://username:password@host:port?schema=schemaName[&logLevel=debug&sslFilesPath&=pathValue&timeout=timeoutValue¶m1=value1&...¶mN=valueN]
```
`dm://SYSDBA:SYSDBA@localhost:5236`
## Example
`go get github.com/ganl/go-dm@v1.2.193`
PS: 8.1.2.192 / 8.2.2.192 官方未改驱动构建32位,编译报错: constant 4294967295 overflows int
```golang
package main
import (
"database/sql"
_ "github.com/ganl/go-dm"
"log"
)
func main() {
//url := "dm://" + os.Getenv("dm_username") + ":" + os.Getenv("dm_password") + "@" + os.Getenv("dm_host") + "?noConvertToHex=true"
conn, err := sql.Open("dm", "dm://SYSDBA:SYSDBA@192.168.100.168:7777")
if err != nil {
log.Fatal(err)
return
}
defer conn.Close()
for _, sqlstr := range []string{
"DROP TABLE IF EXISTS tmp_testabc",
`CREATE TABLE tmp_testabc (
id bigint primary key,
name varchar(12)
)`,
} {
_, err := conn.Exec(sqlstr)
if err != nil {
log.Fatal(err)
return
}
}
var id int64
sqlstr := "insert into tmp_testabc(id, name) values(1, 'a') returning id into :id"
_, err = conn.Exec(sqlstr, sql.Out{Dest: &id})
if err != nil {
log.Fatal(err)
return
}
if id != 1{
log.Fatal("Error cmp")
}
sqlstr = "insert into tmp_testabc(id, name) values(2, 'b') returning id into :id"
_, err = conn.Exec(sqlstr, sql.Named("id123", sql.Out{Dest: &id}))
if err != nil {
log.Fatal(err)
return
}
if id != 2{
log.Fatal("Error cmp")
}
}
```