From 19ce0b7cad1382c880adaae75734fd7424a341d1 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 5 Dec 2017 11:07:48 +0000 Subject: [PATCH] Improve IF / ELSE statement formatting --- sql/string.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sql/string.go b/sql/string.go index 15d7254a..2ca7c8ef 100644 --- a/sql/string.go +++ b/sql/string.go @@ -168,6 +168,17 @@ func (this InfoStatement) String() string { } } +func (this IfStatement) String() string { + m := make([]string, len(this.Cond)) + for k := range this.Cond { + m[k] = print("%v THEN %v", this.Cond[k], this.Then[k]) + } + return print("IF %v%v END", + strings.Join(m, " ELSE IF "), + maybe(this.Else != nil, print(" ELSE %v", this.Else)), + ) +} + func (this LetStatement) String() string { return print("LET %v = %v", this.Name, @@ -722,10 +733,13 @@ func (this SubExpression) String() string { } func (this IfelExpression) String() string { - return print("IF %v THEN %v%v", - this.Cond, - this.Then, - maybe(this.Else != nil, print("ELSE %v END", this.Else)), + m := make([]string, len(this.Cond)) + for k := range this.Cond { + m[k] = print("%v THEN %v", this.Cond[k], this.Then[k]) + } + return print("IF %v%v END", + strings.Join(m, " ELSE IF "), + maybe(this.Else != nil, print(" ELSE %v", this.Else)), ) }