Skip to content

Commit

Permalink
Add enable_source/disable_source
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Jul 30, 2024
1 parent 3c938b5 commit 41d573d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
2 changes: 0 additions & 2 deletions include/hello.inc

This file was deleted.

8 changes: 6 additions & 2 deletions r/source.result
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
first line
before source
Hello from the included file
SELECT 1
1
1
last line
after source
Goodbye from the included file
SELECT 3
3
3
9 changes: 9 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
retryConnCount int
collationDisable bool
checkErr bool
disableSource bool
)

func init() {
Expand Down Expand Up @@ -516,7 +517,15 @@ func (t *tester) runQueries(queries []query) (int, error) {
q.location(), q.Query))
}
t.replaceRegex = regex
case Q_ENABLE_SOURCE:
disableSource = false
case Q_DISABLE_SOURCE:
disableSource = true
case Q_SOURCE:
if disableSource {
log.WithFields(log.Fields{"line": q.location()}).Warn("source command disabled")
break
}
fileName := strings.TrimSpace(q.Query)
cwd, err := os.Getwd()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions src/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ const (
Q_COMMENT /* Comments, ignored. */
Q_COMMENT_WITH_COMMAND
Q_EMPTY_LINE
Q_DISABLE_SOURCE
Q_ENABLE_SOURCE
)

// ParseQueries parses an array of string into an array of query object.
Expand Down
2 changes: 2 additions & 0 deletions src/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ var commandMap = map[string]int{
"single_query": Q_SINGLE_QUERY,
"begin_concurrent": Q_BEGIN_CONCURRENT,
"end_concurrent": Q_END_CONCURRENT,
"disable_source": Q_DISABLE_SOURCE,
"enable_source": Q_ENABLE_SOURCE,
}

func findType(cmdName string) int {
Expand Down
12 changes: 9 additions & 3 deletions t/source.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
--echo first line
--source include/hello.inc
--echo last line
--echo before source
--source include/hello1.inc
--echo after source

--disable_source
--source include/hello2.inc
--enable_source

--source include/hello3.inc

0 comments on commit 41d573d

Please sign in to comment.