Questions tagged [sqliteopenhelper]

SQLiteOpenHelper is a class from the Android SDK which can be used for easier handling of a SQLiteDatabase.

Using the SQLiteOpenHelper only requires implementing its two abstract methods(other methods for different events can be implemented if the user chooses) onCreate(used for initializing the database) and onUpgrade(used when the database is being changed). The Android system will call this methods according to the state of the database( not created/created/upgrading) and in return, it will offer the user a valid SQLiteDatabase reference with the methods getWritableDatabase() and/or getReadableDatabase(). More information can be found in the documentation for the SQLiteOpenHelper class.

801 questions
1
vote
1 answer

onCreate() method calling instead of onUpgrade() method while updating database

I have an app with a database version = 1. Now I want to upgrade my database to version = 2. However my problem is when I am running updated application on previous version with changed database version it is calling onCreate() method instead of…
Kunu
  • 5,078
  • 6
  • 33
  • 61
1
vote
2 answers

Android SQLite database sharing across activities

Background info: new to Android, not to Java. I am writing an app that sends its own messages separately from the default Android sms app. Since my app is not the default, I can't write to Android's provider.sms.outbox, which is absolutely fine. To…
CoffeeSaurus
  • 105
  • 1
  • 11
1
vote
2 answers

sqlite database hardcode /data/ db_path android

Cannot retrieve database, and shows a lint warning that says: Do not hardcode "/data/"; use Context.getFilesDir().getPath() instead Have tried searching for related errors but nothing helps. Here's the code private static String DB_PATH =…
Kaitlin Reyes
  • 71
  • 1
  • 8
1
vote
0 answers

Can't insert to Sql tables with classes extends

I asked this question previously but I had no answer because I was not clear. I created a model class of "People" with some variable and another class to extends the People class. and when i tried to insert to the tables it seem only one table are…
Matan
  • 296
  • 5
  • 24
1
vote
1 answer

Android SQLite database re-Import

in my project i have imported a sqlite database using this.. private void copyDataBase() throws IOException{ InputStream myInput = myContext.getAssets().open(DB_NAME); String outFileName = DB_PATH + DB_NAME; OutputStream myOutput =…
Anwar Hossain
  • 654
  • 6
  • 21
1
vote
1 answer

SQLiteOpenHelper.setWriteAheadLoggingEnabled(true) vs SQLiteDatabase.enableWriteAheadLogging()

I was looking at the JavaDoc for SQLiteOpenHelper and noticed the setWriteAheadLoggingEnabled(boolean) method. The SQLiteOpenHelper doc suggest enabling write-ahead logging in a helper's onConfigure(SQLiteDatabase) method. Is there any difference…
spaaarky21
  • 6,524
  • 7
  • 52
  • 65
1
vote
2 answers

cannot bind argument at index because the index is out of range

i still have problem with this sqlitedatabase. you know i want to store and retrieve data in sqlite database. i have a table named tour with five column. my database has been create and i could see it via filemanager but the problem is that the both…
1
vote
3 answers

I can't get data from Cursor Object

I've following table structure in my SQLite Database. In my SqliteOpenHelper class, I wrote following method. public Form getAllForms(){ SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from "+FORM_TABLE,…
Zin Win Htet
  • 2,448
  • 4
  • 32
  • 54
1
vote
1 answer

getReadableDatabase get database called recursively

Okay, so I've gone over all the question here as well as many of the tutorials out there about creating an SQLiteDatabase. Last night I had this working perfectly and now today I am getting the "Get Database called recursively" error, even after I…
Jeremey
  • 13
  • 4
1
vote
3 answers

Proper way to copy database from /assets to app's private storage

I have template database in /assets directory. This database has to be copied to the main app's database which resides in the private storage area. Now, all samples I've seen on the Internet seem very odd to me. Namely, they all extend…
sandalone
  • 41,141
  • 63
  • 222
  • 338
1
vote
1 answer

Android SQLiteOpenHelper onUpdate doesn't drop table with rows

I'm trying to drop my tables onUpgrade, and it does delete the empty tables, but if tables have rows in it - it doesn't get deleted. I've tried the following code to clean the table first: @Override public void onUpgrade(SQLiteDatabase db, int…
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
1
vote
3 answers

Accessing SQLite database from fragment

My app contains MainActivity class and several fragments. One of the is the registration fragment which I want it to be able tho interact with my database which should contain only one table named USERS to whom I will CRUD. I've opened the…
evyamiz
  • 164
  • 1
  • 1
  • 15
1
vote
1 answer

Should simultaneously having multiple different SQLite Database Versions be considered harmful?

I am breaking out each SQLite table's code (including initial construction of the table as well as operations on that table) into separate classes extending SQLiteOpenHelper. In order to get these tables to be created (that is to say, to get the…
1
vote
1 answer

Singleton database: "attempt to re-open an already-closed object: SQLiteDatabase” when working from both app and service

So I have two contexts (service and UI activity) running from the same process, and also I use traditional's wrapped way to get write handle: package me.soexample.sobad; import java.util.concurrent.atomic.AtomicInteger; import…
kagali-san
  • 2,964
  • 7
  • 48
  • 87
1
vote
0 answers

Sqlite database connection lost at real time use of application

I have my database class that is extending SQLiteOpenHelper which contains all the steps to create the database instance and executing queries. DbAdapter.java Creating database instance to be used throughtout my application------ public static…
sjain
  • 23,126
  • 28
  • 107
  • 185