Can we store .doc .pdf and .jpg files in SQLite Database (Android)?
Asked Answered
G

3

20

Is it possible to store files like pdf doc in SQLite db and the retrieve them again successfully.the files must be intact and readable again.I know we can store image files but for the above??.

Even if we can store what will be the given max file size??

Grosgrain answered 12/3, 2015 at 11:36 Comment(2)
no, SQLite is supposed to be embedded database to save minimum data that's allSolvolysis
Yeah I know its not recommended to save files in a SQLite db but the scenario is to store highly confidential files in the user's mobile then retrieve it back.the files are really small . So the plan is to create a crypted SQLite db and store the docs temporarily .Grosgrain
N
20

Yes, go ahead. It is easier to store every file in the database, than just using the database to keep track of where each file is.

If the files are small, performance should be fine. From the SQLite website:

... many developers are surprised to learn that SQLite can read and write smaller BLOBs (less than about 100KB in size) from its database faster than those same blobs can be read or written as separate files from the filesystem. (See 35% Faster Than The Filesystem and Internal Versus External BLOBs for further information.) There is overhead associated with operating a relational database engine, however one should not assume that direct file I/O is faster than SQLite database I/O, as often it is not.

Napalm answered 28/8, 2017 at 6:19 Comment(0)
M
13

I know we can store image files but for the above?

From the standpoint of SQLite, an image is no different than any other type of file. You are welcome to store file contents in a BLOB column. This may not be very efficient.

Even if we can store what will be the given max file size?

The limit of a SQLite database is something like 2TB. Your Android device will not have that much storage space.

Merryman answered 12/3, 2015 at 11:42 Comment(1)
Thanks for the answer CommonsWare ...Stored the files in DB successfully .now have to check for libraries to display the .doc and .pdf files to the user within the app.Grosgrain
P
0

SQLite is a liteweight component. Instead of storing files like .pdf and .doc in SQLite,store them in internal storage and get the path in internal storage and now store that in SQLite as a string.

Pardner answered 9/7, 2016 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.