dmdb

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

dmdb

达梦go驱动

该项目包装了odbc驱动,以解决达梦数据库string类型数据编码问题。

解决的问题

windows平台中,达梦数据库使用odbc驱动时,所有的字符串类型数据,将按照gbk编码返回,需要额外编写代码转换回utf-8,否则go语言中将是乱码。该项目拦截了Scan操作,自动对所有的[]byte类型进行编码转换。

示例

package main

import (
	"database/sql"

	_ "github.com/linlexing/dmdb"

	_ "github.com/alexbrainman/odbc"
)

func main() {
	db1, err := sql.Open("odbc", "driver={DM8 ODBC DRIVER};server=localhost:5236;database=DMSERVER;uid=test;pwd=123456789;charset=UTF8;")
	if err != nil {
		panic(err)
	}
	defer db1.Close()
	db2, err := sql.Open("dmdb", "driver={DM8 ODBC DRIVER};server=localhost:5236;database=DMSERVER;uid=test;pwd=123456789;charset=UTF8;")
	if err != nil {
		panic(err)
	}
	defer db2.Close()

	var str1, str2 string
	if err := db1.QueryRow("select '测试'").Scan(&str1); err != nil {
		panic(err)
	}
	if err := db2.QueryRow("select '测试'").Scan(&str2); err != nil {
		panic(err)
	}
	println("odbc:", str1, ",dmdb:", str2)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

func (*Conn) Close

func (c *Conn) Close() (err error)

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func (*Driver) Close

func (d *Driver) Close() error

func (*Driver) Open

func (d *Driver) Open(dsn string) (driver.Conn, error)

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

func (*Rows) Close

func (r *Rows) Close() error

func (*Rows) ColumnTypeDatabaseTypeName

func (r *Rows) ColumnTypeDatabaseTypeName(index int) string

ColumnTypeDatabaseTypeName 附加的

func (*Rows) Columns

func (r *Rows) Columns() []string

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) error

linux不需要转换编码

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

func (*Stmt) Close

func (s *Stmt) Close() error

func (*Stmt) Exec

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

func (*Stmt) Query

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL