File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import fs from 'fs' ;
22import path from 'path' ;
33
4- export const readSQL = ( dirname : string , fileName : string , isSegment = true ) => {
5- const sqlFiles = fs . readFileSync ( path . join ( dirname , 'fixtures' , fileName ) , 'utf-8' )
6- if ( ! isSegment ) return [ sqlFiles ] ;
7- return sqlFiles . split ( ';' )
8- . filter ( Boolean )
9- . map ( ( i ) => i . trim ( ) ) ;
10- }
4+ export const readSQL = ( dirname : string , fileName : string ) => {
5+ const content = fs . readFileSync ( path . join ( dirname , 'fixtures' , fileName ) , 'utf-8' ) ;
6+ const result : string [ ] = [ ] ;
7+ let tmp = '' ;
8+
9+ for ( let index = 0 ; index < content . length ; index ++ ) {
10+ const char = content [ index ] ;
11+ tmp += char ;
12+
13+ const isMulti = tmp . includes ( 'EXECUTE STATEMENT SET' ) ;
14+
15+ if ( ! isMulti ) {
16+ // 非批量的先简单按照分号切割
17+ if ( tmp . endsWith ( ';' ) ) {
18+ result . push ( tmp . trim ( ) ) ;
19+ tmp = '' ;
20+ }
21+ } else {
22+ if ( tmp . endsWith ( 'END;' ) ) {
23+ result . push ( tmp . trim ( ) ) ;
24+ tmp = '' ;
25+ }
26+ }
27+ }
28+
29+ return result ;
30+ } ;
You can’t perform that action at this time.
0 commit comments