Having an error with creating a sqlite table in Android - android

I'm having a problem with creating a table:
Error:
08-31 02:31:21.559 4121-4121/? E/SQLiteLog﹕ (1) near "limit": syntax error
08-31 02:31:21.689 4121-4121/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start receiver com.mbb.common.SmsReceiver: android.database.sqlite.SQLiteException:
near "limit": syntax error (code 1): , while compiling: CREATE TABLE
feedback(type, speed, expaierdate, date , limit );
MY Code:
db.execSQL("CREATE TABLE feedback(type , speed , expaierdate , date , limit);");

LIMIT is a keyword.
You can either quote it:
db.execSQL("CREATE TABLE feedback(type, speed, expaierdate, date, \"limit\");");
(in which case you have to quote it every time you use it), or use another name:
db.execSQL("CREATE TABLE feedback(type, speed, expiredate, date, some_limit);");

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.

Android Studio Database SQLite Error

i want to build a database system with android studio, so i follow a step on someone blog.
When i start to save a data that i have inputted from my phone, the data cannot saved to the database.
Here is the log cat when i run my app
05-27 17:01:26.579 10597-10597/com.example.opec.menuprototype E/SQLiteLog: (1) table MenuTable has no column named menu_name
05-27 17:01:26.594 10597-10597/com.example.opec.menuprototype E/SQLiteDatabase: Error inserting menu_name=migor menu_id=1st menu_desc=mie menu_price=12000
android.database.sqlite.SQLiteException: table MenuTable has no column named menu_name (code 1): , while compiling: INSERT INTO MenuTable(menu_name,menu_id,menu_desc,menu_price) VALUES (?,?,?,?)
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(table MenuTable has no column named menu_name (code 1): , while compiling: INSERT INTO MenuTable(menu_name,menu_id,menu_desc,menu_price) VALUES (?,?,?,?))
Which part of the code you need to look up ? i will get it for you.
Replace this line
Context context = View.getRootView.getContext();
With this line
Context context = v.getRootView().getContext();

How to insert data in database in android I am getting some error?

I am getting this error. Please give me some tutorials. So that I can improve.
Please do not down vote this is been asked by my student
01-17 16:07:05.234: E/AndroidRuntime(26559): android.database.sqlite.SQLiteException: near "table": syntax error (code 1): , while compiling: CREATE TABLE table(_id INTEGER PRIMARY KEY Autoincrement,date INTEGER,quantity TEXT,materialTEXT ;)
01-17 16:07:05.234: E/AndroidRuntime(26559): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
01-17 16:07:05.234: E/AndroidRuntime(26559): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
01-17 16:07:05.234: E/AndroidRuntime(26559): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
As in log create table query require space between material column name and TEXT data-type:
CREATE TABLE table(_id INTEGER PRIMARY KEY Autoincrement,
date INTEGER,quantity TEXT,material TEXT) ;

SQLiteException: near "-": syntax error

I'm getting this exception when doing a create view sentence:
04-10 10:09:55.475: E/AndroidRuntime(15451): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mo.activity}: android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: CREATE VIEW vNa-MarcadbRESID1dataV18 AS SELECT * FROM ITEMS WHERE 1 AND ( 1 != 1 OR Column7 = 1 )
Where is the problem?
vNa-MarcadbRESID1dataV18 is not a valid name for a View in sqlite?
Identifiers such as view names cannot contain - - it parses as subtraction expression. Either rename it or quote it in `backticks` or "double quotes".

Android SQLite Beginner Error

Just a real quick question, probably something really simple but I've never done ANYTHING with databases before, can someone tell me why the second line is giving me an error?
Thank you! :)
SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS index (ChalNum INT(3));");
ERROR:
ERROR: 02-12 05:21:47.573: E/AndroidRuntime(1199): java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.example/com.example.Home}:
android.database.sqlite.SQLiteException: near "Index": syntax error (code 1): ,
while compiling: CREATE TABLE IF NOT EXISTS Index (ChalNum INT(3));
You can not use the Index name for the Table. Its a keyword for SQLite.
Try out with Index1 or some other name.
Besides using exact word Index use Index1 as below:
db.execSQL("CREATE TABLE IF NOT EXISTS Index1 (ChalNum INT(3));");
INDEX is a SQLite keyword. Choose a different name for your table.
You will like to use:
db.execSQL("CREATE TABLE IF NOT EXISTS index1 (ChalNum INTEGER);");
Emil

Categories

Resources