Design patterns implementation examples

How to be relational database independent in C++

Problem:

We want to implement easy to use database access classes which are database independent.


Solution:

To be database implementaion independent we need interfaces : DBConnection, QueryResult, QueryRow.


DBConnection.h:

/src/articles/DBConnection.h

QueryResult.h:

/src/articles/QueryResult.h

QueryRow.h:

/src/articles/QueryRow.h

Implementation classes for MySql are below:


MySqlConnection.h:

/src/articles/MySqlConnection.h

MySqlConnection.cpp:

/src/articles/MySqlConnection.cpp

MySqlQueryResult.h:

/src/articles/MySqlQueryResult.h

MySqlQueryResult.cpp:

/src/articles/MySqlQueryResult.cpp

MySqlQueryRow.h:

/src/articles/MySqlQueryRow.h

MySqlQueryRow.cpp:

/src/articles/MySqlQueryRow.cpp

Main program for database access should looks like below.


/src/articles/MailSender.cpp