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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:14:54+00:00 2026-06-11T04:14:54+00:00

I have an app with a simple table stored in a common sqlite database.

  • 0

I have an app with a simple table stored in a common sqlite database. The app has a mainview and several other views say, view1, view2, ....,viewN. From a mainview, the user go to view1 by this code section:

screen.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:screen animated:YES];

in view1, the user will access the database, doing something, then update the database, quite view1 back to the mainview:

[self dismissModalViewControllerAnimated:YES];

The user will do the same thing for the other views, i.e., accessing the database, doing something, updating the database, then back to the mainview.

My question is how should I organize the database in my case, using a singleton to create a common object to open the database at the mainview, then all views will access the database, updating it or each view will open the database, accessing it, then update individually or is there any other efficient way. Thank you

  • 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-11T04:14:56+00:00Added an answer on June 11, 2026 at 4:14 am

    As you describe the structure of your app being one threaded only – using a singleton is perfectly OK. You need to open the DB only once when the app starts and make sure to close it when the app ends or even when the app goes to background (of course then you need to open the DB when return from background too)

    By the way, I also tried to open and close the DB for each view – which also works fine. In this approach I also sometimes use a “dirty” flag, that is set to indicate that the DB needs updateing before closing – but that turned out to make no difference in performance.

    Instead of using a singleton you may also use a class variable or declare it within your app delegate, which is often done for the cotext of core data ( where the “context” in core data is similar to the DB in your case)

    What is important in whatever approach you use is that your DB will be in a consistent state all the time since your app can get “interrupted” by phone call for example.

    By the way, I tend to use core data more often on iPhone if circumstances allow, since core data takes care of many of the DB issues – only saving at consistent states needs to be done explicitly. But it really depends if your data is more a big DB or just “some” persitent objects/attributes.

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

Sidebar

Related Questions

I have a simple cakephp app with table articles that has a cat_id column
My iphone app uses a SQLite database to store data. I have a table
I have a simple database table (SQL Server 2008 R2 Express), which has a
I have a Answer table which has pk_answerid, answertext , fk_questionid, chosenoptions stored as
I need to create a very simple app that has one table that will
This is a real newbie question. I have simple app that selects a picture
I have a simple app where you can login it looks like this: {{#view
I have a simple app with a full screen UIWebView. This contains HTML generated
I have one simple app that suppose to get information from user and send
I have a simple app that will allow a user to tag a location.

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.