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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:55:38+00:00 2026-06-12T19:55:38+00:00

In this database there is a table called Menu. I want to print this

  • 0

In this database there is a table called “Menu”. I want to print this table in my ViewController but this method do not work and close the database immediately.

In DatabaseMenu.h:

@interface DatabaseMenu : NSObject {
    sqlite3 *databaseMenu;
    DataBaseMenu *rowMenu;
}

@property (nonatomic, assign) int ID; 
@property (nonatomic, copy)NSString *descrizione;
@property (nonatomic, assign) BOOL haSubMenu;
@property (nonatomic, assign) int IDPadre;
@property (nonatomic, copy) NSString *tabelleFigli;
@property (nonatomic, assign) int ordine;
@property (nonatomic, copy) NSString *custView;
@property (nonatomic, assign) BOOL visMappa;
@property (nonatomic, copy) NSMutableArray *menuArray;

-(NSMutableArray*) loadDataFromMenu;
+(DatabaseMenu*) database;

@end

In DatabaseMenu.m

static DatabaseMenu * database;

+(DatabaseMenu*) database{
    if (database==nil) {
        database =[[DatabaseMenu alloc]init];
    }
    return database;
}


-(NSMutableArray*) loadDataFromMenu{ 

    NSString *query = @"SELECT * FROM Menu";

    sqlite3_stmt *statement;

    if (sqlite3_prepare_v2(databaseMenu, [query UTF8String], -1, &statement, nil)
        == SQLITE_OK) {

        while (sqlite3_step(statement) == SQLITE_ROW) {

            //.......

        }
        sqlite3_finalize(statement);

    } else {        
        sqlite3_close(databaseMenu);
    }

    return self.menuArray;  
}

  -(id) init{ //open database
        self =[super init];
        if(self){
        NSString *sqliteDb = [[NSBundle mainBundle]pathForResource:@"China" ofType:@"sqlite"];

         if(sqlite3_open([sqliteDb UTF8String], &databaseMenu)!=SQLITE_OK){

                     NSLog(@"Failed to open database");

            }else {

                     NSLog(@"open the database");



                  [self loadDatiFromMenu];
    }

    return self;
}

}

The debugger not get to enter in the while loop. Why?

  • 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-12T19:55:39+00:00Added an answer on June 12, 2026 at 7:55 pm

    What you have done is not proper way to read data from database.

    After init the sqlite3 variable have to open the database first and then have to access the database like below

    if(!sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)
    {
         NSLog(@"An error has occured");
    }
    
    const char *sql = "SELECT * FROM Menu";
    sqlite3_stmt *sqlStatement;
    if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
    {
         NSLog(@"Problem with prepare statement.");
    }
    
    while(sqlite3_step(sqlStatement) == SQLITE_ROW)
    {
        //get all data from 
    }
    

    Here dbPath is ivar used to store whole path pointing to the data base

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

Sidebar

Related Questions

I want to display a table like this Generated from three database tables depends
There's this already populated database which came from another dev. I'm not sure what
Imagine it like this. There is a field in my database called flags in
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
I have an Postgre database and a table called my_table. There are 4 columns
I have an database table called MenuItem (MenuItemID, ParentMenuItemID, MenuItemName). I want to use
Ok... I have a database table called employees.. This has columns called ID, Name,
I've created a database with a table called pages in it. Within this table
I have a database table called users This table has two columns (that are
I have this database with a table and a row called 'rank'. In that

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.