【发布时间】:2021-09-29 21:20:44
【问题描述】:
我正在尝试在我的 Flutter 应用中打开现有的 SQLite 数据库,但在启动应用时我总是在控制台中收到该错误消息:
I/OpenGLRenderer(16880): Davey! duration=949ms; Flags=1, IntendedVsync=32058088200606, Vsync=32058088200606, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=32058101631102, AnimationStart=32058101709175, PerformTraversalsStart=32058101714227, DrawStart=32059029835685, SyncQueued=32059030411883, SyncStart=32059030862195, IssueDrawCommandsStart=32059030915893, SwapBuffers=32059035930789, FrameCompleted=32059037678966, DequeueBufferDuration=3920000, QueueBufferDuration=1405000,
E/SQLiteLog(16880): (1) no such table: Links
E/SQLiteLog(16880): (1) no such table: Links
I/flutter (17672): sdlu conver_refactor MemberProfileDealer 17 1 1
I/flutter (17672): sdlu conver_refactor MessageDealer 45 0 1
I/flutter (17672): sdlu conver_refactor LiveInfoDealer 497 1 0
I/flutter (17672): sdlu conver_refactor ProductInfoDealer 810 0 0
I/flutter (17672): sdlu conver_refactor MarkInfoDealer 1511 0 3
I/flutter (17672): sdlu conver_refactor MemberProfileDealer 4 0 1
I/flutter (17672): sdlu conver_refactor MessageDealer 41 0 0
I/flutter (17672): sdlu conver_refactor ProductInfoDealer 823 0 0
I/flutter (17672): sdlu conver_refactor LiveInfoDealer 1095 0 2
I/flutter (17672): sdlu conver_refactor MarkInfoDealer 1404 0 5
I/flutter (17672): sdlu conver_refactor MemberProfileDealer 19 0 0
I/flutter (17672): sdlu conver_refactor MessageDealer 46 0 0
I/flutter (17672): sdlu conver_refactor LiveInfoDealer 491 0 1
I/flutter (17672): sdlu conver_refactor ProductInfoDealer 805 0 0
I/flutter (17672): sdlu conver_refactor MarkInfoDealer 1410 0 2
这是我的 Database_Helper 类:
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'model.dart';
class DatabaseHelper {
DatabaseHelper._privateConstructor();
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();
static Database? _database;
Future<Database> get database async => _database ??= await _initDatabase();
Future<Database> _initDatabase() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, 'DSA_Database.db');
return await openDatabase(
path,
version: 1,
onCreate: _onCreate,
);
}
Future _onCreate(Database db, int version) async {
await rootBundle.load(join('assets', 'DSA_Database.db'));
}
Future<List<Titles>> getTitles() async {
Database db = await instance.database;
var titles = await db.query('Links');
List<Titles> titlesList =
titles.isNotEmpty
? titles.map((e) => Titles.fromMap(e)).toList()
: [];
return titlesList;
}
}
数据库已添加到 pubspec.yaml 文件中
assets:
- assets/DSA_Database.db
我对 SQLite 很陌生,所以我不能 100% 知道我是否做得对。
是的,我仔细检查了表格的命名。
提前致谢!
【问题讨论】: