C ++: general interface design for the database

I have a class that is used to create a database connection:

class DBHandler
{
public:
    DBHandler();
   ~DBHandler();

    int connect();
    int execQuery( string query);
    string getField( int row, int col);
};

Now there is another class that is used to get some information from the database,

class DBManager
{
public:
    DBManager();
   ~DBManager();

   //Approach 1
   string getUsername()
   {
      //create a query here and use     object of DBHandler class to execute it.
   }

   //Approach 2
   string getUsername (struct     QueryDetails& qDetails)
   {
      //create query using fields of structure and execute the query using DBHandler class.
   }
 };

Now here is the problem:

1) to which I must follow:

  • A) If I use approach 1, then I need to request a hard code.
  • B) If I use approach 2, I need to populate the structure every time before calling the getUsername function.

2) Is there a better solution than two that would be common?

PS: Structure Definition

struct QueryDetails
{
    string tableName;
    vector<string> colList;
 ...
};
+4
source share
1 answer

Your question is very broad, and the elements that you give do not allow you to offer you an objective, best answer.

1 :

  • :
  • ( ), ,
  • , , , .

, . PostGres - , .

2 :

  • .
  • , .

, : , , .

, , .

1. , , , .

, , . , calsses , 2 .

+1

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


All Articles