Programmatically check database structure in C ++

How can I verify that the database is structured as my C ++ program expects? Our initial control was very weak in the past, so we have many production installations there, using databases that lack the columns and tables that are now required in the current version of the C ++ program. I would like my application verification to make sure that the database is structured as it expects at startup. Ideally, this will work for SQL, Oracle, Access, MySql DB.

+3
source share
3 answers

The difficulty seems to be cross-DBMS. ODBC drivers provide most of the functionality you need in all databases. In this situation, I used ODBC SQLTables and SQLDescribeColumn to retrieve the definition of all the tables, columns, and indexes in the database, and then compared them to the output of the process with a well-known good database.

It is simple enough if you just want to check the structure, the code for restoring such a database, adding columns and indexes, logically following from this, but complicating it a bit.

+4
source

Assuming you can query the database using SQL, you can use the SQL DESCRIBE statement to query the description of the table you are looking at, for example

DESCRIBE table1;

, , , .

, , .

Field |Type    |NULL |Key |Default| Extra
Col 1 |int(11) |NO   |PRI |NULL   | auto_increment
Co1 2 |time    |No   |    |NULL   |

.

+2

" , , , , ".

... , ?

, , , ( , ).

, ( , , , , ), , , , , : " , , "?

In both situations, the result is almost guaranteed: your program will not work. If you are having problems with "databases that are not structured as expected," you need to look at (and fix the errors) the general process. The software does not live β€œin its own world” and the databases do not work.

0
source

Source: https://habr.com/ru/post/1715437/


All Articles