Reputation: 1052
I have created a data table with sqflite. But it showed me a syntax error. Can you tell me please where is the syntax error here?
Future _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY,
$columnfid VARCHAR,
$columnfname TEXT,
)
''');
}
Here is the error:
Exception has occurred.
SqfliteDatabaseException (DatabaseException(near ")": syntax error (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE fid_table (
id INTEGER PRIMARY KEY,
fid VARCHAR,
fname TEXT,
)) sql ' CREATE TABLE fid_table (
id INTEGER PRIMARY KEY,
fid VARCHAR,
fname TEXT,
)
' args []})
Upvotes: 3
Views: 3419
Reputation: 9117
The issue is with the trailing comma (,) of the SQL, i.e after the last TEXT.
Instead of
await db.execute('''
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY,
$columnfid VARCHAR,
$columnfname TEXT,
)
''');
try
wait db.execute('''
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY,
$columnfid VARCHAR,
$columnfname TEXT
)
''');
Also, the extra quotes are not required as well. So, you could write this as well.
wait db.execute('
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY,
$columnfid VARCHAR,
$columnfname TEXT
)
');
Upvotes: 10