0

I want to save image in my database and retrieve it when i need them, i have tried all solutions which i get through searching

[database executeQuery:
@"INSERT INTO customerPresImage (cbFormFK, imageName, imagePath, imageData) VALUES (?, ?, ?, ?)", 
cbFormPK, 
[[AllFormFields sharedManager].nameSaved objectAtIndex:i],
[[AllFormFields sharedManager].images objectAtIndex:i], 
[[AllFormFields sharedManager].actualImageData objectAtIndex:i]
];

[[AllFormFields sharedManager] actualImageData]

contains NSData object but when ever i try to execute my app got stuck at this point:

enter image description here

i have also tried to making that object archived but logically this doesnt make sense because i already have nsdata object in my array

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[[AllFormFields sharedManager].actualImageData objectAtIndex:i]];

P.S: I am using blob data type in sqlite. Please suggest me correction or if there is another way to get it done.

i have seen and acted upon these questions Question1

Question2

Community
  • 1
  • 1
MQ.
  • 365
  • 6
  • 28
  • the screenshot implies you have a memory management problem and try to access a pointer/variable not available anymore – Volker Apr 18 '15 at 07:35
  • but why it succeed when i remove column names and execute it. but nsdata object does not save in it – MQ. Apr 18 '15 at 07:40

1 Answers1

0

Use

[database executeUpdate:… ] instead of
[database executeQuery :… ].


See Executing Updates at the FMDB Website. Here is the first line:

Any sort of SQL statement which is not a SELECT statement qualifies as an update.

  • Did that not good for me. Although i had sought out the way but this saving of image data isn't working for me idk why. – MQ. Apr 19 '15 at 11:35
  • Do some error checking. If you don't know how: read the part about executing updates @ the FMDB Website, it's described there. Make sure the objects you're trying to insert are valid, non-nil objects. I think it can fail when an object is nil. –  Apr 19 '15 at 12:47