mirror of https://github.com/AMT-Cheif/drift.git
sqlparser: Fix parsing binary literals
This commit is contained in:
parent
039838b2ba
commit
43b7f72bad
|
@ -4,6 +4,7 @@
|
||||||
generated companion class.
|
generated companion class.
|
||||||
- Add the `TypeConverter.extensionType` factory to create type converters for
|
- Add the `TypeConverter.extensionType` factory to create type converters for
|
||||||
extension types.
|
extension types.
|
||||||
|
- Fix invalid SQL syntax being generated for `BLOB` literals on postgres.
|
||||||
|
|
||||||
## 2.16.0
|
## 2.16.0
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
## 3.35.0-dev
|
## 3.35.0-dev
|
||||||
|
|
||||||
|
- Fix parsing binary literals.
|
||||||
- Drift extensions: Allow custom class names for `CREATE VIEW` statements.
|
- Drift extensions: Allow custom class names for `CREATE VIEW` statements.
|
||||||
|
|
||||||
## 0.34.1
|
## 0.34.1
|
||||||
|
|
|
@ -290,7 +290,7 @@ class Scanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
final value = source
|
final value = source
|
||||||
.substring(_startOffset + 1, _currentOffset - 1)
|
.substring(_startOffset + (binary ? 2 : 1), _currentOffset - 1)
|
||||||
.replaceAll("''", "'");
|
.replaceAll("''", "'");
|
||||||
tokens.add(StringLiteralToken(value, _currentSpan, binary: binary));
|
tokens.add(StringLiteralToken(value, _currentSpan, binary: binary));
|
||||||
}
|
}
|
||||||
|
|
|
@ -642,7 +642,7 @@ class EqualityEnforcingVisitor implements AstVisitor<void, void> {
|
||||||
@override
|
@override
|
||||||
void visitStringLiteral(StringLiteral e, void arg) {
|
void visitStringLiteral(StringLiteral e, void arg) {
|
||||||
final current = _currentAs<StringLiteral>(e);
|
final current = _currentAs<StringLiteral>(e);
|
||||||
_assert(current.value == e.value, e);
|
_assert(current.value == e.value && current.isBinary == e.isBinary, e);
|
||||||
_checkChildren(e);
|
_checkChildren(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1114,6 +1114,9 @@ class NodeSqlBuilder extends AstVisitor<void, void> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void visitStringLiteral(StringLiteral e, void arg) {
|
void visitStringLiteral(StringLiteral e, void arg) {
|
||||||
|
if (e.isBinary) {
|
||||||
|
symbol('X', spaceBefore: true);
|
||||||
|
}
|
||||||
_stringLiteral(e.value);
|
_stringLiteral(e.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,26 @@ void main() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('binary string literal', () {
|
||||||
|
final scanner = Scanner("X'1234' x'5678'");
|
||||||
|
scanner.scanTokens();
|
||||||
|
|
||||||
|
expect(scanner.tokens, hasLength(3));
|
||||||
|
expect(
|
||||||
|
scanner.tokens[0],
|
||||||
|
const TypeMatcher<StringLiteralToken>()
|
||||||
|
.having((token) => token.binary, 'binary', isTrue)
|
||||||
|
.having((token) => token.value, 'value', '1234'),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
scanner.tokens[1],
|
||||||
|
const TypeMatcher<StringLiteralToken>()
|
||||||
|
.having((token) => token.binary, 'binary', isTrue)
|
||||||
|
.having((token) => token.value, 'value', '5678'),
|
||||||
|
);
|
||||||
|
expect(scanner.tokens[2].type, TokenType.eof);
|
||||||
|
});
|
||||||
|
|
||||||
group('parses numeric literals', () {
|
group('parses numeric literals', () {
|
||||||
void checkLiteral(String lexeme, NumericToken other, num value) {
|
void checkLiteral(String lexeme, NumericToken other, num value) {
|
||||||
final scanner = Scanner(lexeme)..scanTokens();
|
final scanner = Scanner(lexeme)..scanTokens();
|
|
@ -568,6 +568,11 @@ CREATE UNIQUE INDEX my_idx ON t1 (c1, c2, c3) WHERE c1 < c3;
|
||||||
testFormat('SELECT a -> b');
|
testFormat('SELECT a -> b');
|
||||||
testFormat('SELECT a ->> b');
|
testFormat('SELECT a ->> b');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('blob literal', () {
|
||||||
|
testFormat(
|
||||||
|
"select typeof(X'0100000300000000000000000000803F000000000000003F0000803F');");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('identifiers', () {
|
test('identifiers', () {
|
||||||
|
|
Loading…
Reference in New Issue