Insert a PDF file into Core Data? - iphone

I'm using my app to import some PDF files.
But I'm trying to insert my PDF file int my database. I'm using Core Data. Is it possible to do this ? If it is, how can I do it ? Which kind of types I have to use (NSData, NSDocument, ... ?)
Thanks you so much! :)

To store a PDF (or really any big data blob):
Use the Core Data "binary" type for the attribute, which corresponds to NSData.
In your Core Data model, turn on "Allows External Storage" for the attribute so that Core Data can store the data outside of the persistent store.
It's often better to just write the PDF to a file, and store the filename in your persistent store instead of the whole file.

Usually for large files, i.e large images or pdf files, what you should save in core data is simply a reference to the file, and store the pdf in NSCachesDirectory or in a permanent directory, depending on your needs.
Hope that helps.

Related

Store .sav file into RDBMS including meta data

I want to know what is the best approach to store the data from .sav file into RDBMS database with out loosing any meta data model as well as actual response data.
Note first that you can save all the metadata in a sav file where you have deleted all the data and then reapply the metadata to a new, similar sav file using APPLY DICTIONARY.
Otherwise, you would need to create tables in the database for the various attributes. That's easy for variable labels, formats, measurement level, and missing value codes. For value labels it would take a bit more work.
One possible approach would be to use OMS to capture the output from CODEBOOK (without any statistics) as data files and then export those files to the database.

Is saving data in SQLite as BLOB, a good programming practice?

Currently I am working with the project in which I need to parse complex XML, which contains multilevel details (Name & Paths for PDFs, PNGs, etc) at each node.
I need to store all the data in local memory of iPhone/iPad.
Should I create classes for each of those details and make appropriate tables in SQLite or store the data as BLOB and retrieve all the data all the time?
Any Suggestions, thoughts are most welcome...
EDIT:
I am storing Files in DocumentsDirectory and path to SQLite database. Question is to create well defined database tables or to store data in BLOB form.
Pros and Cons for both approach would be much appreciated. Thanks.
in my opinion you should simply use BLOB : when you startup your app load you'r xml into an object all changes will be made to that object so you can win the time to rewrite back to disk
on exit application save all to disk..
Using of BLOB is not a good process .Store all pdf and images in Document directory..store that path only in DB...

How to convert sqlite data into xml file and xml file into sql data?

I am developing an application. In that I want to create an XML file with sqlite data and place another XML data into sqlite field. So please tell me how to do this.
Well hope you used Core Data to interact with your DB.
If you did so, just loop your Entities and use a NSMutableString to build your XML document.

Storing UIImage in Core Data with the new External Storage flag

I know that the storing of UIImage's in core data has been discussed a lot, such as here, but that was pre-ios5. Now that we have the external storage flag, do you guys think it would be a fine idea to store UIImage's directly in the entity, as a separate entity, or still on the disk?
Here is a source explaining the external storage option.
Core Data Release Notes for iOS 5.0
When enabled, Core Data heuristically decides on a per-value basis if
it should save the data directly in the database or store a URI to a
separate file which it manages for you. You cannot query based on the
contents of a binary data property if you use this option.
And from your link External Binary Data, the heuristic seems to be
Objects that are smaller than 1MB are stored in the database. For
objects that are larger, an external file is created and the database
just stores a reference to it.
So the following advice is still valid: CoreData : store images to DB or not?
< 100kb store in the same table as the relevant data
< 1mb store in a separate table attached via a relationship to avoid loading unnecessarily
1mb store on disk and reference it inside of Core Data
The flag sets Core Data to follow that advice and automatically store images >1MB as a separate disk file.

Import data from Excel File to Core Data

I have thousands of students records in Excel sheet. Now I will import that all data into Coradata [from Excel sheet to Coredata] and I will create my iPhone application using that coredata.
I don't have any idea, how to import Excel file data into coredata.
You're thinking to broadly. You need to decompose this problem further. Here's your real problem:
How do I read an Excel file into memory?
How do I create Core Data objects?
"Excel" has nothing to do with "Core Data". They are entirely disjoint topics.
For the first question, there are several options. You could try and find a library that reads .xls or .xlsx files directly, or you could require that the file be in a different format (like CSV or something).
For the second question, that's easily answered by reading the Core Data documentation.
I would convert the file to xml.
There are plenty of codes showing how to parse xml.