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

  • Home
  • SEARCH
  • 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 9264089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:44:22+00:00 2026-06-18T13:44:22+00:00

I have an app that reads from sqlite database,data is read and included in

  • 0

I have an app that reads from sqlite database,data is read and included in the objects using this method ….I checked with NSLog

#import "ViewController1.h"
#import "Ricetta.h"
#import "AppDelegate.h"


static sqlite3_stmt *leggiStatement = nil;

@interface ViewController1 ()

@end

@implementation ViewController1

@synthesize Webmain, oggetto2;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization



    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    //percorso file su cartella documents
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *path = [documentsDir stringByAppendingPathComponent:@"Rice.sqlite"];

    //controllo se il file esiste
    if(![[NSFileManager defaultManager] fileExistsAtPath:path])
    {
        //se non esiste lo copio nella cartella documenti
        NSString *pathLocale=[[NSBundle mainBundle] pathForResource:@"Rice" ofType:@"sqlite"];
        if ([[NSFileManager defaultManager] copyItemAtPath:pathLocale toPath:path error:nil] == YES)
        {
            NSLog(@"copia eseguita");
        }       
    }





    [self personalizzaAspetto];


    [self carica_ID];




   // NSString * query = @" SELECT Immagine, Titolo, Descrizione FROM LIBRO";
   // NSArray * arrayQuery = [[NSArray alloc] initWithObjects:@"Immagine",@"Titolo",@"Descrizione",nil];
   // NSArray * arrayElementi = [self caricaValoriMain:query :arrayQuery];




        Webmain= [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 365)];
        NSString *htmlString =[NSString stringWithFormat:@"<html> \n"
                               "<head> \n"
                               "<style type=\"text/css\"> \n"
                               "body {font-family: \"%@\"; font-size: %@;}\n"
                               "</style> \n"
                               "</head> \n"
                               "<body><center><img src='%@'/></center></body><center><h1>%@</h1></center><body bgcolor=\"#FFFFFF\" text=\" #ffa500\">%@</body></html>" ,@"futura",[NSNumber numberWithInt:15],oggetto2.Immagine,oggetto2.Titolo,oggetto2.Descrizione];

        [Webmain loadHTMLString:htmlString baseURL:nil];

        [self.view addSubview:Webmain];







-(void)carica_ID{




      sqlite3 *database = NULL;

      NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDir = [documentPaths objectAtIndex:0];
      NSString *dbPath = [documentsDir stringByAppendingPathComponent:@"Rice.sqlite"];

    if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
    {
        if(leggiStatement==nil){
        const char *sql = "select Immagine,Titolo,Descrizione from LIBRO WHERE RicettaID=1";

        if(sqlite3_prepare_v2(database, sql, -1, &leggiStatement, NULL) != SQLITE_OK)
           NSAssert1(0, @"Errore creazione compiledState '%s'", sqlite3_errmsg(database));

            }


            //while(sqlite3_step(leggiStatement) == SQLITE_ROW)
            if(SQLITE_DONE != sqlite3_step(leggiStatement))
            {




                NSString *titolo = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(leggiStatement, 1)];
                NSLog(@"%@",titolo);
                oggetto2.Titolo=titolo;

                NSString *descrizione = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(leggiStatement, 2)];
                NSLog(@"%@",descrizione);
                oggetto2.Descrizione = descrizione;

                NSString *image= [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(leggiStatement, 0)];
                NSLog(@"%@",image);
                oggetto2.Immagine= image;



        }

        sqlite3_finalize(leggiStatement);
    }

 sqlite3_close(database);

}



@end

My problem is that I can not put them in webMain…objects in webMain remain empty.

I do not use Xib.

  • 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-18T13:44:23+00:00Added an answer on June 18, 2026 at 1:44 pm

    In the code snippet provided, you never perform the alloc and init of oggetto2. Thus, it is nil, and thus attempts to set its properties will achieve nothing.

    In addition to your existing NSLog statements, I’d also suggest doing a NSLog of the htmlString right before you perform loadHTMLString, because it’s easier to see what’s going on with your HTML by looking at the source, rather than trying to make inferences from a blank web view.


    Unrelated to your problem, but you probably should not have code that could potentially reusing your static sqlite3_stmt after you’ve finalized it. The first time you call carica_ID you would initialize the static leggiStatement. But you end up doing a sqlite_finalize but don’t set leggiStatement to nil. If you ever called this method a second time, it won’t sqlite3_prepare_v2 again, but you will have freed the resources associated with your prior leggiStatement.

    A couple of easy fixes:

    • do not make leggiStatement a static global, but rather make it a local, non-static variable of the method;

    • if you do sqlite3_finalize, make sure you set leggiStatement to nil as well; or

    • don’t call sqlite3_finalize, but rather just call sqlite3_reset, which will reset the prepared statement, but won’t release its resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web app that reads data from a SQL DB that contains
I currently have an iPhone app that reads data from an external XML file
I am creating an iOS app that reads data from a single SQLITE table
I have an app that shows data from a SQLite DB and the data
I have successfully created an app that reads from a bundled .plist file and
I have an app that needs to read a PDF file from the file
I have an HTML (App) file that reads another HTML (data) file via jQuery.ajax()
I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
I dont have much knowledge in using the Cursor to read data of SQLite
I got an app I'm working on that uses static data from a sqlite

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.