简体   繁体   English

数据库异常错误 SQLLITE 和 FLUTTER

[英]Database Exception Error SQLLITE and FLUTTER

Can I get some help with this please...I am getting error like我能得到一些帮助吗...我收到类似的错误

1) near "VALUES": syntax error
I/flutter ( 6415): DatabaseException(near "VALUES": syntax error (code 1 SQLITE_ERROR): , while compiling: INSERT INTO words (

here is my dart model code..it says something is wrong here这是我的 dart model 代码..它说这里有问题

[Here][1] [这里][1]

Wordtable is my SQLite model where I'm saving the data and Word is my backend model where I'm fetching the data to save into SQLite one Wordtable 是我的 SQLite model,我在其中保存数据,Word 是我的后端 model,我在其中获取数据以保存到 SQLite 中

I tried to make it short and precise as possible so please do let me know if any further clarification is needed.我尽量使它简短和准确,所以如果需要任何进一步的说明,请告诉我。 Thank you and happy new year谢谢你,新年快乐

class WordList {
  List<Word>? words;

  WordList({this.words});

  factory WordList.fromJson(List<dynamic> json, String lang) {
    List<Word> words = json.map((i) => Word.fromJson(i, lang)).toList();

    return new WordList(
      words: words,
    );
  }
}

class WordTableList {
  final List<WordTable>? words;

  WordTableList({this.words});

  factory WordTableList.fromJson(List<dynamic> json) {
    List<WordTable> words = json.map((e) => WordTable.fromMap(e)).toList();

    return new WordTableList(
      words: words,
    );
  }
}

////////////////////WordTable SQLLITE/////////////////////
class WordTable {
  static String table = 'words';
  int? WORD_ID;
  String? TINA;
  String? LETTER;
  String? NABA;
  String? ITAVI;
  String? LOMANIBAI;
  String? DEWA;
  String? IVAKAMACALA;
  String? COKE;
  String? IDUSIDUSI;
  // String? LINKED_SYN;
  String? IVOSAVOSA;
  String? ITAKATAKA;
  String? VOSA_VAKALATINA;
  String? WORDIMG;
  String? MAIN_AUDIO;
  String? STORY_AUDIO;

  WordTable.fromJson(Map<String, dynamic> json) {
    this.WORD_ID = json['word_id'];
    this.TINA = json['tina'];
    this.LETTER = json['letter'];
    this.NABA = json['naba'];
    this.ITAVI = json['itavi'];
    this.LOMANIBAI = json['lomanibai'];
    this.DEWA = json['dewa'];
    this.IVAKAMACALA = json['ivakamacala'];
    this.COKE = json['coke'];
    this.IDUSIDUSI = json['idusidusi'];
    //this.LINKED_SYN = json['ivosavosa'];
    this.IVOSAVOSA = json['ivosavosa'];
    this.ITAKATAKA = json['itakataka'];
    this.VOSA_VAKALATINA = json['vosa_vakalatina'];
    this.WORDIMG = json['word_main_image'];
    this.MAIN_AUDIO = json['word_main_audio'];
    this.STORY_AUDIO = json['story_audio'];
    // if (json['family'] != null) {
    //   this.plantFamily = PlantFamily.fromJson(json['family']);
    // }
  }

  WordTable.fromMap(Map<String, dynamic> json) {
    this.WORD_ID = json['word_id'] == null ? 0 : json['word_id'];
    this.TINA =
        json['tina'] == null ? "No Scientific Name Available" : json['tina'];
    this.LETTER =
        json['letter'] == null ? "No Local Name Available" : json['letter'];
    this.NABA = json['naba'] == null
        ? "storage/images/13293205681610263850.png"
        : json['naba'];
    this.ITAVI =
        json['itavi'] == null ? "No Description Available" : json['itavi'];
    this.LOMANIBAI = json['lomanibai'] == null
        ? "No Description Available"
        : json['lomanibai'];
    this.DEWA =
        json['dewa'] == null ? "No Distribution Available" : json['dewa'];
    this.IVAKAMACALA = json['ivakamacala'] == null
        ? "No Distribution Available"
        : json['ivakamacala'];
    this.COKE =
        json['coke'] == null ? "No Distribution Available" : json['coke'];
    this.IDUSIDUSI = json['idusidusi'] == null
        ? "No Description Available"
        : json['idusidusi'];
    this.IVOSAVOSA = json['ivosavosa'] == null
        ? "No Description Available"
        : json['ivosavosa'];
    this.ITAKATAKA = json['itakataka'] == null
        ? "No Description Available"
        : json['itakataka'];
    this.VOSA_VAKALATINA = json['vosa_vakalatina'] == null
        ? "No Description Available"
        : json['vosa_vakalatina'];
    this.WORDIMG = json['word_main_image'] == null
        ? "No Description Available"
        : json['word_main_image'];
    this.MAIN_AUDIO = json['word_main_audio'] == null
        ? "No Description Available"
        : json['word_main_audio'];
    this.STORY_AUDIO = json['story_audio'] == null
        ? "No Description Available"
        : json['story_audio'];
    // this.hpfMedicalUseOtherFj = json['hpf_medical_use_other_fj'] == null
    //     ? "No Description Available"
    //     : json['hpf_medical_use_other_fj'];
    // if (json['plant_family'] != null) {
    //   print('family is not null');
    //   this.plantFamily = new PlantFamily(
    //       bookChapterId: 0,
    //       hpfBotanicalCat: json['plant_botanical_category'],
    //       hpfBotanicalSubCat: json['plant_sub_botanical_category'],
    //       hpfFamilyName: json['plant_family'],
    //       id: 0);
    //}
  }

  static String plantTableQuery(WordTable words) {
    return ''' INSERT INTO words (
    word_id, 
    tina,
    letter,
    naba,
    itavi,
    lomanibai,
    dewa,
    ivakamacala,
    coke,
    idusidusi,
    ivosavosa,
    itakataka,
    vosa_vakalatina,
    word_main_image,
    word_main_audio,
    story_audio,
    VALUES (
    '${words.WORD_ID}',
    '${words.TINA}',
    '${words.LETTER}',
    '${words.NABA}',
    '${words.ITAVI}',
    '${words.LOMANIBAI}',
    '${words.DEWA}',
    '${words.IVAKAMACALA}',
    '${words.COKE}',
    '${words.IDUSIDUSI}',
    '${words.IVOSAVOSA}',
    '${words.ITAKATAKA}',
    '${words.VOSA_VAKALATINA}',
    '${words.WORDIMG}',
    '${words.MAIN_AUDIO}',
    '${words.STORY_AUDIO}'
    )''';
  }

  static const String CREATE_TABLE = '''CREATE TABLE IF NOT EXISTS words ( 
    word_id INTEGER PRIMARY KEY,
    tina TEXT,
    letter TEXT,
    naba TEXT,
    itavi TEXT,
    lomanibai TEXT,
    dewa TEXT,
    ivakamacala TEXT,
    coke TEXT,
    idusidusi TEXT,
    ivosavosa TEXT,
    itakataka TEXT,
    vosa_vakalatina TEXT,
    word_main_image TEXT,
    word_main_audio TEXT,
    story_audio TEXT,
)''';

  static const String DELETE_TABLE = 'DROP TABLE IF EXISTS words';
}

//////////////////////////////WordTable SQLLITE END////////////////////////////////

class Word {
  static String table = 'words';
  int? WORD_ID;
  String? TINA;
  String? LETTER;
  String? NABA;
  String? ITAVI;
  String? LOMANIBAI;
  String? DEWA;
  String? IVAKAMACALA;
  String? COKE;
  String? IDUSIDUSI;
  String? LINKED_SYN;
  String? IVOSAVOSA;
  String? ITAKATAKA;
  String? VOSA_VAKALATINA;
  String? WORDIMG;
  String? MAIN_AUDIO;
  String? STORY_AUDIO;

  Word(
      {this.WORD_ID,
      this.TINA,
      this.LETTER,
      this.NABA,
      this.ITAVI,
      this.LOMANIBAI,
      this.DEWA,
      this.IVAKAMACALA,
      this.COKE,
      this.IDUSIDUSI,
      this.LINKED_SYN,
      this.IVOSAVOSA,
      this.ITAKATAKA,
      this.VOSA_VAKALATINA,
      this.WORDIMG,
      this.MAIN_AUDIO,
      this.STORY_AUDIO});

  factory Word.fromJson(Map<String, dynamic> json, String lang) {
    return Word(
        WORD_ID: json['word_id'] ?? "0",
        TINA: json['tina'] ?? "",
        LETTER: json['letter'] ?? "",
        NABA: json['naba'] ?? "0",
        ITAVI: json['itavi'] ?? "0",
        LOMANIBAI: json['lomanibai'] ?? "",
        DEWA: json['dewa'] ?? "",
        IVAKAMACALA: json['ivakamacala'] ?? "No Description Provided",
        COKE: json['coke'] ?? "",
        IDUSIDUSI: json['idusidusi'] ?? "",
        IVOSAVOSA: json['ivosavosa'] ?? "",
        ITAKATAKA: json['itakataka'] ?? "",
        VOSA_VAKALATINA: json['vosa_vakalatina'] ?? "",
        WORDIMG: json['word_main_image'] ?? "",
        MAIN_AUDIO: json['word_main_audio'] ?? "",
        STORY_AUDIO: json['story_audio'] ?? "");
  }
}

The query in plantTableQuery is incomplete: plantTableQuery中的查询不完整:

 INSERT INTO words (... word_main_audio, story_audio, VALUES ( '${words.WORD_ID}', '${words.TINA}', ... ```

SQLite has diagrams on their website that show the syntax of commands. SQLite在他们的网站上有显示命令语法的图表。 They show you that in a CREATE TABLE query:他们在CREATE TABLE查询中向您展示:

  • the column-name s should be enclosed in brackets (you don't have a closing bracket ) ) column-name应该用方括号括起来(你没有右方括号)
  • there are commas between column-name s, but there can't be one before the closing bracket ) . column-name之间有逗号,但右括号)之前不能有逗号。

The CREATE TABLE diagram shows you that the query in variable CREATE_TABLE may not have a comma before the closing bracket ) that encloses the column-def s, either: CREATE TABLE向您显示,变量CREATE_TABLE中的查询在括起column-def的右括号)之前可能没有逗号,或者:

 ... word_main_audio TEXT, story_audio TEXT, )

You have a syntax error in your INSERT query near values.您在靠近值的 INSERT 查询中有语法错误。

Insert should be in this format插入应该是这种格式

INSERT INTO table (column1,column2 ,..)
VALUES( value1, value2 ,...);

You are missing closing brackets just after column story_audio.您在 story_audio 列之后缺少右括号。

static String plantTableQuery(WordTable words) {
    return ''' INSERT INTO words (
    word_id, 
    tina,
    letter,
    naba,
    itavi,
    lomanibai,
    dewa,
    ivakamacala,
    coke,
    idusidusi,
    ivosavosa,
    itakataka,
    vosa_vakalatina,
    word_main_image,
    word_main_audio,
    story_audio) 
    VALUES(
    '${words.WORD_ID}',
    '${words.TINA}',
    '${words.LETTER}',
    '${words.NABA}',
    '${words.ITAVI}',
    '${words.LOMANIBAI}',
    '${words.DEWA}',
    '${words.IVAKAMACALA}',
    '${words.COKE}',
    '${words.IDUSIDUSI}',
    '${words.IVOSAVOSA}',
    '${words.ITAKATAKA}',
    '${words.VOSA_VAKALATINA}',
    '${words.WORDIMG}',
    '${words.MAIN_AUDIO}',
    '${words.STORY_AUDIO}'
    )''';
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM