File indexing completed on 2024-04-14 14:53:29

0001 /* This file is part of the KDE project
0002     Copyright (C) 2003-2017 Jarosław Staniek <staniek@kde.org>
0003     Copyright (C) 2004 Martin Ellis <martin.ellis@kdemail.net>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This program is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this program; see the file COPYING.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "KDbDriver_p.h"
0022 #include "KDbAdmin.h"
0023 #include "KDbDriverBehavior.h"
0024 #include "KDbDriverMetaData.h"
0025 #include "KDbVersionInfo.h"
0026 
0027 class Q_DECL_HIDDEN KDbDriverBehavior::Private
0028 {
0029 public:
0030     Private() {}
0031     KDbDriver *driver;
0032 };
0033 
0034 KDbDriverBehavior::KDbDriverBehavior(KDbDriver *driver)
0035         : features(KDbDriver::NoFeatures)
0036         , UNSIGNED_TYPE_KEYWORD(QLatin1String("UNSIGNED"))
0037         , AUTO_INCREMENT_FIELD_OPTION(QLatin1String("AUTO_INCREMENT"))
0038         , AUTO_INCREMENT_PK_FIELD_OPTION(QLatin1String("AUTO_INCREMENT PRIMARY KEY"))
0039         , SPECIAL_AUTO_INCREMENT_DEF(false)
0040         , AUTO_INCREMENT_REQUIRES_PK(false)
0041         , ROW_ID_FIELD_RETURNS_LAST_AUTOINCREMENTED_VALUE(false)
0042         , OPENING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER('"')
0043         , CLOSING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER('"')
0044         , USING_DATABASE_REQUIRED_TO_CONNECT(true)
0045         , CONNECTION_REQUIRED_TO_CHECK_DB_EXISTENCE(true)
0046         , CONNECTION_REQUIRED_TO_CREATE_DB(true)
0047         , CONNECTION_REQUIRED_TO_DROP_DB(true)
0048         , USE_TEMPORARY_DATABASE_FOR_CONNECTION_IF_NEEDED(false)
0049         , IS_DB_OPEN_AFTER_CREATE(false)
0050         , _1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY(false)
0051         , SELECT_1_SUBQUERY_SUPPORTED(false)
0052         , BOOLEAN_TRUE_LITERAL(QLatin1Char('1'))
0053         , BOOLEAN_FALSE_LITERAL(QLatin1Char('0'))
0054         , TEXT_TYPE_MAX_LENGTH(0)
0055         , LIKE_OPERATOR(QLatin1String("LIKE"))
0056         , RANDOM_FUNCTION(QLatin1String("RANDOM"))
0057         , d(new Private)
0058 {
0059     d->driver = driver;
0060     properties.insert("client_library_version", QVariant(),
0061                       KDbDriver::tr("Client library version"));
0062     properties.insert("default_server_encoding", QVariant(),
0063                       KDbDriver::tr("Default character encoding on server"));
0064 }
0065 
0066 KDbDriverBehavior::~KDbDriverBehavior()
0067 {
0068     delete d;
0069 }
0070 
0071 void KDbDriverBehavior::initInternalProperties()
0072 {
0073     properties.insert("is_file_database", d->driver->metaData()->isFileBased(),
0074                       KDbDriver::tr("File-based database driver"));
0075     if (d->driver->metaData()->isFileBased()) {
0076         properties.insert("file_database_mimetypes", d->driver->metaData()->mimeTypes(),
0077                           KDbDriver::tr("File-based database's MIME types"));
0078     }
0079 
0080 #if 0
0081     QString str;
0082     if (features & KDbDriver::SingleTransactions)
0083         str = futureTr("Single transactions support");
0084     else if (features & KDbDriver::MultipleTransactions)
0085         str = futureTr("Multiple transactions support");
0086     else if (features & KDbDriver::NestedTransactions)
0087         str = futureTr("Nested transactions support");
0088     else if (features & KDbDriver::IgnoreTransactions)
0089         str = futureTr("Ignored", "Ignored transactions");
0090     else
0091         str = futureTr2("None", "No transactions");
0092 #endif
0093 // properties["transaction_support"] = features & KDbDriver::TransactionsMask;
0094 // propertyCaptions["transaction_support"] = KDbDriver::tr("Transaction support");
0095     properties.insert("transactions_single", bool(d->driver->behavior()->features & KDbDriver::SingleTransactions),
0096                       KDbDriver::tr("Single transactions support"));
0097     properties.insert("transactions_multiple", bool(d->driver->behavior()->features & KDbDriver::MultipleTransactions),
0098                       KDbDriver::tr("Multiple transactions support"));
0099     properties.insert("transactions_nested", bool(d->driver->behavior()->features & KDbDriver::NestedTransactions),
0100                       KDbDriver::tr("Nested transactions support"));
0101     properties.insert("transactions_ignored", bool(d->driver->behavior()->features & KDbDriver::IgnoreTransactions),
0102                       KDbDriver::tr("Ignored transactions support"));
0103     //! @todo more KDbDriver::Features
0104 
0105     const KDbVersionInfo v(KDb::version());
0106     properties.insert("kdb_driver_version", QString::fromLatin1("%1.%2.%3").arg(v.major()).arg(v.minor()).arg(v.release()),
0107                       KDbDriver::tr("KDb driver version"));
0108 }
0109 
0110 //---------------------------------------------
0111 
0112 KDbDriverPrivate::KDbDriverPrivate(KDbDriver *aDriver)
0113         : driver(aDriver)
0114         , driverBehavior(driver)
0115         , metaData(nullptr)
0116         , adminTools(nullptr)
0117 {
0118 }
0119 
0120 KDbDriverPrivate::~KDbDriverPrivate()
0121 {
0122     delete adminTools;
0123 }