2023-05-11 18:11:12 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
|
2023-05-11 19:31:03 +08:00
|
|
|
export const readSQL = (dirname: string, fileName: string) => {
|
|
|
|
const content = fs.readFileSync(path.join(dirname, 'fixtures', fileName), 'utf-8');
|
|
|
|
const result: string[] = [];
|
|
|
|
let tmp = '';
|
|
|
|
|
|
|
|
for (let index = 0; index < content.length; index++) {
|
|
|
|
const char = content[index];
|
|
|
|
tmp += char;
|
|
|
|
|
2023-05-23 14:40:52 +08:00
|
|
|
const isMulti = tmp.includes('EXECUTE STATEMENT SET') || tmp.includes('BEGIN STATEMENT SET;');
|
2023-05-11 19:31:03 +08:00
|
|
|
|
|
|
|
if (!isMulti) {
|
|
|
|
// 非批量的先简单按照分号切割
|
|
|
|
if (tmp.endsWith(';')) {
|
|
|
|
result.push(tmp.trim());
|
|
|
|
tmp = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tmp.endsWith('END;')) {
|
|
|
|
result.push(tmp.trim());
|
|
|
|
tmp = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|