Fix tests that used "table" as a table name

(we now recognize that as a keyword)
This commit is contained in:
Simon Binder 2019-07-26 13:49:25 +02:00
parent dee9993c83
commit 1766bb3f77
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
8 changed files with 26 additions and 21 deletions

View File

@ -23,7 +23,10 @@ class OrderingTerm extends AstNode {
final Expression expression;
final OrderingMode orderingMode;
OrderingTerm({this.expression, this.orderingMode = OrderingMode.ascending});
OrderingMode get resolvedOrderingMode =>
orderingMode ?? OrderingMode.ascending;
OrderingTerm({this.expression, this.orderingMode});
@override
T accept<T>(AstVisitor<T> visitor) => visitor.visitOrderingTerm(this);

View File

@ -14,6 +14,6 @@ final dateTime = TableColumn(
'date', const ResolvedType(type: BasicType.int, hint: IsDateTime()));
final anotherTable = Table(
name: 'table',
name: 'tbl',
resolvedColumns: [anotherId, dateTime],
);

View File

@ -24,7 +24,7 @@ Map<String, ResolveResult> _types = {
const ResolveResult(ResolvedType(type: BasicType.text, isArray: true)),
'SELECT * FROM demo WHERE content IN (?)':
const ResolveResult(ResolvedType(type: BasicType.text, isArray: false)),
'SELECT * FROM demo JOIN table ON demo.id = table.id WHERE date = ?':
'SELECT * FROM demo JOIN tbl ON demo.id = tbl.id WHERE date = ?':
const ResolveResult(
ResolvedType(type: BasicType.int, hint: IsDateTime())),
};

View File

@ -7,9 +7,9 @@ import 'utils.dart';
void main() {
test('parses delete statements', () {
testStatement(
'DELETE FROM table WHERE id = 5',
'DELETE FROM tbl WHERE id = 5',
DeleteStatement(
from: TableReference('table', null),
from: TableReference('tbl', null),
where: BinaryExpression(
Reference(columnName: 'id'),
token(TokenType.equal),

View File

@ -17,20 +17,20 @@ void main() {
group('from', () {
test('a simple table', () {
final stmt =
SqlEngine().parse('SELECT * FROM table').rootNode as SelectStatement;
SqlEngine().parse('SELECT * FROM tbl').rootNode as SelectStatement;
enforceEqual(stmt.from.single, TableReference('table', null));
enforceEqual(stmt.from.single, TableReference('tbl', null));
});
test('from more than one table', () {
final stmt = SqlEngine()
.parse('SELECT * FROM table AS test, table2')
.parse('SELECT * FROM tbl AS test, table2')
.rootNode as SelectStatement;
_enforceFrom(
stmt,
[
TableReference('table', 'test'),
TableReference('tbl', 'test'),
TableReference('table2', null),
],
);

View File

@ -2,10 +2,10 @@ import 'package:sqlparser/src/ast/ast.dart';
import '../utils.dart';
final Map<String, AstNode> testCases = {
'SELECT table.*, *, 1 as name WHERE 1 ORDER BY name LIMIT 3 OFFSET 5':
'SELECT tbl.*, *, 1 as name WHERE 1 ORDER BY name ASC LIMIT 3 OFFSET 5':
SelectStatement(
columns: [
StarResultColumn('table'),
StarResultColumn('tbl'),
StarResultColumn(null),
ExpressionResultColumn(
expression: NumericLiteral(1, token(TokenType.numberLiteral)),
@ -14,7 +14,10 @@ final Map<String, AstNode> testCases = {
],
where: NumericLiteral(1, token(TokenType.numberLiteral)),
orderBy: OrderBy(terms: [
OrderingTerm(expression: Reference(columnName: 'name')),
OrderingTerm(
expression: Reference(columnName: 'name'),
orderingMode: OrderingMode.ascending,
),
]),
limit: Limit(
count: NumericLiteral(3, token(TokenType.numberLiteral)),
@ -22,9 +25,9 @@ final Map<String, AstNode> testCases = {
offset: NumericLiteral(5, token(TokenType.numberLiteral)),
),
),
'SELECT table.*, (SELECT * FROM table2) FROM table': SelectStatement(
'SELECT tbl.*, (SELECT * FROM table2) FROM tbl': SelectStatement(
columns: [
StarResultColumn('table'),
StarResultColumn('tbl'),
ExpressionResultColumn(
expression: SubQuery(
select: SelectStatement(
@ -35,12 +38,12 @@ final Map<String, AstNode> testCases = {
),
],
from: [
TableReference('table', null),
TableReference('tbl', null),
],
),
'SELECT * FROM table WHERE id IN ()': SelectStatement(
'SELECT * FROM tbl WHERE id IN ()': SelectStatement(
columns: [StarResultColumn(null)],
from: [TableReference('table', null)],
from: [TableReference('tbl', null)],
where: InExpression(
left: Reference(columnName: 'id'),
inside: TupleExpression(expressions: []),

View File

@ -8,7 +8,7 @@ import '../utils.dart';
void main() {
test('parses order by clauses', () {
final parsed = SqlEngine()
.parse('SELECT * FROM table ORDER BY -a, b DESC')
.parse('SELECT * FROM tbl ORDER BY -a, b DESC')
.rootNode as SelectStatement;
enforceEqual(
@ -16,7 +16,6 @@ void main() {
OrderBy(
terms: [
OrderingTerm(
orderingMode: OrderingMode.ascending,
expression: UnaryExpression(
token(TokenType.minus),
Reference(columnName: 'a'),

View File

@ -3,9 +3,9 @@ import 'package:sqlparser/sqlparser.dart';
import 'utils.dart';
final testCases = {
'UPDATE OR ROLLBACK table SET a = NULL, b = c WHERE d': UpdateStatement(
'UPDATE OR ROLLBACK tbl SET a = NULL, b = c WHERE d': UpdateStatement(
or: FailureMode.rollback,
table: TableReference('table', null),
table: TableReference('tbl', null),
set: [
SetComponent(
column: Reference(columnName: 'a'),