0

I have a C++ application that uses SQLite database. The database need to be created and initialized by first checking if the database exists and if a table (known to the application) exists. Subsequently the application will have to do the checking every time it starts. Is this the best way or are there any other approach to this?

Amani
  • 16,245
  • 29
  • 103
  • 153

2 Answers2

0

That seems like a reasonable approach. I've used it before as well.

I believe you can just blindly call your create table script every time you connect when your application starts. Then just handle any return codes appropriately

Vinbot
  • 518
  • 2
  • 14
0

From SQLite Documentation and SQLite Quickstart:

For checking if database exist you could check if the physical file exist, and loaded with sqlite3_open.

For checking if the table exist check the link.

If the table don't exist, you execute a prepared statement with the create table command if the DB don't exist, created and execute the previous create table command

Community
  • 1
  • 1
NetVipeC
  • 4,402
  • 1
  • 17
  • 19