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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:08:04+00:00 2026-06-14T19:08:04+00:00

I have implemented simple cache stored in SQLite database. For one client there is

  • 0

I have implemented simple cache stored in SQLite database. For one client there is one table in database. I want to automaticaly create this table if it not exists. What will be better sollution, checking if table exists using query: SELECT name FROM sqlite_master WHERE type='table' AND name='table_name'; or using CREATE TABLE IF NOT EXISTS table_name (...)? I have to do this every time I need cache, so I wonder which way will be more efficient and more correct.

I’m using PDO, so maybe there is some cleverer way to do this?

Solution:
Use PDO::errorCode to find if table doesn’t exists.

  • 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-14T19:08:05+00:00Added an answer on June 14, 2026 at 7:08 pm

    I’d go with create table if not exists because it’ll be compatible with other databases should you need it one day (in case of sqlite particularly it’s unlikely you’ll switch, but still).

    Also if you check sqlite_master and don’t find your table there you need to send another query to create it. With create table you’re only sending one query, although with table structure defined in it, but if your table structure is not hard to generate or is predefined, you’ll have no problems supplying it every time with create table.

    It also depends on how likely is it for your tables not to exist. If that is not very likely and you just want your app to be safe and self-maintaining you can just assume they exist and process exceptions to create table when queries assuming they exist fail.

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

Sidebar

Related Questions

I have implemented a simple parallel merge sort algorithm in Java. This cuts the
We have a simple but very much used cache, implemented by a ConcurrentHashMap. Now
I have implemented a simple cache using the dictionary class: private Dictionary<int, byte[]> cache
I have implemented a simple entity ejb with a @version annotation. I expect that
I have implemented a simple linux shell in c. Now, I am adding some
I have implemented a simple RSS reader in Java. I hit a URL and
I have implemented my own simple version of a navigation window, mainly because navigation
I've got a simple C class I have implemented, using function pointers in a
I am creating a simple messaging system in WCF and have implemented a minimal
Very simple Qt GUI application: On the scene I have multiple circles implemented as

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.