KDb

KDbConnectionData.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2015 Jarosław Staniek <staniek@kde.org>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KDbConnectionData.h"
21#include "KDbDriverManager.h"
22#include "KDbDriverMetaData.h"
23#include "KDbConnection.h"
24
25#if 0 // needed by lupdate to avoid "Qualifying with unknown namespace/class"
26class KDbConnectionData { Q_DECLARE_TR_FUNCTIONS(KDbConnectionData) };
27#endif
28
29KDbConnectionData::~KDbConnectionData()
30{
31}
32
34{
35 KDbDriverManager mananager;
36 const KDbDriverMetaData *metaData = mananager.driverMetaData(d->driverId);
37 if (!metaData) {
38 return d->databaseName;
39 } else if (metaData->isValid() && metaData->isFileBased()) {
40 if (d->databaseName.isEmpty()) {
41 return tr("<file>");
42 }
43 return tr("file: %1").arg(d->databaseName);
44 }
45 return ((d->userName.isEmpty() || !(options & UserVisibleStringOption::AddUser))
46 ? QString()
47 : (d->userName + QLatin1Char('@')))
48 + (d->hostName.isEmpty() ? QLatin1String("localhost") : d->hostName)
49 + (d->port != 0 ? (QLatin1Char(':') + QString::number(d->port)) : QString());
50}
51
53{
54 KDbDriverManager mananager;
55 const KDbDriverMetaData *metaData = mananager.driverMetaData(d->driverId);
56 if (!metaData) {
57 return false;
58 }
59 const bool fileBased = metaData->isValid() && metaData->isFileBased();
60
61 return !d->savePassword && !fileBased; //!< @todo temp.: change this if there are
62 //!< file-based drivers requiring a password
63}
64
65KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbConnectionData& data)
66{
67 dbg.nospace() << "CONNDATA";
68 KDbDriverManager mananager;
69 const KDbDriverMetaData *metaData = mananager.driverMetaData(data.driverId());
70 dbg.nospace()
71 << " databaseName=" << data.databaseName()
72 << " caption=" << data.caption()
73 << " description=" << data.description()
74 << " driverId=" << data.driverId()
75 << " userName=" << data.userName()
76 << " hostName=" << data.hostName()
77 << " port=" << data.port()
78 << " useLocalSocketFile=" << data.useLocalSocketFile()
79 << " localSocketFileName=" << data.localSocketFileName()
80 << " password=" << QString::fromLatin1("*").repeated(data.password().length()) /* security */
81 << " savePassword=" << data.savePassword()
82 << " isPasswordNeeded=" <<
83 qPrintable(metaData ? QString::number(data.isPasswordNeeded())
84 : QString::fromLatin1("[don't know, no valid driverId]"))
85 << " userVisibleString=" << data.toUserVisibleString();
86 return dbg.nospace();
87}
Database specific connection data, e.g. host, port.
QString toUserVisibleString(UserVisibleStringOptions options=UserVisibleStringOption::AddUser) const
bool isPasswordNeeded() const
A driver manager for finding and loading driver plugins.
const KDbDriverMetaData * driverMetaData(const QString &id)
Provides information about a single driver plugin.
bool isValid() const
QDebug & nospace()
QString fromLatin1(QByteArrayView str)
qsizetype length() const const
QString number(double n, char format, int precision)
QString repeated(qsizetype times) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.