@@ -86,22 +86,6 @@ public function parse_statements( $sql_file_path ) {
8686 $ line = mb_convert_encoding ( $ line , 'UTF-8 ' , $ detected_encoding );
8787 }
8888
89- // Skip empty lines and comments
90- if ( empty ( $ line ) || strpos ( $ line , '-- ' ) === 0 || strpos ( $ line , '# ' ) === 0 ) {
91- continue ;
92- }
93-
94- // Handle multi-line comments
95- if ( ! $ in_comment && strpos ( $ line , '/* ' ) === 0 ) {
96- $ in_comment = true ;
97- }
98- if ( $ in_comment ) {
99- if ( strpos ( $ line , '*/ ' ) !== false ) {
100- $ in_comment = false ;
101- }
102- continue ;
103- }
104-
10589 $ strlen = strlen ( $ line );
10690 for ( $ i = 0 ; $ i < $ strlen ; $ i ++ ) {
10791 $ ch = $ line [ $ i ];
@@ -120,6 +104,29 @@ public function parse_statements( $sql_file_path ) {
120104 continue ;
121105 }
122106
107+ // Handle comments.
108+ if ( 0 === $ single_quotes && 0 === $ double_quotes ) {
109+ $ prev_ch = isset ( $ line [ $ i - 1 ] ) ? $ line [ $ i - 1 ] : null ;
110+ $ next_ch = isset ( $ line [ $ i + 1 ] ) ? $ line [ $ i + 1 ] : null ;
111+
112+ // Skip inline comments.
113+ if ( ( '- ' === $ ch && '- ' === $ next_ch ) || '# ' === $ ch ) {
114+ break ; // Stop for the current line.
115+ }
116+
117+ // Skip multi-line comments.
118+ if ( ! $ in_comment && '/ ' === $ ch && '* ' === $ next_ch ) {
119+ $ in_comment = true ;
120+ continue ;
121+ }
122+ if ( $ in_comment ) {
123+ if ( '* ' === $ prev_ch && '/ ' === $ ch ) {
124+ $ in_comment = false ;
125+ }
126+ continue ;
127+ }
128+ }
129+
123130 // Handle quotes
124131 if ( "' " === $ ch && 0 === $ double_quotes ) {
125132 $ single_quotes = 1 - $ single_quotes ;
0 commit comments