Skip to content

Commit 7375ede

Browse files
author
wb-zj263647
committed
add failed situation
1 parent ab32c33 commit 7375ede

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

lib/parser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ class Parser {
99
}
1010

1111
parse(sql) {
12-
return parseFn(sql)
12+
try {
13+
return parseFn(sql)
14+
} catch(errors) {
15+
throw new Error(`Error occurred while converting ‘${sql}’ into ast, cannot convert it!`)
16+
}
1317
}
1418

1519
whiteListCheck(sql, whiteList) {

test/ast.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -835,15 +835,15 @@ describe('AST', () => {
835835
})
836836

837837

838-
// describe('unsupported statements', () => {
839-
// const unsupportedStatements = {
840-
// drop: 'DROP table t'
841-
// };
842-
843-
// Object.keys(unsupportedStatements).forEach((stmtType) => {
844-
// it(`should throw exception for ${stmtType} statements`, () => {
845-
// expect(getParsedSql.bind(null, unsupportedStatements[stmtType])).to.throw(Error, `${stmtType} statements not supported at the moment`);
846-
// });
847-
// });
848-
// });
838+
describe('unsupported situation', () => {
839+
840+
it(`should throw exception for INSERT SELECT INFO`, () => {
841+
const sql = 'INSERT INTO t1 select * from t'
842+
expect(getParsedSql.bind(null, sql)).to.throw(Error, `Error occurred while converting ‘${sql}’ into ast, cannot convert it!`);
843+
});
844+
845+
it(`should throw exception for drop statements`, () => {
846+
expect(util.astToSQL.bind(null, {type: 'Drop'})).to.throw(Error, `Drop statements not supported at the moment`);
847+
});
848+
});
849849
});

test/delete.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,11 @@ describe('delete', () => {
8989
}
9090
});
9191
});
92+
93+
it('Drop statement not surported!', () => {
94+
const sql = 'DROP table t'
95+
const fun = parser.parse.bind(parser, sql)
96+
expect(fun).to.throw(`Error occurred while converting ‘${sql}’ into ast, cannot convert it!`)
97+
})
98+
9299
});

test/insert.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ describe('insert', () => {
2626
}]
2727
}]);
2828
});
29+
30+
it('failed with INSERT SELECT INFO', () => {
31+
const sql = 'INSERT INTO t1 SELECT * FROM t'
32+
const fun = parser.parse.bind(parser, sql)
33+
expect(fun).to.throw(`Error occurred while converting ‘${sql}’ into ast, cannot convert it!`)
34+
})
2935
});

0 commit comments

Comments
 (0)