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, ...);
Related
I am new to Android Studio and Java. In my app I have 2 SQLitedb's; one with general info like titles, subtitles, images etc (spotsDb). The other one I use to store Favorites (favDB; with only titles). Because the Favorites have to stay when I update app and the general info, there are 2 databases.
But I want to set the value of the key "favorite" to "yes" in the general db when the title exists in the favorites db. How can I do that? Is there an sqlite command for this just like you can check arrays or maps with contains(...)?
ATTACH one database to the other, and then just look up the titles:
UPDATE main.MyTable
SET favorite = 1
WHERE title IN (SELECT title
FROM favorites.OtherTable);
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.
I put my data in 3 tables(Links, Images and PDF)
each table has columns(university, faculty, grade, and description,...)
I want to retrieve description column in the 3 tables.
where university, faculty, and grade equal to certain values.
and sort them with creation date.
how can I perform that query in parse?
I'm not familiar with Android, but I'm pretty sure Parse does not support "Join" in the way a SQL database does. You could nest the queries, performing the next one in the previous one's completion block.
However, if you regularly want to get data from those 3 tables, I'd suggest you make it 1 table instead, with a column "Content" instead of Link/Img/PDF. Images and PDFs would probably be stored as PFFiles anyway, and you can put link as either its own string column or putting it in a file. You could also add a column "type" if you want to be able to query a specific type, or just keep track of which columns contains which data.
Then you could query the "Content" class, on the keys you want.
I think this link might help you
https://parse.com/docs/js/guide#relations and it is quite simple and nicely explained . You can't do it directly in the database, though.
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.
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)