diff --git a/lib/gat/gatling/client/client.go b/lib/gat/gatling/client/client.go index 88763f866cc37a722a8f0f652aed10291d4f49ff..b6a888697da1a19880dc5417e817129502c54e18 100644 --- a/lib/gat/gatling/client/client.go +++ b/lib/gat/gatling/client/client.go @@ -537,14 +537,7 @@ func (c *Client) handle_query(ctx context.Context, q *protocol.Query) error { } transaction := -1 - for idx, cmd := range parsed { - var next int - if idx+1 >= len(parsed) { - next = len(q.Fields.Query) - } else { - next = parsed[idx+1].Index - } - + for _, cmd := range parsed { cmdUpper := strings.ToUpper(cmd.Command) // not in transaction @@ -556,14 +549,14 @@ func (c *Client) handle_query(ctx context.Context, q *protocol.Query) error { } fallthrough case "BEGIN": - transaction = cmd.Index + transaction = cmd.Begin } } if transaction == -1 { // this is a simple query c.startRequest() - err = c.handle_simple_query(ctx, q.Fields.Query[cmd.Index:next]) + err = c.handle_simple_query(ctx, cmd.SQL) if err != nil { return err } @@ -572,7 +565,7 @@ func (c *Client) handle_query(ctx context.Context, q *protocol.Query) error { switch cmdUpper { case "END": c.startRequest() - err = c.handle_transaction(ctx, q.Fields.Query[transaction:next]) + err = c.handle_transaction(ctx, q.Fields.Query[transaction:cmd.End]) if err != nil { return err } diff --git a/lib/parse/parse.go b/lib/parse/parse.go index ab76676304bb08a8914a4b2d70b958a96249df51..22dad031ebdb233186c7b0ea792c2bef771a11e4 100644 --- a/lib/parse/parse.go +++ b/lib/parse/parse.go @@ -8,7 +8,12 @@ import ( ) type Command struct { - Index int + // start index in parsed SQL string + Begin int + // end index in parsed SQL string + End int + // the subtext SQL. Same as src[Begin:End] + SQL string Command string Arguments []string } @@ -242,7 +247,11 @@ func (r *reader) nextArgument() (string, error) { } func (r *reader) nextCommand() (cmd Command, err error) { - cmd.Index = r.p + start := r.p + defer func() { + cmd.SQL = r.v[start:r.p] + }() + cmd.Command, err = r.nextIdentifier() if err != nil { if err == EndOfStatement { diff --git a/test/docker-compose.yml b/test/docker-compose.yml index d10f7f8e9f2a12a25ef627163635a23b12b31bd8..d360903f567c79a0f654f3910ca68a6cbaa6cbb8 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -16,5 +16,7 @@ services: pggat: build: ../ restart: always + environment: + PGGAT_DB_PASS: example ports: - 6432:6432