1

error DatabaseException(near ")": syntax error (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE my_table ( I/flutter (21754): _id INTEGER PRIMARY KEY, I/flutter (21754): name TEXT NOT NULL, I/flutter (21754): address TEXT NOT NULL, I/flutter (21754): comments TEXT NOT NULL, I/flutter (21754): sigURL TEXT NOT NULL, I/flutter (21754): selfpicURL TEXT NOT NULL, I/flutter (21754): I/flutter (21754): hi INT NOT NULL, I/flutter (21754): time TEXT NOT NULL,

import 'dart:io';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path_provider/path_provider.dart';

class DatabaseHelper {

static final _databaseName = "MyDatabase.db";
static final _databaseVersion = 1;

static final table = 'my_table';

static final columnId = '_id';
static final columnName = 'name';
static final address = 'address';

static final comments = 'comments';
static final sigURL = 'sigURL';

static final columnAge = 'hi';

static final  selfpicURL = 'selfpicURL';

static final  createdTime = 'time';

DatabaseHelper._privateConstructor();
static final DatabaseHelper instance = DatabaseHelper._privateConstructor();

static Database? _database;
Future<Database> get database async {
if (_database != null) return _database!;
// lazily instantiate the db the first time it is accessed
_database = await _initDatabase();
return _database!;
}

_initDatabase() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, _databaseName);
return await openDatabase(path,
version: _databaseVersion,
onCreate: _onCreate);
}

Future _onCreate(Database db, int version) async {
await db.execute('''
          CREATE TABLE $table (
            $columnId INTEGER PRIMARY KEY,
            $columnName TEXT NOT NULL,
            $address TEXT NOT NULL,
           $comments TEXT NOT NULL,
            $sigURL TEXT NOT NULL,
           $selfpicURL TEXT NOT NULL,

           $columnAge INT NOT NULL,
            $createdTime TEXT NOT NULL,

                        
                        
            
          )
          ''');
}


Future<int> insert(Map<String, dynamic> row) async {
Database db = await instance.database;
return await db.insert(table, row);
}


Future<List<Map<String, dynamic>>> queryAllRows() async {
Database db = await instance.database;
return await db.query(table);
}


Future queryRowCount() async {
Database db = await instance.database;
return Sqflite.firstIntValue(await db.rawQuery('SELECT COUNT(*) FROM $table'));
}


Future<int> update(Map<String, dynamic> row) async {
Database db = await instance.database;
int id = row[columnId];
return await db.update(table, row, where: '$columnId = ?', whereArgs: [id]);
}


Future<int> delete(int id) async {
Database db = await instance.database;
return await db.delete(table, where: '$columnId = ?', whereArgs: [id]);
}
}

3 Answers 3

7

SQLite SQL parser does not support trailing comma before the end parenthesis

Instead of (at the end of your statement)

  ...
  $createdTime TEXT NOT NULL,
)

do

  ...
  $createdTime TEXT NOT NULL
)
Sign up to request clarification or add additional context in comments.

Comments

1
create table $tableTodo ( 
  $columnId integer primary key autoincrement, 
  $columnTitle text not null,
  $columnDone integer not null)
''');

if you look carefully in the last line $columnDone integer not null it has no comma like the other 2 top lines, that's the problem in your code.

for more info

Happy coding

Comments

1

SQLite doesn't support trailing commas. Try removing the comma of your last statement about creating a table. for example

if you are writing like this;

$createdTime TEXT NOT NULL,

try instead;

$createdTime TEXT NOT NULL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.