mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	
		
			
	
	
		
			29 lines
		
	
	
		
			511 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			29 lines
		
	
	
		
			511 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 
								 | 
							
								package base
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import (
							 | 
						||
| 
								 | 
							
									"fmt"
							 | 
						||
| 
								 | 
							
									"testing"
							 | 
						||
| 
								 | 
							
								)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func TestParserSql(t *testing.T) {
							 | 
						||
| 
								 | 
							
									sql := `-- selectByCond
							 | 
						||
| 
								 | 
							
									Select * from tdb where id > 10;
							 | 
						||
| 
								 | 
							
									-- another comment
							 | 
						||
| 
								 | 
							
									Select * from another_table where name = 'test'
							 | 
						||
| 
								 | 
							
									and age = ?;
							 | 
						||
| 
								 | 
							
									-- multi-line comment
							 | 
						||
| 
								 | 
							
									-- continues here
							 | 
						||
| 
								 | 
							
									Select * from yet_another_table
							 | 
						||
| 
								 | 
							
									Where id = ?;`
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									statements, err := parseSQL(sql)
							 | 
						||
| 
								 | 
							
									if err != nil {
							 | 
						||
| 
								 | 
							
										fmt.Println("Error:", err)
							 | 
						||
| 
								 | 
							
										return
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									for _, stmt := range statements {
							 | 
						||
| 
								 | 
							
										fmt.Printf("Comment: %s\nSQL: %s\n\n", stmt.Comment, stmt.SQL)
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 |