Skip to content

Commit

Permalink
Support execute non query statement (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
HTHou authored Nov 25, 2022
1 parent a05323c commit e7dcc09
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions client/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,25 @@ func (s *Session) ExecuteStatement(sql string) (*SessionDataSet, error) {
return s.genDataSet(sql, resp), err
}

func (s *Session) ExecuteNonQueryStatement(sql string) (r *rpc.TSStatus, err error) {
request := rpc.TSExecuteStatementReq{
SessionId: s.sessionId,
Statement: sql,
StatementId: s.requestStatementId,
FetchSize: &s.config.FetchSize,
}
resp, err := s.client.ExecuteStatement(context.Background(), &request)

if err != nil && resp == nil {
if s.reconnect() {
request.SessionId = s.sessionId
resp, err = s.client.ExecuteStatement(context.Background(), &request)
}
}

return resp.Status, err
}

func (s *Session) ExecuteQueryStatement(sql string, timeoutMs *int64) (*SessionDataSet, error) {
request := rpc.TSExecuteStatementReq{SessionId: s.sessionId, Statement: sql, StatementId: s.requestStatementId,
FetchSize: &s.config.FetchSize, Timeout: timeoutMs}
Expand Down
7 changes: 7 additions & 0 deletions example/session_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func main() {
createTimeseries("root.sg1.dev1.status")
deleteTimeseries("root.sg1.dev1.status")

createTimeseriesByNonQueryStatement("create timeseries root.sg1.dev1.status with datatype = int32")
deleteTimeseries("root.sg1.dev1.status")

createMultiTimeseries()
deleteTimeseries("root.sg1.dev1.temperature")

Expand Down Expand Up @@ -295,6 +298,10 @@ func createTimeseries(path string) {
checkError(session.CreateTimeseries(path, dataType, encoding, compressor, nil, nil))
}

func createTimeseriesByNonQueryStatement(sql string) {
checkError(session.ExecuteNonQueryStatement(sql))
}

func createAlignedTimeseries(prefixPath string, measurements, measurementAlias []string) {
var (
dataTypes = []client.TSDataType{
Expand Down

0 comments on commit e7dcc09

Please sign in to comment.