简体   繁体   中英

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, ...);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM