Android :: SQLite Using The SQLiteOpenHelper

Jun 9, 2010

I have a SQLite database, and several tables within that datbase. I am developing a DBAdapter for each table within the database. (reference Reto Meier's Professional Android 2 Application Development, Listing 7.1).

I am using the adb shell to interface with the database from the command line and see that the database is being populated as I expect. Occasionally, I want to drop a table so that I can ensure it's being built properly, from scratch.

The problem is that SQLiteOpenHelper only checks to see if the database exists. Is there a typical solution to writing a helper to also see that the table(s) exists? Basically once I drop a table, the helper checks to see that the database exists and assumes all is well.

Also, the CREATE_DATABASE string used in the reference above only creates the one table. Should I consider using the DBAdapter for an adapter to ALL of my tables? That doesn't seem as clean to me.

Android :: SQLite using the SQLiteOpenHelper


Android :: SQLiteOpenHelper Per Activity?

Jul 21, 2010

Do I need an instance of my SQLiteOpenHelper class for each Activity I have? I have 1 currently that all activities access, but started getting an exception

"illegal state exception SQLiteDatabase created and never closed "

on simple a simple query and I can't seem to figure out why this is happening. I read online about this, and wanted to try to understand why the SQLiteOpenHelper was dependent on an Activity.

Is there a way to just have open SQLiteDatabase object without the Helper and have it just exist within all activities?

View 10 Replies View Related

Android :: SQLiteOpenHelper - OnUpgrade

Sep 10, 2009

I get a SQLiteException if I try to issue an alter statement in the onUpgrade method of SQLiteOpenHelper subclass:

Can't upgrade read-only database from version X to Y: /path/to/db

That makes no sense at all! Where did I go wrong?

View 5 Replies View Related

Android :: Having Several SQLiteOpenhelper In One Appli?

Feb 11, 2010

I would like to know if it is possible to have several DbOpenHelper in the same app Android but to use them to write and read in the same database? because I'm trying to create tables from 2 different OpenHelper (with different names) and only the first one seems to create. when I try to run the 2nd one, i get an error...

View 1 Replies View Related

Android :: SQLiteOpenHelper OnUpgrade()

Aug 17, 2010

I am doing my first app with a database and I am having a little trouble understanding the onUpgrade function. My database has a table with an items and a favorite column so that the user can favorite an item. Most implementations I see simply drop the table and reconstruct it but I don't want to do this. I want to be able to add more items to the table.

When the app is upgraded through the android marketplace does the database know its version number? So could I increment the version number in the code and then export it to the marketplace and when the user boots up the upgraded version for the first time then onUpgrade will be called?

If this is the case my onUpgrade would simply pull from a file and add the database items in. Is this a standard way of doing things or is there a better way of handling this in Android. I am trying to stay as standard as possible.

View 1 Replies View Related

Android :: SQLiteOpenHelper Documentation Not Clear

Jul 9, 2010

The documentation does not make the interation between onUpgrade() and onCreate() clear.

When implementing onCreate() should this create the database at version 1, assuming that onUpgrade will apply all of the patches to bring it up to version x (lets say version 5 for example)? Or should onCreate build the latest version of the database, and onUpgrade is only used to upgrade legacy clients.

I kind of prefer the first, because it effectively means that the same SQL is executed for everybody. Whereas the second options means that there is a potential for onCreate to build something slightly different to the succession of patches built by onUpgrade.

I can always make onCreate call into onUpgrade, however, this is the kind of implementation detail that should go into the javadocs...

View 3 Replies View Related

Android :: SQLiteOpenHelper Without Or Less Restrictive Use Of Context?

May 21, 2010

If you extend SQLiteOpenHelper, for the Constructor you have to use a Context. I am wondering if there is a way to leave this out, and be able to work with database tables without a Context.

Or at least be least restrictive, I mean a way of project/class structure that will make history the several context passings I have to do now.

As it is my application has several level of classes, chained in each other, and there are a few that connects to the database, but have no whatsoever influence on the interface, so they don't actually need the Context.

Are you creating your classes in the way that you pass each time a Context to them?
If not, how you do, how you reuse a Context in a short class?

View 1 Replies View Related

Android :: Why Isn't SQLiteOpenHelper Called Just SQLiteHelper

Jun 11, 2010

The documentation describes the class as a helper object to create, open, and/or manage a database. Having that in mind wouldn't you say that the name is a little misleading?

View 2 Replies View Related

Android :: Why SQLiteOpenHelper.onUpgrade Fail?

Sep 13, 2010

Every time i increase my database version and push the upgraded app to the users, something weird happens.. For some it works perfectly fine, and some report crashes (including through the Market's reporting system) caused by the lack of table columns i just added in onUpgrade.

If you want to see the method:
http://code.google.com/p/tag-todo-list/source/browse/trunk/Donut/src/com/android/todo/data/ToDoDB.java#136

I can't spot any exceptions that appear in onUpgrade. What i'm currently doing to bypass these problems is intercepting the exceptions where the new fields are invoked for the first time and then calling onUpgrade 'manually', which is kind of dirty.

Also, the app sometimes generates a 'no such table' SQLiteException when accessing the main table (again, only for some users) which is incredibly strange... Does someone know why these things happen? Or can you spot something wrong in my code?

View 1 Replies View Related

Android :: SQLiteOpenHelper Existing Database?

Jun 9, 2010

I have an existing SQLite database file from another project.

Where do I include the database file into my Eclipse project to have it deploy with the app.

Do I need to indicate that the database file is writable? (In the iPhone world you need to copy the database file from the app's bundle to a writable folder on the iPhone proper before first use.)

Once I have the database file on the phone, how do I tell SQLiteOpenHelper to use it? (I extend SQLiteOpenHelper in a custom class.

View 1 Replies View Related

Android :: How To Emulate OnUpgrade Call In SQLiteOpenHelper

Oct 17, 2010

How can I emulate an onUpgrade call for my SQLiteOpenHelper class? I have tried changing the version number in my SQLiteOpenHelper class and versionCode in manifest but onUpgrade is not called. Any idea? I need to check my onUpgrade code before upload it to the market, I don't want my app's users get a buggy upgrade.

View 10 Replies View Related

Android :: Database In Application - SQLiteOpenHelper GetType?

Aug 24, 2010

I'm trying to implement a database in my application. I'm following a tutorial about writing my own ContentProvider, but I'm confused about SQLiteOpenHelper::getType. We're supposed to write it and, essentially, write a switch that returns the MIME type corresponding to the type of data we're dealing with.

I don't fully understand it. I'm not sure, even though I have an example, what is precisely supposed to be conveyed here. How do I determine the MIME type of my different tables of data?

View 1 Replies View Related

Android :: Calling GetSharedPreferences(); From SQLiteOpenHelper Class?

Feb 27, 2010

I have two classes, one MainClass and one DataBaseHelper class, which extends SQLiteOpenHelper.

From my MainClass I call a method in the DataBaseHelper class to open a data base. Before opening the data base I want to check the users data base version (this is important as soon as I want to update the data base and push it to the Android market). So from the DataBaseHelper class I call the following method, which is in the MainClass.

CODE:..........

I call the checkCurrentDbVersion() method from the DataBaseHelper class like so:

CODE:.....................

As soon as the debugger runs the following line, it stops.

CODE:...........

I have no constructor defined. Could that be the failure?

View 2 Replies View Related

Android :: SQLiteOpenHelper.getWriteableDatabase() Null Pointer Exception

Nov 16, 2009

I've had fine luck using SQLite with straight, direct SQL in Android, but this is the first time I'm wrapping a DB in a ContentProvider. I keep getting a null pointer exception when calling getWritableDatabase() or getReadableDatabase().

Is this just a stupid mistake I've made with initializations in my code or is there a bigger issue?

CODE:.........

But here's LogCat showing the exception:

View 2 Replies View Related

Android :: Android - Use One SQLiteOpenHelper Class For Multiple Database Files

Nov 20, 2010

My app uses two databases (separate files). To handle these databases I have created two Helper classes which extend SQLiteOpenHelper, one for each database.

I am now going to add a third database and wonder whether I need to create yet another Helper class (and if I used a 4th and a 5th database would I need even more Helper classes), or can I use the same Helper class for multiple databases?

The problem that I see with trying to use just one Helper class is that I can't see how to pass the name of the individual database files to the Helper. At present the name of the database is hard-coded as a Static field of each of the Helper classes, but if I had only one Helper class I would need to be able to pass the different names in to the Constructor when creating the separate Helper objects; the problem is that the SQLiteOpenHelper Constructor seems to be called by Android with just one parameter: the Context.

View 2 Replies View Related

Android :: Finalizing Cursor Android.database.sqlite.SQLite­Cursor

May 6, 2009

I am seeing the exception in 'adb logcat'.But I don't know if it is caused by my application or android platform.Can you please give me any idea how to troubleshoot this exception?

View 3 Replies View Related

Android :: Sqlite And SimpleCursorAdapter

Apr 1, 2010

I want to create a table whose primary key will be some other field and not _id . The below table gets created but the value of _id remains null :

"create table accounts ("+BaseColumns._ID+" integer , profile_name text primary key" +" name text not null);";

My doubt is wont _id get auto incremented if we do not place "+BaseColumns._ID integer primary key autoincrement+" .

View 3 Replies View Related

Android :: Using My Own SQLite Database

Feb 13, 2009

I'm new to Android, I just finished the Notepad Tutorials, where we can create SQLite Databases to save notes. So I wanted to know if it was possible to "import" my own SQLite database (not created with my App but with a 3rd-party software) to my project, and if the answer is yes, where should I save my SQLite databse and how can I have access to it.

View 9 Replies View Related

Android :: How To Use SQLite Functions?

Apr 1, 2009

I read in the documentation for SQLite that there should be some core functions and aggregate functions available, but I can't seem to use them in my code.. Can anyone help? Here's the documentation ad: http://www.sqlite.org/lang_aggfunc.html http://www.sqlite.org/lang_corefunc.html There is for example the function count() but how do I use it? I have tried to use it as stated below, but none of the functions in the documentation is available that way (i.e when I type "db." the list that shows in Eclipse documentation doesn't include any of the functions from the SQLite doc except from execSQL):
Code...

View 7 Replies View Related

Android :: Database - XML Or SQLite?

Mar 25, 2010

I'm doing a application that will use a database with serialized object. The objects will be already serialized and the user will just display things. On a PC I would just make an XML but with android I'm not sure. Can I make an XML and "unpack" it when the user launch the application for the first time or should I do something else?

View 3 Replies View Related

Android :: Use Own Sqlite Database?

Mar 5, 2010

I put my database field in "assets" folder. And use the code from this blog to copy the database to "/data/data/my_packname/databases/", (This copy code i run it in the onCreate() method when i run this app) then use select * from ... to get data. But it gives me the exception: no such table. Someone told me that if i am attempting to copy the file in SQLiteOpenHelper's onCreate(), it's too late. So the copy file code can not copy the complete file. So i need to use adb or ddms to pull the database first? So, Anyone can teach me how to use my own databse?

View 3 Replies View Related

Android :: SQLite And ListViews?

Nov 18, 2009

Firstly, I have found many examples of how to grab data from a db and place it into a list, however this seems to be all for ListActivites.

My list is part of the UI and therefore I can't use a ListActivity because it does not consume the whole screen (or can I?).

This is the UI:

CODE:........

So, from what ive read I need to grab the data from the db, then place it into some sort of array then use an array adapter to fill the list view. Is that correct? If so, is there some sample code because all I can find is code releated to ListActivites.

View 2 Replies View Related

Android :: How To Use SQLite DB From AsyncTask

Nov 24, 2010

I've been using my Activity class to access my DB which made my program freeze sometimes.

So I decided to use AsyncTask instead to handle the DB.

My problem is I don't know how to instantiate my SQLite DB "TheDB" from AsyncTask's class

CODE:.............

This worked fine on the Activity class, but it I dont know how to use it here

TheDB's constructor is TheDB(Context context) but this class is not a "context" so how can i use my DB here?

View 2 Replies View Related

Android : Way To Get Values From SQLite?

Jul 5, 2010

I wanna set a textview as the values from SQLite when I click the ListView Here is my way...

View 1 Replies View Related

Android :: Arraylist Storage In SQLite

Nov 16, 2009

Can any one tell me how to store and retrieve arraylist in/from sqlite.
ArrayList<Double> results = new ArrayList<Double>();

View 4 Replies View Related

Android :: SQLite Image Storing

Dec 17, 2009

i have the critical situation.i want to store the image in DB in android. but i don't know how to store image in db and how to get from db.i novice to android platform.so anyone give me the samplecode to develop my application.i tried more time but not i get the correct output.how to create the image field in SQLite db and how to insert the image within db.

View 2 Replies View Related

Android :: Use Sqlite In AsyncTask Freeze All

Jul 21, 2009

I execute this async task in my application, I don't understand why my progress dialog and all application freeze. Insert in doInBackground put one hundred or so entity in database.

In other case (but it's fisrt time with sqlite).

I use AsyncTask and I have no problem.

CODE:.................

View 3 Replies View Related

Android :: Using Sqlite In Native Code

Nov 22, 2010

I have a library written in C which implements some complicated algorithm over two databases and as a result produce new one. I am trying to import it in android using android-ndk. What is the correct wat to use sqlite in you native libraries, i was able to build the sqlite manually using the ndk but when i use it gives some strange errors when trying to fetch rows from db which is on phone storate - after i fetch some data i got SQL:database not opened. how can use sqlite in native code on android.

View 2 Replies View Related

Android :: How To Implement - Undo For SQLite DB Changes

Nov 1, 2010

I am trying to adapt my application from a confirmation model to an undo model. For those of you who don't know, this is where you can delete something with one click but if it was a mistake you can undo it just as easily, as opposed to interrupting the user every time he/she wants to do something to ask the annoying "Are you sure you want to...?" question via dialog.

My app is backed by the Android SQLite DB and I want to be able to undo a limited set of delete and update operations. Also, I only need to be able to undo one sequential change and the information does not have to stick arround for very long.

Everything I read on undo/redo says to use a command model to store the data. My question is how can I store the database changes in a lightweight restorable way?

View 1 Replies View Related

Android :: How To Add Objects To Sqlite Database?

Nov 18, 2009

I have a class like class My data{ String name; int data; Location[] locality.

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved