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
[Here][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
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'] ?? "");
}
}
CodePudding user response:
The query in plantTableQuery
is incomplete:
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. They show you that in a CREATE TABLE
query:
- the
column-name
s should be enclosed in brackets (you don't have a closing bracket)
) - there are commas between
column-name
s, but there can't be one before the closing bracket)
.
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:
... word_main_audio TEXT, story_audio TEXT, )
CodePudding user response:
You have a syntax error in your INSERT query near values.
Insert should be in this format
INSERT INTO table (column1,column2 ,..)
VALUES( value1, value2 ,...);
You are missing closing brackets just after column 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}'
)''';
}