From c4f321748a4c7ab6ff7ea3e3cce3da9aadebb98b Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 25 Sep 2019 20:19:39 +0200 Subject: [PATCH] Prepare release for sqlparser 0.3.0 --- sqlparser/CHANGELOG.md | 6 ++++++ sqlparser/README.md | 17 ++++++++++------- sqlparser/lib/src/engine/sql_engine.dart | 2 ++ sqlparser/pubspec.yaml | 2 +- .../errors/compound_column_mismatch.dart | 16 ++++++++++++++++ 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 sqlparser/test/analysis/errors/compound_column_mismatch.dart diff --git a/sqlparser/CHANGELOG.md b/sqlparser/CHANGELOG.md index 961eb570..42adbc3a 100644 --- a/sqlparser/CHANGELOG.md +++ b/sqlparser/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.3.0 +- parse compound select statements +- scan comment tokens +- experimental auto-complete engine (only supports a tiny subset based on the grammar only) +- some features that are specific to moor + ## 0.2.0 - Parse `CREATE TABLE` statements - Extract schema information from parsed create table statements with `SchemaFromCreateTable`. diff --git a/sqlparser/README.md b/sqlparser/README.md index 728977b3..77cce681 100644 --- a/sqlparser/README.md +++ b/sqlparser/README.md @@ -1,12 +1,16 @@ # sqlparser -An sql parser and static analyzer, written in pure Dart. At the moment, this library only targets -the sqlite dialect and some advanced features aren't supported yet. +Sql parser and static analyzer written in Dart. At the moment, this library targets the +sqlite dialect only. ## Features -This library can parse most statements and perform type analysis for parameters and returned -columns. It supports joins, `group by`, nested sql statements, updates and deletes, and more. -### Just parsing +This library can parse most sql statements and perform static analysis. We can resolve +what type a column in a `SELECT` statement has, infer types for variables, find +semantic errors and more. + +This library supports most features, including joins, `group by`, nested and compound sql +statements, window functions and foreign keys. +### Using the parser You can parse the abstract syntax tree of sqlite statements with `SqlEngine.parse`. ```dart import 'package:sqlparser/sqlparser.dart'; @@ -34,7 +38,7 @@ Given information about all tables and a sql statement, this library can: tables / columns, uses undefined functions, etc.) To use the analyzer, first register all known tables via `SqlEngine.registerTable`. Then, -`SqlEngine.analyze(sql)` gives you an `AnalysisContext` which contains an annotated ast and information +`SqlEngine.analyze(sql)` gives you an `AnalysisContext` which contains an annotated AST and information about errors. The type of result columns and expressions can be inferred by using `AnalysisContext.typeOf()`. Here's an example: @@ -65,7 +69,6 @@ package to generate type-safe methods from sql. Most on this list is just not supported yet because I didn't found a use case for them yet. If you need them, just leave an issue and I'll try to implement them soon. -- Compound select statements (`UNION` / `INTERSECT`) are not supported yet - Common table expressions are not supported - Some advanced expressions, like `CAST`s aren't supported yet. - An `UPSERT` clause is not yet supported on insert statements diff --git a/sqlparser/lib/src/engine/sql_engine.dart b/sqlparser/lib/src/engine/sql_engine.dart index f5372f1b..56aca60c 100644 --- a/sqlparser/lib/src/engine/sql_engine.dart +++ b/sqlparser/lib/src/engine/sql_engine.dart @@ -107,6 +107,8 @@ class SqlEngine { /// Analyzes the given [node], which should be a [CrudStatement]. /// The [AnalysisContext] enhances the AST by reporting type hints and errors. + /// The [file] should contain the full SQL source code that was used to parse + /// the [node]. /// /// The analyzer needs to know all the available tables to resolve references /// and result columns, so all known tables should be registered using diff --git a/sqlparser/pubspec.yaml b/sqlparser/pubspec.yaml index 9ff135fe..7d397bcc 100644 --- a/sqlparser/pubspec.yaml +++ b/sqlparser/pubspec.yaml @@ -1,6 +1,6 @@ name: sqlparser description: Parses sqlite statements and performs static analysis on them -version: 0.2.0 +version: 0.3.0 homepage: https://github.com/simolus3/moor/tree/develop/sqlparser #homepage: https://moor.simonbinder.eu/ issue_tracker: https://github.com/simolus3/moor/issues diff --git a/sqlparser/test/analysis/errors/compound_column_mismatch.dart b/sqlparser/test/analysis/errors/compound_column_mismatch.dart new file mode 100644 index 00000000..70448102 --- /dev/null +++ b/sqlparser/test/analysis/errors/compound_column_mismatch.dart @@ -0,0 +1,16 @@ +import 'package:sqlparser/sqlparser.dart'; +import 'package:test/test.dart'; + +import '../data.dart'; + +void main() { + test('reports column count mismatch in compound select query', () { + final engine = SqlEngine()..registerTable(demoTable); + final result = engine.analyze('SELECT * FROM demo UNION SELECT 1'); + + expect(result.errors, hasLength(1)); + final error = result.errors.single; + + expect(error.type, AnalysisErrorType.compoundColumnCountMismatch); + }); +}