@@ -29,7 +29,6 @@ import (
2929 "fmt"
3030 "log"
3131 "reflect"
32- "regexp"
3332 "sort"
3433 "strconv"
3534 "strings"
@@ -72,10 +71,6 @@ type fieldValue struct {
7271 values []interface {}
7372}
7473
75- var (
76- reInvisibleChars = regexp .MustCompile (`[\s\r\n\t]+` )
77- )
78-
7974var (
8075 sqlPlaceholder = exql .RawValue (`?` )
8176)
@@ -347,11 +342,10 @@ func Map(item interface{}, options *MapOptions) ([]string, []interface{}, error)
347342}
348343
349344func columnFragments (columns []interface {}) ([]exql.Fragment , []interface {}, error ) {
350- l := len (columns )
351- f := make ([]exql.Fragment , l )
345+ f := make ([]exql.Fragment , len (columns ))
352346 args := []interface {}{}
353347
354- for i := 0 ; i < l ; i ++ {
348+ for i := range columns {
355349 switch v := columns [i ].(type ) {
356350 case compilable :
357351 c , err := v .Compile ()
@@ -393,19 +387,44 @@ func columnFragments(columns []interface{}) ([]exql.Fragment, []interface{}, err
393387 return f , args , nil
394388}
395389
396- func prepareQueryForDisplay (in string ) (out string ) {
397- j := 1
398- for i := range in {
390+ func prepareQueryForDisplay (in string ) string {
391+ out := make ([]byte , 0 , len (in ))
392+
393+ offset := 0
394+ whitespace := true
395+ placeholders := 1
396+
397+ for i := 0 ; i < len (in ); i ++ {
398+ if in [i ] == ' ' || in [i ] == '\r' || in [i ] == '\n' || in [i ] == '\t' {
399+ if whitespace {
400+ offset = i
401+ } else {
402+ whitespace = true
403+ out = append (out , in [offset :i ]... )
404+ offset = i
405+ }
406+ continue
407+ }
408+ if whitespace {
409+ whitespace = false
410+ if len (out ) > 0 {
411+ out = append (out , ' ' )
412+ }
413+ offset = i
414+ }
399415 if in [i ] == '?' {
400- out = out + "$" + strconv .Itoa (j )
401- j ++
402- } else {
403- out = out + string (in [i ])
416+ out = append (out , in [offset :i ]... )
417+ offset = i + 1
418+
419+ out = append (out , '$' )
420+ out = append (out , strconv .Itoa (placeholders )... )
421+ placeholders ++
404422 }
405423 }
406-
407- out = reInvisibleChars .ReplaceAllString (out , ` ` )
408- return strings .TrimSpace (out )
424+ if ! whitespace {
425+ out = append (out , in [offset :len (in )]... )
426+ }
427+ return string (out )
409428}
410429
411430func (iter * iterator ) NextScan (dst ... interface {}) error {
0 commit comments