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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:46:19+00:00 2026-06-05T19:46:19+00:00

hello i am trying a sqlite database tutorial to build, but its not working

  • 0

hello i am trying a sqlite database tutorial to build, but its not working can any one help me please:

Find my code below:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end

#import "ViewController.h"
#import "PersonInfo.h"
#import "PersonDatabase.h"


@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSArray *personInfo=[[PersonDatabase database]getAllPersons];
    for (PersonInfo*info in personInfo) {
        NSLog(@"%d-%@",info.unique,info.nam);
    }// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end



#import <Foundation/Foundation.h>

@interface PersonInfo : NSObject{
    int unique;
    NSString * nam;
}
@property(nonatomic, assign)int unique;
@property(nonatomic, copy)NSString * nam;
-(id) initWithUniqueId:(int)uniqueId name:(NSString *)name;
@end


#import "PersonInfo.h"

@implementation PersonInfo
@synthesize unique,nam;

-(id) initWithUniqueId:(int)uniqueId name:(NSString *)name{
    self=[super init];
    if (self) {
        self.unique=uniqueId;
        self.nam=name;
        NSLog(@"a");
    }
    return self;
}

@end



#import <Foundation/Foundation.h>
#import "sqlite3.h"


@interface PersonDatabase : NSObject{
    sqlite3 * database;

}
+(PersonDatabase *)database;
-(NSArray *)getAllPersons;
@end



#import "PersonDatabase.h"
#import "PersonInfo.h"

@implementation PersonDatabase
static PersonDatabase * database;

+(PersonDatabase *)database{
    if (database ==nil) {
        database =[[PersonDatabase alloc]init];

    }
    return database;
}
-(id)init{

    self=[super init];
    if (self) {
        NSString *sqliteDb=[[NSBundle mainBundle]pathForResource:@"admin" ofType:@"sqlite3"];
        if(sqlite3_open([sqliteDb UTF8String],&database)!=SQLITE_OK){
            NSLog(@"FAILED");
        }else {
            NSLog(@"passed");
        }
    }
    return self;
}
-(NSArray *)getAllPersons{
    NSMutableArray * returnArray=[[NSMutableArray alloc]init];
    NSString * query= @"SELECT * FROM names";
    NSLog(@"%@",query);
    sqlite3_stmt * statement;
    if(sqlite3_prepare_v2(database, [query UTF8String],-1, &statement,NULL)==SQLITE_OK){

        while (sqlite3_step(statement)==SQLITE_OK) {
            int uniqueId = sqlite3_column_int(statement, 0);
            char *nameChars=(char *)sqlite3_column_text(statement,1);
            NSString *name=[[NSString alloc]initWithUTF8String:nameChars];
            PersonInfo *info=[[PersonInfo alloc]initWithUniqueId:uniqueId name:name];
            [returnArray addObject:info];
        }
        sqlite3_finalize(statement);
    }
    else {
        NSLog(@"a");
    }
    return returnArray;
}

@end

i found the problem is that, it is not passing through the function below, but i don’t know why?.. it also not giving any errors????

if(sqlite3_prepare_v2(database, [query UTF8String],-1, &statement,NULL)==SQLITE_OK)

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-05T19:46:21+00:00Added an answer on June 5, 2026 at 7:46 pm

    sqlite3_open takes second parameter as sqlite3** but you pass PersonDatabase** (as well as sqlite3_prepare_v2 needs sqlite3*, not PersonDatabase*):

    First of all, there is a lot of ambiguity in code:

    Rename

    static PersonDatabase *database;
    

    to something like

    static PersonDatabase *instance;
    

    than

    +(PersonDatabase *)database;
    

    to

    +(PersonDatabase *)sharedInstance;
    

    So

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

    Will be

    +(PersonDatabase *)sharedInstance{
            if (instance ==nil) {
                instance =[[PersonDatabase alloc]init];
    
            }
            return instance;
        }
    

    So now there is no ambiguity between sqlite3 *database and static PersonDatabase *database. And all should work.

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

Sidebar

Related Questions

Hello I'm trying to save string into SQLite database, but nothing happens. I have
Hello i am trying to set a views height but its throwing a null
Hello im trying to update google admboads to V6 but im having some trouble
Hello i am trying to return a struct from a function but i cant
Hello i am trying to find out how can i print a file which
Hello I am trying to make a C# program that downloads files but I
Hello im trying to echo out a image in side pagenation but is just
Hello iam trying to store sum information inside a SQL Server table , but
hello everyone im trying to create this tweak that copies a file from one
hello im trying to make something like github treeslider im new to javascript.. but

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.