Tag: sqlite

RealmObject AND Parcelable

I’m new to Realm for Android so I’m not sure I’m approaching this the right way. I have a class which looks like this: public class Entry extends RealmObject implements Parcelable { … } The problem is the Parcelable interface contains methods like describeContents() writeToParcel() and RealmObjects aren’t supposed to have methods other than getters […]

How to use rawQuery to insert a record

I need to store a record using rawQuery method, because i want to insert the current date and time (datetime()), but I also need to insert strings that contain quotes. So I wrote this code: String sql=”INSERT INTO sms VALUES ( null, ?1, ?2, ?3, datetime())”; dbw.rawQuery(sql, new String[]{str1,str2,str3}); But it doesn’t store anything… what’s […]

Android: copy database from asset folder, but only get an empty file

guys, I have the problem when copying database from local assets folder to /data/data/package_name/databases directory. As I use the http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ tutorial to do it, I can only get an empty file. I quoted the part of copyDataBase() method and there is no difference. Every time the app start, it will create the directory and empty […]

SQLite Drop and Recreate Table

How do I drop and recreate a table with updated information? For example; I have a table in my application with 5 records. ID Entry 1 a 2 b 3 c 4 d 5 e Now when I delete a record lets say, ID 3 the table becomes ID Entry 1 a 2 b 4 […]

How do I create an SQLite database in Android by importing from an SQL file?

I have a big text file containing SQL CREATE TABLE and INSERT statements. How do I import this file in the SQLiteOpenHelper onCreate method? Or, is there an accepted way of using the binary database file directly? I need this to be compatible with Android 1.6.

Should I use a Content Provider?

I’m reading the official documentation from android‘s content providers and I’ve seen this: Decide if you need a content provider. You need to build a content provider if you want to provide one or more of the following features: You want to offer complex data or files to other applications. You want to allow users […]

Android and SQLite: When to use semicolons to end statements?

If you are using the rawQuery() or execSQL() methods of SQLite on Android, when should you use a semicolon to end your statement? On this tutorial, for instance, the author uses the semicolon on the create table statement (via execSQL), but not on select statement (via rawQuery). For instance: Create Table Statement: private static final […]

UNIQUE constraint failed: sqlite database : android

I am trying to insert values in table. But there is only one value inserted. I am getting an error in log cat when I am trying to insert new values. Log cat shows : abort at 13 in [INSERT INTO event(totalminutesfrom,dayofweek,title,location,totalminutesto,id) VALUES (?,?,?,?,?,?)]: UNIQUE constraint failed: event.id 01-24 11:34:39.764 7763-7763/com.example.siddhi.timetablelayout E/SQLiteDatabase: Error inserting totalminutesfrom=694 […]

E/SQLiteLog(1893): (14) cannot open file at line 30176 of

I am using this tutorial to import a database into my App. It runs fine on API 10, but on API 17 it throws the following error: 05-19 14:52:46.492: E/SQLiteLog(1893): (14) cannot open file at line 30176 of [00bb9c9ce4] 05-19 14:52:46.492: E/SQLiteLog(1893): (14) os_unix.c:30176: (2) open(/data/data/com.example.koday/databases/dizionario7.sqlite) – 05-19 14:52:46.492: E/SQLiteDatabase(1893): Failed to open database ‘/data/data/com.example.koday/databases/dizionario7.sqlite’. […]

how should I open and close my database properly

I have an app which stores some data in a SQLite DB.Also I’m doing a lot of query an requery in my app.I have about 15 activities in it.And almoust all use the DB to query for data. But what I’m doing is opening my DB in every activity and close it in onDestroy{…} of […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.