0

我正在尝试将 SQFlite 添加到我的颤振项目中。但是在初始化数据库时,我收到以下错误。

E/SQLiteLog(26082): (1) near "references": syntax error
I/flutter (26082): error DatabaseException(near "references": syntax error (code 1): , while compiling: CREATE TABLE cv (
I/flutter (26082):             id INTEGER PRIMARY KEY,
I/flutter (26082):             name TEXT NOT NULL,
I/flutter (26082):             image TEXT NOT NULL,
I/flutter (26082):             signature TEXT NOT NULL,
I/flutter (26082):             skills TEXT NOT NULL,
I/flutter (26082):             address TEXT NOT NULL,
I/flutter (26082):             country TEXT NOT NULL,
I/flutter (26082):             education TEXT NOT NULL,
I/flutter (26082):             email TEXT NOT NULL,
I/flutter (26082):             phone TEXT NOT NULL,
I/flutter (26082):             objective TEXT NOT NULL,
I/flutter (26082):             references TEXT NOT NULL,
I/flutter (26082):             experience TEXT NOT NULL,
I/flutter (26082):           )) during open, closing...
E/flutter (26082): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DatabaseException(near "references": syntax error (code 1): , while compiling: CREATE TABLE cv (
E/flutter (26082):             id INTEGER PRIMARY KEY,
E/flutter (26082):             name TEXT NOT NULL,
E/flutter (26082):             image TEXT NOT NULL,
E/flutter (26082):             signature TEXT NOT NULL,
E/flutter (26082):             skills TEXT NOT NULL,
E/flutter (26082):             address TEXT NOT NULL,
E/flutter (26082):             country TEXT NOT NULL,
E/flutter (26082):             education TEXT NOT NULL,
E/flutter (26082):             email TEXT NOT NULL,
E/flutter (26082):             phone TEXT NOT NULL,
E/flutter (26082):             objective TEXT NOT NULL,
E/flutter (26082):             references TEXT NOT NULL,
E/flutter (26082):             experience TEXT NOT NULL,
E/flutter (26082):           ))
E/flutter (26082): #0      wrapDatabaseException (package:sqflite/src/exception_impl.dart:11:7)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #1      SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:29:7)
E/flutter (26082): #2      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.safeInvokeMethod (package:sqflite/src/database_mixin.dart:183:15)
E/flutter (26082): #3      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.invokeExecute (package:sqflite/src/database_mixin.dart:328:12)
E/flutter (26082): #4      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnExecute.<anonymous closure> (package:sqflite/src/database_mixin.dart:323:14)
E/flutter (26082): #5      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart:275:26)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #6      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnWriteSynchronized (package:sqflite/src/database_mixin.dart:307:7)
E/flutter (26082): #7      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnExecute (package:sqflite/src/database_mixin.dart:313:12)
E/flutter (26082): #8      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin&SqfliteDatabaseExecutorMixin.execute (package:sqflite/src/database_mixin.dart:35:15)
E/flutter (26082): #9      DatabaseHelper._onCreate (package:cv_builder/db_helper.dart:35:14)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #10     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.doOpen.<anonymous closure> (package:sqflite/src/database_mixin.dart:661:29)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #11     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin._runTransaction (package:sqflite/src/database_mixin.dart:433:28)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #12     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.transaction.<anonymous closure> (package:sqflite/src/database_mixin.dart:450:14)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #13     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart:275:26)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #14     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnWriteSynchronized (package:sqflite/src/database_mixin.dart:307:7)
E/flutter (26082): #15     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.transaction (package:sqflite/src/database_mixin.dart:449:12)
E/flutter (26082): #16     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.doOpen (package:sqflite/src/database_mixin.dart:651:15)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #17     SqfliteDatabaseOpenHelper.openDatabase (package:sqflite/src/database.dart:32:22)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #18     _SqfliteDatabaseFactoryImpl&Object&SqfliteDatabaseFactoryMixin.openDatabase.<anonymous closure> (package:sqflite/src/factory_mixin.dart:100:43)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #19     ReentrantLock.synchronized.<anonymous closure>.<anonymous closure> (package:synchronized/src/reentrant_lock.dart:33:24)
E/flutter (26082): #20     _rootRun (dart:async/zone.dart:1124:13)
E/flutter (26082): #21     _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (26082): #22     _runZoned (dart:async/zone.dart:1516:10)
E/flutter (26082): #23     runZoned (dart:async/zone.dart:1463:12)
E/flutter (26082): #24     ReentrantLock.synchronized.<anonymous closure> (package:synchronized/src/reentrant_lock.dart:32:24)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #25     BasicLock.synchronized (package:synchronized/src/basic_lock.dart:31:26)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #26     ReentrantLock.synchronized (package:synchronized/src/reentrant_lock.dart:28:17)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #27     _SqfliteDatabaseFactoryImpl&Object&SqfliteDatabaseFactoryMixin.openDatabase (package:sqflite/src/factory_mixin.dart:66:17)
E/flutter (26082): #28     openDatabase (package:sqflite/sqflite.dart:150:26)
E/flutter (26082): #29     DatabaseHelper._initDatabase (

可能是什么问题?

4

2 回答 2

2

在 sql 查询的最后一行experience TEXT NOT NULL, 更新它以experience TEXT NOT NULL 删除逗号,

于 2019-08-21T10:51:47.470 回答
0

当然,这个解决方案可以解决你的问题,但在我的情况下,情况并非如此。我的语法是正确的。我的查询很大,所以编译器导致错误。这只是解决了将查询分离为字符串变量然后传递给数据库查询函数的问题。

例如,

这会导致错误。



await db.execute('''
CREATE TABLE TEST(.................
..................)
''');



解决方案 :

String query='''
CREATE TABLE TEST(.................
..................)
''';

await db.execute(query);


于 2019-12-29T06:50:29.743 回答