b43f968b6c
- 在应用程序中新增对达梦数据库(DM)的配置和连接支持 - 实现 SetDmDB 函数以配置达梦数据库连接 - 更新数据库操作逻辑,支持达梦特有的 SQL 语法和功能 - 在相关文件中添加达梦数据库的处理逻辑,包括表创建、数据插入和查询 - 更新 go.mod 和 go.sum 文件以引入达梦数据库驱动 - 增强文档,详细说明达梦数据库的配置和使用方法
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
/*
|
|
* Copyright (c) 2000-2018, 达梦数据库有限公司.
|
|
* All rights reserved.
|
|
*/
|
|
package dm
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/zlib"
|
|
"github.com/golang/snappy"
|
|
)
|
|
|
|
func Compress(srcBuffer *Dm_build_78, offset int, length int, compressID int) ([]byte, error) {
|
|
if compressID == Dm_build_786 {
|
|
return snappy.Encode(nil, srcBuffer.Dm_build_372(offset, length)), nil
|
|
}
|
|
return GzlibCompress(srcBuffer, offset, length)
|
|
}
|
|
|
|
func UnCompress(srcBytes []byte, compressID int) ([]byte, error) {
|
|
if compressID == Dm_build_786 {
|
|
return snappy.Decode(nil, srcBytes)
|
|
}
|
|
return GzlibUncompress(srcBytes)
|
|
}
|
|
|
|
func GzlibCompress(srcBuffer *Dm_build_78, offset int, length int) ([]byte, error) {
|
|
var ret bytes.Buffer
|
|
var w = zlib.NewWriter(&ret)
|
|
w.Write(srcBuffer.Dm_build_372(offset, length))
|
|
w.Close()
|
|
return ret.Bytes(), nil
|
|
}
|
|
|
|
func GzlibUncompress(srcBytes []byte) ([]byte, error) {
|
|
var bytesBuf = new(bytes.Buffer)
|
|
r, err := zlib.NewReader(bytes.NewReader(srcBytes))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer r.Close()
|
|
_, err = bytesBuf.ReadFrom(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return bytesBuf.Bytes(), nil
|
|
}
|