Reputation: 103
Actually, I want to download a PDF file in our Android phone and don't want to give the permission to open the PDF file in PC when he try to open by connecting the Phone to PC. so I want to go with storing the PDF file in SQLite Data Base solution.
My question is...
Is it possible to store PDF file in SQLite database? If yes, how?
Or is there any other way to implement same functionality?
Please Help me...
Thanks...
Upvotes: 1
Views: 8087
Reputation: 8142
One solution is to use blob and to store the raw data of the file as column in the db.
Other solution which i think is better to store the files on the Internal Storage and in the db just to store the file paths. Internal storage is private for your application so no one will have access to the files. But be careful in both cases the files are stored on the phone storage and people can find themselves in situation when there is no more phone storage.
Upvotes: 2
Reputation: 544
You can use a BLOB datatype to store a PDF file in the database but that wouldnt be my suggestion since you are using SQLlite tough its possible. Some people say it's a dirty way to store binary files in a database. Large databases will result in slower queries.
My solution would be to store a PDF file in a directory and use a string pointer to the file name. This will result in faster queries and a smaller database. Only downside is that you have to write functionality to rename duplicate entries and delete files from the file system when you delete an entry.
Please comment if (large) binary files in databases make the database slower...
Upvotes: 0
Reputation: 1267
AFAIK Sqlite support the BLOB datatype, I used BLOB for store images into MySql databases, I think you can do the same thing reading the file content and storing that into a BLOB column in SQLite
Upvotes: 0
Reputation: 43108
You can. Simply read all the bytes of the pdf file and store in the blob field of sqlite db.
Upvotes: 2