Flutter SQLite Syntax Error near TEXT decimal point - android

I can't seem to figure out what this syntax error is, I have tried TEXT & BLOB for both the mac & the image fields but nothing seems to work. Please help!
customQuery("CREATE TABLE Profile ("
"mac TEXT,"
"image TEXT,"
"name TEXT,"
"age INT,"
"nationality TEXT,"
"profession TEXT,"
"about TEXT"
")");
onPressed: () {
profile.add(Profile(
mac: _platformVersion,
image: imagePath,
name: nameController.text,
age: ageController.text,
nationality: nationalityController.text,
profession: professionController.text,
about: aboutController.text));
DBProvider.db.customQuery("INSERT Into Profile (mac,image,name,age,nationality,profession,about)"
" VALUES (${profile[0].mac},${profile[0].image},"
"${profile[0].name},${profile[0].age},${profile[0].nationality},"
"${profile[0].profession},${profile[0].about});");
},
& this is the error
E/SQLiteLog( 4520): (1) near ".0": syntax error in "INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES (0.0.0.0.0.0,/data/user/0/com.test.fltestar/cache/scaled_image_picker3315305739073272987.jpg,test,35,test
E/flutter ( 4520): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: DatabaseException(near ".0": syntax error (code 1 SQLITE_ERROR): , while compiling: INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES (0.0.0.0.0.0,/data/user/0/com.test.test/cache/scaled_image_picker3315305739073272987.jpg,test,35,test,test,test);) sql 'INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES (0.0.0.0.0.0,/data/user/0/com.test.test/cache/scaled_image_picker3315305739073272987.jpg,test,35,test,test,test);' args []

The INSERT syntax is, in fact, wrong.
Here's your actual syntax:
INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES (0.0.0.0.0.0,/data/user/0/com.test.fltestar/cache/scaled_image_picker3315305739073272987.jpg,test,35,test,test,test);
But the values are not expressed as TEXTs for all TEXT fields. It should be something like this:
INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES ('0.0.0.0.0.0','/data/user/0/com.test.fltestar/cache/scaled_image_picker3315305739073272987.jpg','test',35,'test','test','test');
Also, I would suggest you use libraries like moor, that helps you a lot.

Related

SQLite database not recognizing one of my columns

I'm trying to create an SQLite database in an Android app, but my app keeps crashing and LogCat gives the following error:
FATAL EXCEPTION: main
Process: com.zebra.leadcapture, PID: 15427
android.database.sqlite.SQLiteException: table lead_capture_database has no column named EntryNumber (code 1): , while compiling: INSERT INTO lead_capture_database(EntryNumber,BarcodeData,Notes) VALUES('0','','');
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(table lead_capture_database has no column named EntryNumber (code 1): , while compiling: INSERT INTO lead_capture_database(EntryNumber,BarcodeData,Notes) VALUES('0','','');)
Here's the code I'm using:
public void addNewEntry(String barcodeDataString, String notesString) {
leadDatabase = openOrCreateDatabase(database_name,MODE_PRIVATE,null);
String create_string = "CREATE TABLE IF NOT EXISTS " + database_name
+ "(EntryNumber TEXT,BarcodeData TEXT,Notes TEXT);";
String insert_string = "INSERT INTO " + database_name + "(EntryNumber,BarcodeData,Notes) VALUES('" + entryCount + "','" + barcodeDataString + "','" + notesString + "');";
leadDatabase.execSQL(create_string);
leadDatabase.execSQL(insert_string);
entryCount++;
}
Why is it not recognizing EntryNumber as a column?
This was answered in the comments above, but for future reference: I deleted the app from my device and reinstalled it through Android Studio which fixed the problem. I had previously been writing the app with a SQLite database without that column but with the same name. I imagine changing the string I was using for the name would have had the same effect.
You added that column after table was created. In this case, that column is not added into database. If you drop the table and recreate it, it will fix your problem without uninstalling the app. Also you can create a method for migration.

Whats wrong with my SQLite query?

Error:
android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: CREATE TABLE new_info(user-name TEXT,user_mob TEXT,user_email TEXT);
Code:
public String CREATE_QUERY="CREATE TABLE "+ UserContract.addnew.TABLE_NAME+"("+ UserContract.addnew.USER_NAME+" TEXT,"
+ UserContract.addnew.MOBILE+" TEXT,"+ UserContract.addnew.EMAIL+" TEXT);";
As you can see in the query it tries to execute: CREATE TABLE new_info(user-name TEXT,user_mob TEXT,user_email TEXT); You have - instead of _. Just replace user-name with user_name.
Check this post to understand how to be able to use hyphen in the table names.

Inserting apostrophe values in sqlite error

I cant a able to insert apostrophe character in sqlite . I tried this way what many says in forum is replace " ' " with " ' ' "
String replace=replaceString.replace("'"," ''") but after using this method too gives insert error.
I like to use
String replace = replaceString.replace("'","\'");
This will insert the apostrophe into the table.
Are you looking to use ' in a string?
If so you can do this
"insert into my_table set myvalue = 'My dog\'s bone' where id = 5"

Android database tables syntax errors

I am trying to create a database with the name of a string stored in a local variable with the following syntax:
mDb.execSQL("CREATE TABLE " + FLASH_TABLE + " (" + KEY_CARD_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUESTION
+ "TEXT NOT NULL," + KEY_ANSWER + "TEXT NOT NULL);");
which produces the following error in log cat:
05-14 04:40:05.892: ERROR/Database(372): Failure 1 (near "15": syntax error) on 0x272140 when preparing 'CREATE TABLE 15 (_id INTEGER PRIMARY KEY AUTOINCREMENT, questionTEXT NOT NULL,answerTEXT NOT NULL);'.
with FLASH_TABLE being the local variable with the value "15"
KEY_QUESTION and KEY_ANSWER are also local variables
I have looked at every example online that I could find and I can not find the reason for the syntax error. I appreciate any advice you can offer.
You cannot create a table name (or a field name, for that matter) with a string that begins with a number unless you double-quote it. But even though it's technically possible, it's not considered a best practice. If you do, you will also have to double-quote the table name every time you use it in a query so you will quickly find that it's more trouble than it's worth.

sqlite error in android

I am getting the value from webservice. I am storing in sqlite. While storing in sqlite, I am getting an error. even I replaced single quote with "\'". Which characters are not supported in sqlite?
My error is:
03-26 13:22:22.478: WARN/System.err(311): android.database.sqlite.SQLiteException: near "s": syntax error:
My insert statement is:
myDB.execSQL("INSERT INTO "+TableName
+"("+fieldname+")"
+" VALUES ('"+(homevalue)+"');");
Can anybody tell what to do or give an example?
there is a name which is like "name's" i.e this single quote is problem
Maybe one of your string TableName, fieldname or homevalue contains some quotation. print out the query first and see.
I am just a beginner,
but i think you should write it like this:
"INSERT INTO " + tableName + "(" + feildName + ") VALUES ('" + homeValue + "');"
you put () around the homeValue

Categories

Resources