4
votes

I am using Visual C++ to write a small app which will invoke SQLite C Interface to create an database and insert some data into it.

When debugging the application, I want to check the data in the database. Therefore, I start the sqlite3 shell(sqlite3.exe) from commandline, then use the following command to open the database:

.open filename

Thereafter, I want to check the table created by my app, but always get “table does not exist” error.

Then I use “select * from sqlite_master;” but still return empty result.

I make more tests as below:

  1. Try to open the database again with --readonly option, as below:

.open --readonly FileName;

  1. After opening the database, I try to use command like this:

select * from sqlite_master;

Then I will see "database is locked" error. I try to search on Stackoverflow for solutions, and all solutions just suggest to close the other application that is accessing the database. However, what I need is just let the app still access the database, meanwhile I can still view(not modify) the contents in the sqlite database, is that possible?

Therefore, I just wonder whether I can access a sqlite database which has already been opened by another program simultaneously via the sqlite3.exe shell? Currently only my app will write into the database, and sqlite3 shell only needs to read the data in the database.

2
Are you sure your program and the sqlite3 shell are using the same database file? - Shawn
Probably wrong directory. - CL.
@CL, I am sure the database is opened successfully, since the first time when I input a wrong name, I get an error. Then I correct the name and the open is successfuly without error. - alancc
Check out WAL mode. - CL.

2 Answers

0
votes

Hi you can use 'DB Browser for SQlite'. With this tool you can easily create your sqlite database and insert rows. Also you can view the data inserted.

0
votes

If sqlite_master is empty, you might have opened the wrong file with the CLI tool, or the writing application might not have committed the transaction that created the tables you are looking for.

If you want one writer and one reader process, it might be a good idea to check out https://www.sqlite.org/wal.html making sure you open the database correctly in both processes.

If this is only for debugging, perhaps using the https://www.sqlite.org/backup.html Backup API might be a solution aswell. That allows you to dump the database to a separate file which allows you to ignore concurrency issues when reading.