Advertisement
popov-aa

CONNECTIONPARAMETERS_H

Feb 7th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #ifndef CONNECTIONPARAMETERS_H
  2. #define CONNECTIONPARAMETERS_H
  3.  
  4. #include <QDebug>
  5. #include <QSqlDatabase>
  6. #include <QString>
  7.  
  8. namespace Atm { namespace DbProvider {
  9.  
  10. struct ConnectionParameters
  11. {
  12.     QString driver;
  13.     QString hostName;
  14.     quint16 port;
  15.     QString databaseName;
  16.     QString userName;
  17.     QString password;
  18.  
  19.     static ConnectionParameters fromSqlDatabase( const QSqlDatabase & database );
  20.  
  21.     QSqlDatabase createSqlDatabase(
  22.       const QString & connectionName = QLatin1String( QSqlDatabase::defaultConnection ) ) const;
  23.  
  24.     friend QDebug & operator<<( QDebug & d, const ConnectionParameters & p )
  25.     {
  26.         bool space = d.autoInsertSpaces();
  27.         if ( p.driver == "QSQLITE" ) {
  28.             d.noquote().nospace() << p.databaseName;
  29.         } else {
  30.             if ( !p.userName.isEmpty() ) {
  31.                 d.noquote().nospace() << p.userName << "@";
  32.             }
  33.             d.noquote().nospace() << p.hostName << ":" << p.port << "\\" << p.databaseName;
  34.         }
  35.         d.setAutoInsertSpaces( space );
  36.         return d.maybeSpace();
  37.     }
  38.  
  39.     bool operator==( const ConnectionParameters & other ) const;
  40.     bool operator!=( const ConnectionParameters & other ) const;
  41. };
  42.  
  43. }} // namespace Atm::DbProvider
  44.  
  45. #endif // CONNECTIONPARAMETERS_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement