From 27430cbb0758dd664d606f9a1f6b05c9388579fa Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 26 Jan 2020 15:37:46 +0100 Subject: [PATCH] Add table-valued query to test moor file --- moor/test/data/tables/custom_tables.g.dart | 30 +++++++++++++++++-- moor/test/data/tables/tables.moor | 6 +++- .../lib/src/reader/parser/expressions.dart | 7 ++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/moor/test/data/tables/custom_tables.g.dart b/moor/test/data/tables/custom_tables.g.dart index 50503040..78048d1f 100644 --- a/moor/test/data/tables/custom_tables.g.dart +++ b/moor/test/data/tables/custom_tables.g.dart @@ -1181,11 +1181,18 @@ abstract class _$CustomTablesDb extends GeneratedDatabase { readsFrom: {config}).map(_rowToConfig); } - Selectable findValidJsons() { + TableValuedResult _rowToTableValuedResult(QueryRow row) { + return TableValuedResult( + key: row.readString('key'), + value: row.readString('value'), + ); + } + + Selectable tableValued() { return customSelectQuery( - 'SELECT * FROM config WHERE json_valid(config_value)', + 'SELECT\n "key", "value"\n FROM config, json_each(config.config_value)\n WHERE json_valid(config_value)', variables: [], - readsFrom: {config}).map(_rowToConfig); + readsFrom: {config}).map(_rowToTableValuedResult); } MultipleResult _rowToMultipleResult(QueryRow row) { @@ -1270,6 +1277,23 @@ abstract class _$CustomTablesDb extends GeneratedDatabase { ]; } +class TableValuedResult { + final String key; + final String value; + TableValuedResult({ + this.key, + this.value, + }); + @override + int get hashCode => $mrjf($mrjc(key.hashCode, value.hashCode)); + @override + bool operator ==(dynamic other) => + identical(this, other) || + (other is TableValuedResult && + other.key == this.key && + other.value == this.value); +} + class MultipleResult { final String a; final int b; diff --git a/moor/test/data/tables/tables.moor b/moor/test/data/tables/tables.moor index 850d8407..fcdc351c 100644 --- a/moor/test/data/tables/tables.moor +++ b/moor/test/data/tables/tables.moor @@ -41,7 +41,11 @@ END; readConfig: SELECT * FROM config WHERE config_key = ?; readMultiple: SELECT * FROM config WHERE config_key IN ? ORDER BY $clause; readDynamic: SELECT * FROM config WHERE $predicate; -findValidJsons: SELECT * FROM config WHERE json_valid(config_value); + +tableValued: + SELECT "key", "value" + FROM config, json_each(config.config_value) + WHERE json_valid(config_value); @create: INSERT INTO config (config_key, config_value) VALUES ('key', 'values'); diff --git a/sqlparser/lib/src/reader/parser/expressions.dart b/sqlparser/lib/src/reader/parser/expressions.dart index 2043d1dc..92a26fd3 100644 --- a/sqlparser/lib/src/reader/parser/expressions.dart +++ b/sqlparser/lib/src/reader/parser/expressions.dart @@ -339,7 +339,12 @@ mixin ExpressionParser on ParserBase { } } - _error('Could not parse this expression'); + if (_peek is KeywordToken) { + _error('Could not parse this expressions. Note: This is a reserved ' + 'keyword, you can escape it in double ticks'); + } else { + _error('Could not parse this expression'); + } } @override