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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:55:48+00:00 2026-05-28T01:55:48+00:00

I m trying to store and retrieve image and text from sqlite database..My saveDatabase

  • 0

I m trying to store and retrieve image and text from sqlite database..My saveDatabase coding is working correct..but i dont whether it is saved in my database..Here is my code for that..

    sqlite3 *database;
    dbName=@"dataTable.sqlite";
    NSArray *documentpath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentdir=[documentpath objectAtIndex:0];
    dbPath=[documentdir stringByAppendingPathComponent:dbName];
    sqlite3_stmt *compiledStmt;
   if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK){
        NSLog(@"Name:%@,Company:%@,URL:%@",model.personName,model.companyName,model.imgurl);
//        NSString *sqlStatement=[NSString stringWithFormat:@"insert or ignore into Persons(PersonName,CompanyName,ImgUrl)values(\"%@\",\"%@\",\"%@\")",model.personName,model.companyName,model.imgurl];
//           const char *insertSQL=[sqlStatement UTF8String];

       const char *insertSQL="insert or ignore into Persons(PersonName,CompanyName,ImgUrl,UserImage)values(?,?,?,?)";
       sqlite3_bind_text(compiledStmt,1,[model.personName UTF8String],-1,SQLITE_TRANSIENT);
       sqlite3_bind_text(compiledStmt,2,[model.companyName UTF8String],-1,SQLITE_TRANSIENT);
       sqlite3_bind_text(compiledStmt,3,[model.imgurl UTF8String],-1,SQLITE_TRANSIENT);
       NSData *imageData=UIImagePNGRepresentation(imageView.image);
       sqlite3_bind_blob(compiledStmt, 4, [imageData bytes], [imageData length], NULL);
    if(sqlite3_prepare_v2(database,insertSQL, -1, &compiledStmt, NULL)==SQLITE_OK){
        sqlite3_step(compiledStmt);

//    char *errMsg;
//        sqlite3_exec(database, insertSQL, NULL,compiledStmt,&errMsg);
        NSLog(@"Add to Favourites");

When i m trying to retrieve my database i m getting error..

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'

This is my code for reading database..

    sqlite3 *database;

    favArray=[[NSMutableArray alloc]init];
    if(sqlite3_open([dbPath UTF8String],&database)==SQLITE_OK)
    {
        const char *sqlStatement="select * from Persons";
        sqlite3_stmt *compiledStatement;

        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)==SQLITE_OK)
        {
            while (sqlite3_step(compiledStatement)==SQLITE_ROW) 
            {
                int personId = sqlite3_column_int(compiledStatement,0);

                NSString *personName=[NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 1)];

                NSString *companyName=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];

                NSString *imgurl=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
                int length = sqlite3_column_bytes(compiledStatement, 4);
//                NSData *data       = [NSData dataWithBytes:sqlite3_column_blob(compiledStatement, 4) length:length];
                NSString *imageString=[NSString stringWithCharacters:sqlite3_column_blob(compiledStatement, 4) length:length];
                UIImage *personImage=[UIImage imageNamed:imageString];

                Favourites *favourites=[[Favourites alloc]initWithPersonId:personId personName:personName companyName:companyName imgurl:imgurl personImage:personImage];
                [favArray addObject:favourites];
            }
        }sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database);

I think i m doing something wrong in reading database by wrong way of accessing data.. anyone help me to get an image from database…

  • 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-05-28T01:55:49+00:00Added an answer on May 28, 2026 at 1:55 am

    Finally i found which place i m having a problem…First i checked the data is stored in my simlator database..its not stored.so i found there was a problem in my insert coding…it is that I m binding data before the prepare statement…The answer i found out is..

    if(sqlite3_prepare_v2(database,insertSQL, -1, &compiledStmt, NULL)==SQLITE_OK){
    
    sqlite3_bind_text(compiledStmt,1,[model.personName UTF8String],-1,SQLITE_TRANSIENT);
           sqlite3_bind_text(compiledStmt,2,[model.companyName UTF8String],-1,SQLITE_TRANSIENT);
           sqlite3_bind_text(compiledStmt,3,[model.imgurl UTF8String],-1,SQLITE_TRANSIENT);
           NSData *imageData=UIImagePNGRepresentation(imageView.image);
           sqlite3_bind_blob(compiledStmt, 4, [imageData bytes], [imageData length], NULL);
    
    sqlite3_step(compiledStmt);
    
    //    char *errMsg;
    //        sqlite3_exec(database, insertSQL, NULL,compiledStmt,&errMsg);
            NSLog(@"Add to Favourites");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve image from database and store it to a folder. Once
I'm trying to store GPS data in a Sqlite database. I retrieve the data
I am trying to retrieve an image that is stored in a database.. I
I am trying to store a null value into the database but everytime I
I am using trying to use scifihifi-iphone (from Github) to store and retrieve usernames
I am trying to retrieve OrdImage object from Oracle database using selection over dual
I am trying to store/retrieve a value that is stored in the Application Settings.
I'm trying to store a password in a file that I'd like to retrieve
I'm trying to store an xml serialized object in a cookie, but i get
I'm trying to store a lightly filtered copy of a database for offline reference,

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.