(sql string)
| 761 | } |
| 762 | |
| 763 | func splitSQLStatements(sql string) []string { |
| 764 | var statements []string |
| 765 | var current strings.Builder |
| 766 | inString := false |
| 767 | stringChar := byte(0) |
| 768 | inLineComment := false |
| 769 | |
| 770 | for i := 0; i < len(sql); i++ { |
| 771 | c := sql[i] |
| 772 | |
| 773 | // Handle line comments (--) when not in a string |
| 774 | if !inString && !inLineComment && c == '-' && i+1 < len(sql) && sql[i+1] == '-' { |
| 775 | inLineComment = true |
| 776 | i++ // skip second dash |
| 777 | continue |
| 778 | } |
| 779 | |
| 780 | // End line comment on newline |
| 781 | if inLineComment { |
| 782 | if c == '\n' { |
| 783 | inLineComment = false |
| 784 | current.WriteByte(' ') // replace comment with space |
| 785 | } |
| 786 | continue |
| 787 | } |
| 788 | |
| 789 | // Handle string literals |
| 790 | if (c == '\'' || c == '"') && (i == 0 || sql[i-1] != '\\') { |
| 791 | if !inString { |
| 792 | inString = true |
| 793 | stringChar = c |
| 794 | } else if c == stringChar { |
| 795 | inString = false |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | // Handle statement terminator |
| 800 | if c == ';' && !inString { |
| 801 | stmt := strings.TrimSpace(current.String()) |
| 802 | if stmt != "" { |
| 803 | statements = append(statements, stmt) |
| 804 | } |
| 805 | current.Reset() |
| 806 | continue |
| 807 | } |
| 808 | |
| 809 | current.WriteByte(c) |
| 810 | } |
| 811 | |
| 812 | // Add any remaining statement |
| 813 | if stmt := strings.TrimSpace(current.String()); stmt != "" { |
| 814 | statements = append(statements, stmt) |
| 815 | } |
| 816 | |
| 817 | return statements |
| 818 | } |
| 819 | |
| 820 | func truncate(s string, maxLen int) string { |
no test coverage detected