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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:12:34+00:00 2026-05-27T17:12:34+00:00

I have built an application in which I use sqlite to store data. It

  • 0

I have built an application in which I use sqlite to store data. It is running well in the simulator but when it run on a real device it stop responding to sqlite. Even the code is not responding to sqlite command..Here is my code..

    - (void)viewDidLoad {

//Create Database
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir=[paths objectAtIndex:0];

NSString *dirString=[dir stringByAppendingPathComponent:@"ABC.sqlite"];

databasepath=[[NSString alloc]initWithString:dirString];
NSFileManager *fileManager=[NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:databasepath]==NO) 
{
    const char *dbpath=[databasepath UTF8String];
    if (sqlite3_open(dbpath, &contactDB)==SQLITE_OK)
    {
        char *errMsg;
        const char *createSQL="CREATE TABLE IF NOT EXISTS QUESTIONS(ID INTEGER PRIMARY KEY AUTOINCREMENT,QUESTIONSLIST TEXT,ANSWER1 TEXT,ANSWER2 TEXT,ANSWER3 TEXT,ANSWER4 TEXT,CORRECTANSWER TEXT)";

        if (sqlite3_exec(contactDB, createSQL, NULL, NULL, &errMsg) !=SQLITE_OK)
        {
            NSLog(@"Failed to create table");

        }
        sqlite3_close(contactDB);
    }


}



[super viewDidLoad];

}

    -(void)xyz{


NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir=[paths objectAtIndex:0];

NSString *dirString=[dir stringByAppendingPathComponent:@"ABC.sqlite"];

databasepath=[[NSString alloc]initWithString:dirString];

const char *dbpath=[databasepath UTF8String];
sqlite3_stmt *statement;

if (sqlite3_open(dbpath, &contactDB)==SQLITE_OK)
{
    NSString *querySQL=[NSString stringWithFormat:@"select * from questions order by random() LIMIT 1"];
    const char *query=[querySQL UTF8String];

    if (sqlite3_prepare_v2(contactDB, query, -1, &statement, NULL)==SQLITE_OK)
    {
        if (sqlite3_step(statement)==SQLITE_ROW)
        {
            NSString *questionField=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 1)];
            questionView.text=questionField;

            NSString *option1=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];
            [answer1 setTitle:option1 forState:UIControlStateNormal];

            NSString *option2=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 3)];
            [answer2 setTitle:option2 forState:UIControlStateNormal];


            NSString *option3=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 4)];
            [answer3 setTitle:option3 forState:UIControlStateNormal];


            NSString *option4=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 5)];
            [answer4 setTitle:option4 forState:UIControlStateNormal];

            NSString *option5=[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 6)];
            correctAnswer.text=option5;
            correctAnswer.hidden=NO;


            [option1 release];
            [option2 release];
            [option3 release];
            [option4 release];
            [option5 release];
        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(contactDB);

}

}

  • 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-27T17:12:35+00:00Added an answer on May 27, 2026 at 5:12 pm

    NoviceDeveloper:

    please tell me how to copy sqlite file to device
    

    If you want to do this, you need to have this file in the resources of your project: in this way it will be included to the app package and transfered to your device then.

    Next step is to copy it to applicationDocumentsDirectory if you didn’t do so before. Smth. like:

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"NameOfYourDatabase.sqlite"];
    NSError *error = nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *defaultStoreURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"NameOfYourDatabase" ofType:@"sqlite"]];
    if (![fileManager fileExistsAtPath:[storeURL relativePath]]) {
        if (defaultStoreURL) {
            [fileManager copyItemAtURL:defaultStoreURL toURL:storeURL error:&error];
        }
    }
    if (error)
        //handle it
    

    EDITED:

    With function:

    - (NSURL *)applicationDocumentsDirectory {
        return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a application built in Silverlight, which will run on a ATOM processor
I have an application in which we use a hand-made build system.The reason for
I have an .Net MVC application which runs fine if I use the build
I have a custom built application framework written in PHP which I have been
I have an application which is built from command line (ANT) using J2ME Polish.
I have an application, built using MVC, that produces a view which delivers summary
I have an ASP.Net 4.0 web application which very frequently loads data from the
We have an application which uses SQLite as an embedded RDBMS. Initially the application
I have built an asp.net application from which I would like to post blog
We have built an application using wxWidgets in C++ and use wxToolTips to provide

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.