tags:

views:

111

answers:

1

Hi... I have few queries on Android SQLiteDatabase

1.) As normally the database stored in internal memory, can we specify the path of external storage and use it in similar way ? 2.) How to determine the size of available space of database ? I used getMaximumSize() from SQLIteDatabase class but that gives me 1099511626752 Is this in bytes ? If assumed then this seems to be too large and not practical. I am using HTC G1 to test this. 3.) How can I determine the size of an entry in table ? Or do I have to pull the whole table and manually see its size. Is it same that would be in phone storage ? 4.) Can I check if any free space available before making entry in database ? I want to prevent SQLiteFullException.

Thanks.

+1  A: 

As normally the database stored in internal memory, can we specify the path of external storage and use it in similar way

As I understand it, yes, though you will not be able to use SQLiteOpenHelper.

How to determine the size of available space of database ? I used getMaximumSize() from SQLIteDatabase class but that gives me 1099511626752 Is this in bytes ? If assumed then this seems to be too large and not practical. I am using HTC G1 to test this.

I expect that it would be the smaller of getMaximumSize() and the amount of free space available wherever you have the database stored.

How can I determine the size of an entry in table ?

I have no idea what "an entry" is, let alone how to compute its size.

Can I check if any free space available before making entry in database ?

Not easily, AFAICT. Android does not have the getFreeSpace() method on File.

CommonsWare
Thanks for the answer. But how do I calculate amount of free space that my application can use for database growth ?
mob_king
@mob-king: Ah, I found it -- use `android.os.StatFS`.
CommonsWare
By entry I mean database row , or we can consider whole database. I want rough idea of how much space it occupies in android storage. Is it same if I pull it to PC and see its size ? Also pulling database from device gives permission denied. So that won't work except from emulator or rooted device.
mob_king
@CommonsWare Thanks for the link android.os.StatFS. But would need some reference for how to use it in practice for it would be in reference to UNIX filesystem which is quite different as read long back in book "The Design of the Unix Operating System - Maurice J. Bach". :)
mob_king
@mob-king: "I want rough idea of how much space it occupies in android storage." -- this is covered in the SQLite documentation on sqlite.org, AFAIK. "Is it same if I pull it to PC and see its size ?" -- the actual size should be the same. "Also pulling database from device gives permission denied. So that won't work except from emulator or rooted device." -- correct. "But would need some reference for how to use it in practice" -- use a search engine to find sample code for use of `StatFS`.
CommonsWare
@CommonsWare Thanks for your help.
mob_king