mirror of https://github.com/AMT-Cheif/drift.git
Support sqlite_master, sqlite_sequence tables (#197)
This commit is contained in:
parent
fd27c878d4
commit
a69f469444
|
@ -67,7 +67,8 @@ class QueryHandler {
|
|||
final tableFinder = ReferencedTablesVisitor();
|
||||
_select.accept(tableFinder);
|
||||
_foundTables = tableFinder.foundTables;
|
||||
final moorTables = _foundTables.map(mapper.tableToMoor).toList();
|
||||
final moorTables =
|
||||
_foundTables.map(mapper.tableToMoor).where((s) => s != null).toList();
|
||||
|
||||
return SqlSelectQuery(
|
||||
name, context, _foundElements, moorTables, _inferResultSet());
|
||||
|
@ -100,6 +101,12 @@ class QueryHandler {
|
|||
final table = candidatesForSingleTable.single;
|
||||
final moorTable = mapper.tableToMoor(table);
|
||||
|
||||
if (moorTable == null) {
|
||||
// References a table not declared in any moor api (dart or moor file).
|
||||
// This can happen for internal sqlite tables
|
||||
return InferredResultSet(null, columns);
|
||||
}
|
||||
|
||||
final resultEntryToColumn = <ResultColumn, String>{};
|
||||
var matches = true;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
## unreleased
|
||||
- Handle special `rowid`, `oid`, `__rowid__` references
|
||||
- Support references to `sqlite_master` and `sqlite_sequence` tables
|
||||
|
||||
## 0.3.0
|
||||
- parse compound select statements
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import 'package:sqlparser/sqlparser.dart';
|
||||
|
||||
/// Constructs the "sqlite_sequence" table.
|
||||
Table get sqliteSequence {
|
||||
final name = TableColumn('name', const ResolvedType(type: BasicType.text));
|
||||
final seq = TableColumn('seq', const ResolvedType(type: BasicType.int));
|
||||
|
||||
return Table(name: 'sqlite_sequence', resolvedColumns: [name, seq]);
|
||||
}
|
||||
|
||||
/// Constructs the "sqlite_master" table
|
||||
Table get sqliteMaster {
|
||||
final type = TableColumn('type', const ResolvedType(type: BasicType.text));
|
||||
final name = TableColumn('name', const ResolvedType(type: BasicType.text));
|
||||
final tblName =
|
||||
TableColumn('tbl_name', const ResolvedType(type: BasicType.text));
|
||||
final rootPage =
|
||||
TableColumn('rootpage', const ResolvedType(type: BasicType.int));
|
||||
final sql = TableColumn('sql', const ResolvedType(type: BasicType.text));
|
||||
|
||||
return Table(
|
||||
name: 'sqlite_master',
|
||||
resolvedColumns: [type, name, tblName, rootPage, sql],
|
||||
);
|
||||
}
|
|
@ -7,6 +7,8 @@ import 'package:sqlparser/src/reader/parser/parser.dart';
|
|||
import 'package:sqlparser/src/reader/tokenizer/scanner.dart';
|
||||
import 'package:sqlparser/src/reader/tokenizer/token.dart';
|
||||
|
||||
import 'builtin_tables.dart';
|
||||
|
||||
class SqlEngine {
|
||||
/// All tables registered with [registerTable].
|
||||
final List<Table> knownTables = [];
|
||||
|
@ -16,7 +18,10 @@ class SqlEngine {
|
|||
/// extensions enabled.
|
||||
final bool useMoorExtensions;
|
||||
|
||||
SqlEngine({this.useMoorExtensions = false});
|
||||
SqlEngine({this.useMoorExtensions = false}) {
|
||||
registerTable(sqliteMaster);
|
||||
registerTable(sqliteSequence);
|
||||
}
|
||||
|
||||
/// Registers the [table], which means that it can later be used in sql
|
||||
/// statements.
|
||||
|
|
Loading…
Reference in New Issue