Using text file in SQLite - android

I am dealing with ECG signal processing using Android phone. I am getting the filtered ECG signal after the series of operations as my final output, and it is saved in text file in particular location. The text file contains the values of voltages in a single column, containing 30000 samples. This is done for number of patients.
Now I have to use these text files in my database with particular patients, as a entry in their row.
I am using SQLite database.
How can it be done?
please help me with this.

Read the file and save it as blob in sqlite, but if data is too large, you will have problems with size. Another way would b to keep the files in sdcard with some id as filename, you could save these ids in db which you can refer.

OK basically what you need to do is:
bulkinsert your data.
here is the link on how to do it:
http://notes.theorbis.net/2010/02/batch-insert-to-sqlite-on-android.html
if you need to populate your second table with this data then
update yourtable set blah=(select field from yourfreshlypopulatedtable)

Related

Adding data to database from program. Android

I faced with the following situation. In my program I have to keep files in database. This database contains title of the article which keeps file and path to the file. All files are kept in Assets folder and are created manually. But what if I want to add files from the program itself. For example to create a special edittexts where user can write title and articles. How can I keep this data? I understand how to add title,entered by user,to database,it's easy. But what about the articles. I can't place them with file which were created manually,as Assets can't keep such files. I thought to add all full articles to database,but how can I add asset's files in such case?
Files (images, PDF'd. Word documents .........) are not structured data and serve little purpose being stored in the database (Full Text Search (FTS) an extension for SQLite is a different matter).
The recommended technique is to store some reference to the file (e.g. full path or perhaps file name (if all files are stored at a location that is discernible by the file name)) in the database. So when you locate/search and obtain a row you then use the file itself.
However, if the files average around about 100k or less then SQLite can actual be faster and thus it may performance wise, be better to store the files in the database.
Note the 100k based upon the link below.
35% Faster Than The Filesystem
You would store files as BLOB's (byte arrays). You read them into a byte array and on Android, assuming java and that the byte array is named my_byte_array and that the SQLiteDatabase is db then :-
ContentValues cv = new Contentvalues();
cv.put("FILE_COLUMN",my_byte_array);
........ other cv.put's for the other columns
long inserted_id = db.insert("The_Table",null,cv);
if (inserted_id < 1) {
.... code to handle row not inserted.
} else {
.... code to handle row inserted OK
}
WARNING
Files greater than 2M will be impossible to easily retrieve as a Cursor Window is limited to 2M of memory. Even 1M may well cause issues and may be unusable at some stage if the App needs to be backwardly compatible as I believe that Cursor window's were restricted to 1M (not sure when).
Retrieval from the database
To retrieve data from a BLOB you use the Cursor getBlob(column_offset) method, or generally better use the Cursor getColumnIndex(column_name) method to retrieve the column offset according to the column name. So if the Cursor is named csr then** my_other_byte_array = csr.getBlob(csr.getColumnIndex(column_name));**
Noting that you have to move to a valid row before using the getBlob method.

How to add a very large amount of data in my Android app?

OVERVIEW:
I have a database that contains more than 128,000 records, and each record contains about 12 columns (8 string columns with lengths of about 1-2 words each column, and 4 columns containing reference or indices of 4 images respectively).
GOAL:
What I want basically is that when the user chooses a chapter contained in a spinner, the app shall retrieve the data relevant to the chapter chosen and display it on the screen (this is oversimplification though).
WHAT I DID but FAILED:
Creating a class for each column. (This taught me, in the hard way, the 64KB limit thing in Java.)
Creating an XML resource file for each column. (Failed because apparently, there's a limited number of ID, in effect resources, in an app)
WHAT I'M PLANNING TO (LEARN AND) DO:
Create an SQLite Database. (But I worry how would I prepopulate it with my data? Wouldn't this lead to the 64KB limit error?)
Create a text file for each column and store them as raw resources then retrieve them using input stream. (I, TBH, don't know what I'm talking about here. I picked this up while reading some sites yesterday).
So, what should I do?
(MORE DETAILS):
My app has a spinner containing 114 chapter titles
When the user chooses a chapter, the verses of the chapter will be displayed in the screen.
Each token (or say, word) of each verse is clickable.
Each token (including its details) represents one record in the database.
When the user clicks the token, the details about it will be displayed.
The details consist of 8 string columns, and 4 columns containing reference to the 4 images (image of a page of a dictionary).
The total aggregate size of the images is about 90 MB.
First of all you have to create Datebase from Server Side and you have to manage same Database from Android Side like SQLite.
When your application load first time, you have to copy all the data from server in chunks.(Manage OutOfMemoryError)
then you can use all the data from SQLite so it will work speedy.
After all you have to sync do sync process as i have mentioned here.
Thanks you.

How to store and fetch large text data from SQLite database?

I am working on an android project. Its a tutorials app in which I am providing 100 chapters. But I am not getting exactly how to store these chapters in my app's local database and how to fetch it on button click. I want to provide the facility on button click the next activity must be opened and the contents of the chapters must be loaded on that activity.
For Example. If I click on Button "Chapter 1" then 1st chapter must be loaded from SQlite database.
I have followed lots of tutorials but I am not satisfied. Please Somebody Help Me.
You have 2 choices:
TEXT type - SQLite supports very long text.
Source: http://www.sqlite.org/faq.html#q9
SQLite will be happy to store a 500-million character string there
BLOB type: If you don't want to use TEXT, you can use BLOB instead ( You need to convert the large text to a byte array when inserting/updating, and convert the byte array to back to the large text back later)
For database design. You can do like this:
- Book table ( _id, name, ...)
- Chapter table (_id, content (TEXT,BLOB), book_id, chapter_number, ...);

I would like to create a database containing 600 text files for an android Application

I have 600+ text files. How do I put them in a database, with mySQL lite.
I want to have 3 columns: index(1 to 600), title and content.
How do I do that? Thanks.
http://www.sqlite.org/datatype3.html
When you create the database (the single table in it), the index should be auto-generated when the entry is created in the table (if you properly created the table with auto indexing)
I would use TEXT (varchar) for the title & blob for the actual text file (the data in it).
The previous answer seems to put you on the right track, though I'm not sure I quite understand how you intend to actually populate the table with the data.
Use content provider for android below is nice link.
http://www.vogella.com/tutorials/AndroidSQLite/article.html.
For datatype to use integer,text,text as columns, below is
datatype link of sqlite.
http://www.sqlite.org/datatype3.html
But Instead of storing the file data in sqlite, I would suggest you to store sdcard path of files in sqlite table and retreive from sdcard when required.
In above case columns will be index,title,filepath.

Without replacing previous columns and values/data how to insert values/data in csv fromat in android?

Is there any way, without replacing previous columns and values/data how to insert values/data in csv format in android?.Let me explain in brief what I actually want, I want to create a excel sheet in android for that I am saving the data in csv format because "if I am right saving in csv produce the same output as in excel", But the problem is that whenever I insert the a new data my previous columns and values/data get replaced, which should not to be actually. So any HELP will really be appreciated THANKS A LOT.
Set the append flag to true when doing your file write.

Categories

Resources