@@ -146,7 +146,7 @@ func (p *shell) AddMiddleware(m middleware) {
146
146
//
147
147
// If a middleware returns false, the pipeline stops.
148
148
// The pipeline will always run the middlewares in the order they were added
149
- func (p * shell ) Run (rawQuery string ) bool {
149
+ func (p * shell ) Run (rawQuery string , args ... interface {} ) bool {
150
150
queries := splitMultipleQuery (rawQuery )
151
151
152
152
if len (queries ) == 0 {
@@ -163,6 +163,7 @@ func (p *shell) Run(rawQuery string) bool {
163
163
SQLQuery : query ,
164
164
Config : p .Config ,
165
165
DB : p .DB ,
166
+ Args : args ,
166
167
}
167
168
168
169
// If the query is .read, we read the file
@@ -407,7 +408,7 @@ func splitMultipleQuery(sqlQuery string) []string {
407
408
// isDotCommand => true if the query is a dot command or a slash command
408
409
// isEscaped => true if the character is escaped (in a string '' or "")
409
410
// mustResetWord => true if we find a query that can be appened to queries
410
- var isDotCommand , isEscapedSimpleQuote , isEscapedDoubleQuote , mustResetWord bool
411
+ var isDotCommand , isEscapedSimpleQuote , isEscapedDoubleQuote , isMultiLineComment , isSingleLineComment , mustResetWord bool
411
412
412
413
queries := make ([]string , 0 )
413
414
// The index character of the current query
@@ -431,6 +432,25 @@ func splitMultipleQuery(sqlQuery string) []string {
431
432
isDotCommand = true
432
433
}
433
434
435
+ case '/' :
436
+ if len (sqlQuery ) > i + 1 && sqlQuery [i + 1 ] == '*' {
437
+ isMultiLineComment = true
438
+ }
439
+
440
+ case '*' :
441
+ // If we find a star and we are in a slash command
442
+ // we can assume that it is the end of the slash command
443
+ if isMultiLineComment && len (sqlQuery ) > i + 1 &&
444
+ sqlQuery [i + 1 ] == '/' {
445
+ isMultiLineComment = false
446
+ }
447
+ case '-' :
448
+ // If we find a dash and we are at the beginning of the query
449
+ // we can assume that it is a single line comment
450
+ if i == 0 && len (sqlQuery ) > i + 1 && sqlQuery [i + 1 ] == '-' {
451
+ isSingleLineComment = true
452
+ }
453
+
434
454
case '.' :
435
455
// If we find a dot and we are at the beginning of the query
436
456
// we can assume that it is a dot command
@@ -454,7 +474,7 @@ func splitMultipleQuery(sqlQuery string) []string {
454
474
//
455
475
// It could be simplified as mustResetWord = condition
456
476
// but I prefer to keep it like this for readability
457
- if ! isEscapedSimpleQuote && ! isEscapedDoubleQuote {
477
+ if ! isEscapedSimpleQuote && ! isEscapedDoubleQuote && ! isMultiLineComment && ! isSingleLineComment {
458
478
mustResetWord = true
459
479
}
460
480
@@ -467,17 +487,21 @@ func splitMultipleQuery(sqlQuery string) []string {
467
487
468
488
// If we find a newline, we're not in a string
469
489
// and it's a dot command, it means that the query is finished
470
- if ! isEscapedSimpleQuote && ! isEscapedDoubleQuote && isDotCommand {
490
+ if ! isEscapedSimpleQuote && ! isEscapedDoubleQuote && ! isMultiLineComment && ! isSingleLineComment && isDotCommand {
471
491
mustResetWord = true
472
492
}
473
493
494
+ if isSingleLineComment {
495
+ isSingleLineComment = false
496
+ }
497
+
474
498
}
475
499
476
500
// We append the character to the query
477
501
// unless it is a newline and it is a dot command
478
502
//
479
503
// Or it's a ; and we are not in a string
480
- if ! ((c == '\n' && isDotCommand ) || (c == ';' && ! isEscapedSimpleQuote && ! isEscapedDoubleQuote )) {
504
+ if ! ((c == '\n' && isDotCommand ) || (c == ';' && ! isEscapedSimpleQuote && ! isEscapedDoubleQuote && ! isMultiLineComment && ! isSingleLineComment )) {
481
505
tempQuery .WriteRune (c )
482
506
}
483
507
currentPosition ++
@@ -495,6 +519,8 @@ func splitMultipleQuery(sqlQuery string) []string {
495
519
mustResetWord = false
496
520
isEscapedSimpleQuote = false
497
521
isEscapedDoubleQuote = false
522
+ isMultiLineComment = false
523
+ isSingleLineComment = false
498
524
}
499
525
500
526
}
0 commit comments