Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically verify database structure in C++

Tags:

database

How would I verify a database is structured how my C++ program expects? Our source control was very weak in the past so we have many production installs out there using databases which are missing columns and tables which are now required in the current version of the C++ program. I'd like to have my app check to make sure the database is structured the way it expects at startup time. Ideally this would work for SQL, Oracle, Access, MySql DBs.

like image 810
JonF Avatar asked Apr 07 '26 10:04

JonF


1 Answers

The difficulty seems to be in the cross-DBMS. ODBC drivers provide most of the functionality you need across all databases. In this situation I have used ODBC SQLTables and SQLDescribeColumn to extract a definition of all tables, columns and indexes on the database and then compared that to the output of the process run against a known good database.

This is easy enough if you just want to validate the structure, the code to repair such a database by adding columns and indexes followed logically from that but got a little harder.

like image 162
Elemental Avatar answered Apr 10 '26 00:04

Elemental