diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7d6ed0f..609505c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -77,7 +77,7 @@ jobs: cd TDengine mkdir debug cd debug - cmake .. -DBUILD_JDBC=false -DBUILD_TEST=off -DBUILD_HTTP=false -DVERNUMBER=3.9.9.9 -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + cmake .. -DBUILD_TEST=off -DBUILD_HTTP=false -DVERNUMBER=3.9.9.9 -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache make -j 4 - name: package diff --git a/wrapper/stmt.go b/wrapper/stmt.go index e7b4908..5bba031 100644 --- a/wrapper/stmt.go +++ b/wrapper/stmt.go @@ -15,6 +15,7 @@ import ( "github.com/taosdata/driver-go/v3/common" "github.com/taosdata/driver-go/v3/common/stmt" + taosError "github.com/taosdata/driver-go/v3/errors" taosTypes "github.com/taosdata/driver-go/v3/types" ) @@ -709,3 +710,15 @@ func StmtParseFields(num int, fields unsafe.Pointer) []*stmt.StmtField { func TaosStmtReclaimFields(stmt unsafe.Pointer, fields unsafe.Pointer) { C.taos_stmt_reclaim_fields(stmt, (*C.TAOS_FIELD_E)(fields)) } + +// TaosStmtGetParam DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) +func TaosStmtGetParam(stmt unsafe.Pointer, idx int) (dataType int, dataLength int, err error) { + code := C.taos_stmt_get_param(stmt, C.int(idx), (*C.int)(unsafe.Pointer(&dataType)), (*C.int)(unsafe.Pointer(&dataLength))) + if code != 0 { + err = &taosError.TaosError{ + Code: int32(code), + ErrStr: TaosStmtErrStr(stmt), + } + } + return +} diff --git a/wrapper/stmt_test.go b/wrapper/stmt_test.go index 4d120e6..07878b4 100644 --- a/wrapper/stmt_test.go +++ b/wrapper/stmt_test.go @@ -1145,3 +1145,46 @@ func TestTaosStmtSetTags(t *testing.T) { assert.Equal(t, int32(102), data[0][2].(int32)) assert.Equal(t, []byte(`{"a":"b"}`), data[0][3].([]byte)) } + +func TestTaosStmtGetParam(t *testing.T) { + conn, err := TaosConnect("", "root", "taosdata", "", 0) + assert.NoError(t, err) + defer TaosClose(conn) + + err = exec(conn, "drop database if exists test_stmt_get_param") + assert.NoError(t, err) + err = exec(conn, "create database if not exists test_stmt_get_param") + assert.NoError(t, err) + defer exec(conn, "drop database if exists test_stmt_get_param") + + err = exec(conn, + "create table if not exists test_stmt_get_param.stb(ts TIMESTAMP,current float,voltage int,phase float) TAGS (groupid int,location varchar(24))") + assert.NoError(t, err) + + stmt := TaosStmtInit(conn) + assert.NotNilf(t, stmt, "failed to init stmt") + defer TaosStmtClose(stmt) + + code := TaosStmtPrepare(stmt, "insert into test_stmt_get_param.tb_0 using test_stmt_get_param.stb tags(?,?) values (?,?,?,?)") + assert.Equal(t, 0, code, TaosStmtErrStr(stmt)) + + dt, dl, err := TaosStmtGetParam(stmt, 0) // ts + assert.NoError(t, err) + assert.Equal(t, 9, dt) + assert.Equal(t, 8, dl) + + dt, dl, err = TaosStmtGetParam(stmt, 1) // current + assert.NoError(t, err) + assert.Equal(t, 6, dt) + assert.Equal(t, 4, dl) + + dt, dl, err = TaosStmtGetParam(stmt, 2) // voltage + assert.NoError(t, err) + assert.Equal(t, 4, dt) + assert.Equal(t, 4, dl) + + dt, dl, err = TaosStmtGetParam(stmt, 3) // phase + assert.NoError(t, err) + assert.Equal(t, 6, dt) + assert.Equal(t, 4, dl) +} diff --git a/wrapper/taosc.go b/wrapper/taosc.go index 8eec92f..2e952a2 100644 --- a/wrapper/taosc.go +++ b/wrapper/taosc.go @@ -266,3 +266,24 @@ func TaosGetTablesVgID(conn unsafe.Pointer, db string, tables []string) (vgIDs [ func TaosSetConnMode(conn unsafe.Pointer, mode int, value int) int { return int(C.taos_set_conn_mode(conn, C.int(mode), C.int(value))) } + +// TaosGetCurrentDB DLL_EXPORT int taos_get_current_db(TAOS *taos, char *database, int len, int *required) +func TaosGetCurrentDB(conn unsafe.Pointer) (db string, err error) { + cDb := C.CString(db) + defer C.free(unsafe.Pointer(cDb)) + var required int + + code := C.taos_get_current_db(conn, cDb, C.int(193), (*C.int)(unsafe.Pointer(&required))) + if code != 0 { + err = errors.NewError(int(code), TaosErrorStr(nil)) + } + db = C.GoString(cDb) + + return +} + +// TaosGetServerInfo DLL_EXPORT const char *taos_get_server_info(TAOS *taos) +func TaosGetServerInfo(conn unsafe.Pointer) string { + info := C.taos_get_server_info(conn) + return C.GoString(info) +} diff --git a/wrapper/taosc_test.go b/wrapper/taosc_test.go index cd7dafa..5db50e6 100644 --- a/wrapper/taosc_test.go +++ b/wrapper/taosc_test.go @@ -562,3 +562,28 @@ func TestTaosSetConnMode(t *testing.T) { t.Errorf("TaosSetConnMode() error code= %d, msg: %s", code, TaosErrorStr(nil)) } } + +func TestTaosGetCurrentDB(t *testing.T) { + conn, err := TaosConnect("", "root", "taosdata", "", 0) + assert.NoError(t, err) + defer TaosClose(conn) + dbName := "current_db_test" + _ = exec(conn, fmt.Sprintf("drop database if exists %s", dbName)) + err = exec(conn, fmt.Sprintf("create database %s", dbName)) + assert.NoError(t, err) + defer func() { + _ = exec(conn, fmt.Sprintf("drop database if exists %s", dbName)) + }() + _ = exec(conn, fmt.Sprintf("use %s", dbName)) + db, err := TaosGetCurrentDB(conn) + assert.NoError(t, err) + assert.Equal(t, dbName, db) +} + +func TestTaosGetServerInfo(t *testing.T) { + conn, err := TaosConnect("", "root", "taosdata", "", 0) + assert.NoError(t, err) + defer TaosClose(conn) + info := TaosGetServerInfo(conn) + assert.NotEmpty(t, info) +}