| 80 | } |
| 81 | |
| 82 | bool SQLManager::testConnection(const Connection &conn, QSqlError &error) |
| 83 | { |
| 84 | QString connectionName = (conn.name.isEmpty()) ? QStringLiteral("katesql-test") : conn.name; |
| 85 | |
| 86 | QSqlDatabase db = QSqlDatabase::addDatabase(conn.driver, connectionName); |
| 87 | |
| 88 | if (!db.isValid()) { |
| 89 | error = db.lastError(); |
| 90 | QSqlDatabase::removeDatabase(connectionName); |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | db.setHostName(conn.hostname); |
| 95 | db.setUserName(conn.username); |
| 96 | db.setPassword(conn.password); |
| 97 | db.setDatabaseName(conn.database); |
| 98 | db.setConnectOptions(conn.options); |
| 99 | |
| 100 | if (conn.port > 0) { |
| 101 | db.setPort(conn.port); |
| 102 | } |
| 103 | |
| 104 | if (!db.open()) { |
| 105 | error = db.lastError(); |
| 106 | QSqlDatabase::removeDatabase(connectionName); |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | QSqlDatabase::removeDatabase(connectionName); |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | bool SQLManager::isValidAndOpen(const QString &connection) |
| 115 | { |
no test coverage detected