Create table语句中存在Sqlite语法错误-flutter/dart



我一直收到这个语法错误:E/SQLiteLog(4514(:(1(near"null":"中的语法错误;CREATE TABLE expenses_TABLE(id INTEGER PRIMARY KEY AUTOINCREMENT,空文本,空文本(">

我对此很陌生,并且一直在网上使用示例将这些代码组合在一起,但我似乎找不到是什么导致了这个问题。

任何帮助都将不胜感激!

''

import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'dart:async';
import 'expense_list.dart';
class ExpensesDatabase {
static ExpensesDatabase _expensesDatabase;
static Database _database;
String expensesTable = 'expenses_table';
String id = 'id';
String name;
String amount;
ExpensesDatabase._createInstance();
factory ExpensesDatabase() {
if (_expensesDatabase == null) {
_expensesDatabase = ExpensesDatabase._createInstance();
}
return _expensesDatabase;
}
Future<Database> get database async {
if (_database == null) {
_database = await initializeDatabase();
}
return _database;
}
Future<Database> initializeDatabase() async {
Directory directory = await getApplicationDocumentsDirectory();
String path = directory.path + 'expenses.db';
var expensesDatabase =
await openDatabase(path, version: 1, onCreate: _createDb);
return expensesDatabase;
}
void _createDb(Database db, int newVersion) async {
await db.execute(
'CREATE TABLE $expensesTable($id INTEGER PRIMARY KEY AUTOINCREMENT,'
'$name TEXT,'
'$amount TEXT)');
}

''

初始化您的名称和金额变量,由于字符串名称和金额尚未初始化,它将变为null。

String name = 'name';
String amount = 'amount';

最新更新