SqfliteDatabaseException (DatabaseException(near ")": syntax error

904

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
      )
      ');
Share:
904
Santo Shakil
Author by

Santo Shakil

Nothing special about me.

Updated on December 21, 2022

Comments

  • Santo Shakil
    Santo Shakil over 1 year

    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 []})