Skip to content

Commit

Permalink
fix and support blob
Browse files Browse the repository at this point in the history
  • Loading branch information
isqijing committed Apr 23, 2024
1 parent db9b457 commit 3794680
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
4 changes: 2 additions & 2 deletions a_test/a_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/go-sql-driver/cloudwave"
_ "github.com/go-sql-driver/cloudwave"
"log"
"os"
"proxy.cloudwave.cn/share/go-sql-driver/cloudwave"
_ "proxy.cloudwave.cn/share/go-sql-driver/cloudwave"
"strconv"
"testing"
"time"
Expand Down
14 changes: 11 additions & 3 deletions a_test/junfenghe/types/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"proxy.cloudwave.cn/share/go-sql-driver/cloudwave"
"proxy.cloudwave.cn/share/go-sql-driver/cloudwave/a_test/junfenghe/common"
"testing"
)
Expand Down Expand Up @@ -49,7 +50,7 @@ func TestBlob(t *testing.T) {
if err != nil {
t.Error(err)
}
_, err = db.Exec(fmt.Sprintf("create table %s(id integer,c1 blob, primary key(id))", t.Name()))
_, err = db.Exec(fmt.Sprintf("create table %s(id integer,c1 blob)", t.Name()))
if err != nil {
t.Error(err)
}
Expand All @@ -62,12 +63,19 @@ func TestBlob(t *testing.T) {
t.Error(err)
}
log.Println(exec)

rows, err := db.Query("select * from " + t.Name())
for rows.Next() {
var id int
var c1 []byte
//var c1 []byte
var c1 *cloudwave.CloudBlob
rows.Scan(&id, &c1)
log.Println(id, string(c1))

bytes, err := c1.GetBytes()
if err != nil {
t.Error(err)
}
log.Println(id, string(bytes))
}

}
2 changes: 2 additions & 0 deletions cloudblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (blob *CloudBlob) length() (int64, error) {
return 0, err
}

/*
func (blob *CloudBlob) position(pattern []byte, start int64) (int64, error) {
if start <= 0 {
return 0, errors.New("position is less than 1")
Expand Down Expand Up @@ -90,6 +91,7 @@ func (blob *CloudBlob) position(pattern []byte, start int64) (int64, error) {
}
return 0, err
}
*/

func (blob *CloudBlob) getBinaryStream(position int64, length int64) error {
if position < 0 {
Expand Down
68 changes: 35 additions & 33 deletions command/b_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import (
"testing"
// "errors"
"fmt"
_ "github.com/go-sql-driver/cloudwave"
"log"
_ "proxy.cloudwave.cn/share/go-sql-driver/cloudwave"
"time"
)

func checkErr(err error) {
if err != nil {

func checkErr(err error){
if err != nil{
log.Fatal(err)
}
}

// / main //////////////////////////////////////////////////////////////
/// main //////////////////////////////////////////////////////////////
func TestB(t *testing.T) {
dbw := DbWorker{
Dsn: "system:CHANGEME@(127.0.0.1:1978)/toutiao", //本机翰云
Dsn: "system:CHANGEME@(127.0.0.1:1978)/toutiao", //本机翰云
}
var err error
dbw.Db, err = sql.Open("cloudwave", dbw.Dsn)
Expand All @@ -32,7 +33,7 @@ func TestB(t *testing.T) {
dbw.Db.SetMaxOpenConns(10)
dbw.Db.SetMaxIdleConns(10)

// dest, err := dbw.GetInfoNoparamCommon(GetNetworkStatus)
// dest, err := dbw.GetInfoNoparamCommon(GetNetworkStatus)
dest, err := dbw.GetInfoNoparamCommon(GetRuntimeReport)
if err == nil && dest != nil {
switch v := dest.(type) {
Expand All @@ -53,49 +54,50 @@ func TestB(t *testing.T) {
}
fmt.Println(dest)

// str, err := dbw.GetServerLogger("server", true, -10001000)
// fmt.Println(str)
// str, err := dbw.GetServerLogger("server", true, -10001000)
// fmt.Println(str)

// str, err := dbw.GetProcessJstack(false, "asdfg")
// fmt.Println(str)
// str, err := dbw.GetProcessJstack(false, "asdfg")
// fmt.Println(str)

// str, err = dbw.GetHealthDiagnostic(false) //有待调试
// fmt.Println(str)
// str, err = dbw.GetHealthDiagnostic(false) //有待调试
// fmt.Println(str)

// b, err := dbw.DoRestartServer("ss")
// fmt.Println(b)
// b, err := dbw.DoRestartServer("ss")
// fmt.Println(b)

// ss, err := dbw.GetSchemaNameList("catalog")
// fmt.Println(ss)
// ss, err := dbw.GetSchemaNameList("catalog")
// fmt.Println(ss)

// GetTableComment, GetTableNameList, GetViewNameList
// ss, err := dbw.GetNameList(GetTableComment, "catalog", []byte("toutiao"), []byte("table"))
// fmt.Println(ss)
// GetTableComment, GetTableNameList, GetViewNameList
// ss, err := dbw.GetNameList(GetTableComment, "catalog", []byte("toutiao"), []byte("table"))
// fmt.Println(ss)

// s, err := dbw.GetUserPrivileges("hu")
// fmt.Println(s)
// s, err := dbw.GetUserPrivileges("hu")
// fmt.Println(s)

// s, err := dbw.GetSQLStatistics(1000)
// fmt.Println(s)
// s, err := dbw.GetSQLStatistics(1000)
// fmt.Println(s)

// ss, err := dbw.GetTableDistribution("toutiao", "testtable", 0)
// fmt.Println(ss)
// ss, err := dbw.GetTableDistribution("toutiao", "testtable", 0)
// fmt.Println(ss)

// ss, err := dbw.GetTableDistributionStatistics("toutiao", "testtable")
// fmt.Println(ss)
// ss, err := dbw.GetTableDistributionStatistics("toutiao", "testtable")
// fmt.Println(ss)

// ss, err := dbw.GetTabletData("toutiao", "testtable", 0, 0)
// fmt.Println(ss)
// ss, err := dbw.GetTabletData("toutiao", "testtable", 0, 0)
// fmt.Println(ss)

// ss, err := dbw.GetResultTaskStatistics(0)
// fmt.Println(ss)
// ss, err := dbw.GetResultTaskStatistics(0)
// fmt.Println(ss)

// ss, err := dbw.GetTableColumns("toutiao", "testtable", 0)
// fmt.Println(ss)
// ss, err := dbw.GetTableColumns("toutiao", "testtable", 0)
// fmt.Println(ss)

ss, err := dbw.GetHistorySQLs()
fmt.Println(ss)

dbw.Db.Close()
fmt.Println("end")
}

22 changes: 14 additions & 8 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ func (stmt *cwStmt) readResultSetHeaderPacket2() (int, *textRows, error) {
// read meta data of server cursor's all columns
// first read column count
columnSize := int(binary.BigEndian.Uint32(data[pos:]))
stmt.autokeyFields = make([]bool, columnSize+4)
autokeyFieldsNo := 0
pos += 4
// extend enough columns
//CI_set_num_fields(res->fields, columnSize, TRUE);
Expand Down Expand Up @@ -468,9 +470,13 @@ func (stmt *cwStmt) readResultSetHeaderPacket2() (int, *textRows, error) {
}
pos++
isautokay, _ := regexp.MatchString("__WISDOM_AUTO_KEY__$", columns[j].name)
if !isautokay {
if isautokay {
stmt.autokeyFields[autokeyFieldsNo] = true
} else {
stmt.autokeyFields[autokeyFieldsNo] = false
j++
}
autokeyFieldsNo++
}
if pos <= len(data) {
if j == columnSize {
Expand Down Expand Up @@ -771,7 +777,7 @@ func (rows *textRows) readRow(dest []driver.Value) error {
}
pos += 4
i := 0
start := 1
autokeyFieldsNo := 0
for {
var scale int
if i >= len(dest) {
Expand All @@ -781,14 +787,14 @@ func (rows *textRows) readRow(dest []driver.Value) error {
if err != nil {
break
}
if start != 1 {
i++
}
start = 0
if tp != CLOUD_TYPE_ZONE_AUTO_SEQUENCE {

if tp != CLOUD_TYPE_ZONE_AUTO_SEQUENCE { // ??????
//i++
}

if !rows.stmt.autokeyFields[autokeyFieldsNo] {
i++
}
autokeyFieldsNo++
pos += n
scale = scale
/*
Expand Down
1 change: 1 addition & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type cwStmt struct {
cursorId int32
paramCount int
paramType []byte
autokeyFields []bool
}

func (stmt *cwStmt) Close() error {
Expand Down

0 comments on commit 3794680

Please sign in to comment.