Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:43:15+00:00 2026-06-07T08:43:15+00:00

I am saving some images to a SQLite database in my app. I accessed

  • 0

I am saving some images to a SQLite database in my app. I accessed the database with a graphical SQLite client and it is saving the binary of my images correctly. The problem is on retrieving it from the database.
This is whats it looks like:

Save

-(void)insertObject:(Object *)object
{
    const char* sqliteQuery = "INSERT INTO OBJECTS (OBJECTID, OBJECTIMAGE, OBJECTNAME) VALUES (?,?,?)";

sqlite3_stmt* statement;

if( sqlite3_prepare_v2(databaseHandle, sqliteQuery, -1, &statement, NULL) == SQLITE_OK )

{

    sqlite3_bind_text(statement, 1, [object.id UTF8String], -1, SQLITE_TRANSIENT);

    sqlite3_bind_blob(statement, 2, [object.imgData bytes], [object.imgData length], SQLITE_STATIC);

    sqlite3_bind_text(statement, 3, [object.name UTF8String], -1, SQLITE_TRANSIENT);

    sqlite3_step(statement);

}

else NSLog( @"SaveBody: Failed from sqlite3_prepare_v2. Error is:  %s", sqlite3_errmsg(databaseHandle) );

sqlite3_finalize(statement);
}

Retrieve

-(Object *)retrieveObjectWithID:(NSString*)id
{

NSString* sqliteQuery = [NSString stringWithFormat:@"SELECT OBJECTIMAGE,OBJECTNAME FROM OBJECTS WHERE OBJECTID = '%@'", id];    
NSLog(@"sqlitequery: %@",sqliteQuery);
sqlite3_stmt* statement;

Object *object = [[Object alloc]init];

object.id = id;

if( sqlite3_prepare_v2(databaseHandle, [sqliteQuery UTF8String], -1, &statement, NULL) == SQLITE_OK )

{

    if( sqlite3_step(statement) == SQLITE_ROW )

    {

        NSUInteger length = sqlite3_column_bytes(statement, 1);

        object.imgData  = [NSData dataWithBytes:sqlite3_column_blob(statement, 1) length:length];
        object.name = [NSString stringWithFormat:@"%s",sqlite3_column_text(statement, 2)];

    }

}


// Finalize and close database.

sqlite3_finalize(statement);


return object;
}

this is the Object

@interface Object : NSObject


@property(nonatomic,strong) NSString *id;
@property(nonatomic,strong) NSString *name;
@property(nonatomic,strong) NSData *imgData;

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:43:21+00:00Added an answer on June 7, 2026 at 8:43 am

    Please check the following code,

    NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 0) length:sqlite3_column_bytes(statement, 0)];
    
    object.imgData = data;
    

    instead of,

    NSUInteger length = sqlite3_column_bytes(statement, 1);
    
            object.imgData  = [NSData dataWithBytes:sqlite3_column_blob(statement, 1) length:length];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app is saving some images on the SD Card, in the AppImages directory
I have this kind of problem where I want to download some images that
I am saving some images in to the documents directory of the app using
What I'm trying to do is to paste some images from my app in
I have some jpg images I am saving to the documents directory from camera
currently i'm trying to use imagick to generate some images without saving them on
I am saving some pictures on the SD card in this way: File dir
I have a action class for saving some data to a database.In action class
I'm getting some data from the web service and saving it in the core
I have a DataSet with some Datatables and I am saving this DataSet as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.