Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

sqlite

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.

like image 494
WASEEM A Avatar asked Dec 02 '25 06:12

WASEEM A


1 Answers

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, ...);
like image 89
Loc Avatar answered Dec 03 '25 22:12

Loc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!