2

I have two C++ functions, which each construct an SQLite database.

First function constructs database version 1, and then upgrades it to newest version by adding all tables/columns that have been added to the database since the first version. Another function constructs a database that is already in the newest version. As result, each function gives one database that has all necessary tables and columns, but no values.

I wish to write an unit test that compares the results of those two functions. I want to test that they have exactly the same tables and columns, and that all columns have the same CHECK and NOT NULL constraints. I only need to compare columns and tables, because the databases have no values in them at this point.

I would prefer to get the differences in a human readable form (to place them in an error message), but a boolean value (different/not different) is also fine.

How can I do that, given that both databases are in different variables and I cannot combine them?

There are other questions that suggest external applications for this, but can I do it in a simple way in C++? One possibility is to execute some SQL commands for each database, and compare the results in a for loop, but which commands do I need?

1 Answer 1

2

You can read the sqlite_master table to read the SQL used to create each table and compare that:

SELECT name, type, sql FROM sqlite_master;

For more information on sqlite_master, consult the SQLite documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.