Mike Schwörer
42424f4bc2
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m16s
33 lines
528 B
Go
33 lines
528 B
Go
package sq
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
var CommentTrimmer = NewPreListener(fnTrimComments)
|
|
|
|
func fnTrimComments(ctx context.Context, cmdtype string, id *uint16, sql *string, params *PP) error {
|
|
|
|
res := make([]string, 0)
|
|
|
|
for _, s := range strings.Split(*sql, "\n") {
|
|
if strings.HasPrefix(strings.TrimSpace(s), "--") {
|
|
continue
|
|
}
|
|
|
|
idx := strings.Index(s, "--")
|
|
if idx != -1 {
|
|
s = s[:idx]
|
|
}
|
|
|
|
s = strings.TrimRight(s, " \t\r\n")
|
|
|
|
res = append(res, s)
|
|
}
|
|
|
|
*sql = strings.Join(res, "\n")
|
|
|
|
return nil
|
|
}
|