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 8693187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:29:29+00:00 2026-06-13T00:29:29+00:00

Hi All I’m New to Xcode I’m trying to insert image from UITableView to

  • 0

Hi All I’m New to Xcode I’m trying to insert image from UITableView to database(sqlite3) in ios 5
i tried below code

-(void)addItemCUR
{

    if(addStmt == nil) {
        const char *sql = "insert into Table(C_Name, C_Image) Values(?,?)";
        if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
            NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
    }

    sqlite3_bind_text(addStmt, 1, [C_Name UTF8String], -1, SQLITE_TRANSIENT);

    NSData *ImageData = [[NSData alloc] initWithData:UIImagePNGRepresentation(self.C_Image)];
    int returnValue = -1;
    if(self.C_Image != nil)
       returnValue =        sqlite3_bind_blob(addStmt, 3, [ImageData bytes], [ImageData length], NULL);
    else
        returnValue =         sqlite3_bind_blob(addStmt, 4, nil, -1, NULL);



    if(SQLITE_DONE != sqlite3_step(addStmt))
        NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
    else
        //SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
        rowid = sqlite3_last_insert_rowid(database);

    //Reset the add statement.
    sqlite3_reset(addStmt);
}

I’m getting Error like

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString CGImage]: unrecognized selector sent to instance 0xb7c0'
*** First throw call stack:
(0x158f052 0x1720d0a 0x1590ced 0x14f5f00 0x14f5ce2 0xf8b6c 0x5c65 0x3182 0x7030 0x16d71d 0x16d952 0x9f586d 0x1563966 0x1563407 0x14c67c0 0x14c5db4 0x14c5ccb 0x1478879 0x147893e 0xdda9b 0x2ac8 0x2a25)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
(gdb

Please any one help me to get through this thanks in advance.

  • 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-13T00:29:30+00:00Added an answer on June 13, 2026 at 12:29 am

    Try to store the images in local document directory.Then store the image path in sqlite.Following code will help you.

    NSData *imageData = UIImagePNGRepresentation(photo);//photo - your image
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *pngFilePath = [NSString stringWithFormat:@"%@/photo.png",documentsDir]; 
    [imageData writeToFile:pngFilePath atomically:YES];
    
    NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
    NSString *docDirectory = [sysPaths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/photo.png", docDirectory];
    
    sqlite3 *database;
    @try 
    {
        NSString *query = [NSString stringWithFormat:@"INSERT INTO Photos(PhotoPath) VALUES('%@')",filePath];
        NSString *databasePath;
        NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDir = [documentPaths objectAtIndex:0];
        databasePath = [documentsDir stringByAppendingPathComponent:@"GolfElite.sqlite"];
        if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)    
        {
            NSLog(@"DB opened...");
            sqlite3_exec(database, [query UTF8String], NULL, NULL, NULL);   
        }
    
    }
    @catch (NSException * e) 
    {
        NSLog(@"Exception = %@", e);
    }
    @finally
    {
        sqlite3_close(database);
    }
    NSLog(@"Photos inserted successfully..");   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All I want to do is to insert Null with the database when the
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
All, See the code below: function menu() { this.menuitem=[]; this.submenu=[]; this.menuitem[0] = $('div#sivname1'); this.menuitem[1]
All, I'm inserting some text from a textarea in a mySQL database. I'm using
All, In Apple's sample code DateCell http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html the ivar pickerView is declared in MyTableViewController.h
All is in the question. I have an image saved in database in an
All, I am trying to bulk insert some data in a table using the
All, I have a controller which saved the posted file(Please review below code). It
All, If I run a query like the following: $qry = Select wrong_column from
All, If I've go the following database fields/values: user_id field_name field_value 1 EventHour1 1

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.