diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kexi/kexidb/dbproperties.cpp | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kexi/kexidb/dbproperties.cpp')
-rw-r--r-- | kexi/kexidb/dbproperties.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/kexi/kexidb/dbproperties.cpp b/kexi/kexidb/dbproperties.cpp new file mode 100644 index 00000000..c5780542 --- /dev/null +++ b/kexi/kexidb/dbproperties.cpp @@ -0,0 +1,148 @@ +/* This file is part of the KDE project + Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "dbproperties.h" +#include <klocale.h> + +using namespace KexiDB; + +DatabaseProperties::DatabaseProperties(Connection *conn) + : KexiDB::Object() + , m_conn(conn) +{ +} + +DatabaseProperties::~DatabaseProperties() +{ +} + +bool DatabaseProperties::setValue( const QString& _name, const QVariant& value ) +{ + QString name(_name.stripWhiteSpace()); + bool ok; + //we need to know whether update or insert + bool exists = m_conn->resultExists( + QString::fromLatin1("SELECT 1 FROM kexi__db WHERE db_property=%1") + .arg(m_conn->driver()->escapeString(name)), ok); + if (!ok) { + setError(m_conn, i18n("Could not set value of database property \"%1\".").arg(name)); + return false; + } + + if (exists) { + if (!m_conn->executeSQL( + QString::fromLatin1("UPDATE kexi__db SET db_value=%1 WHERE db_property=%2") + .arg(m_conn->driver()->escapeString(value.toString())) + .arg(m_conn->driver()->escapeString(name)))) + { + setError(m_conn, i18n("Could not set value of database property \"%1\".").arg(name)); + return false; + } + return true; + } + + if (!m_conn->executeSQL( + QString::fromLatin1("INSERT INTO kexi__db (db_property, db_value) VALUES (%1, %2)") + .arg(m_conn->driver()->escapeString(name)) + .arg(m_conn->driver()->escapeString(value.toString())))) + { + setError(m_conn, i18n("Could not set value of database property \"%1\".").arg(name)); + return false; + } + return true; +} + +bool DatabaseProperties::setCaption( const QString& _name, const QString& caption ) +{ + QString name(_name.stripWhiteSpace()); + //captions have ' ' prefix + name.prepend(" "); + bool ok; + //we need to know whether update or insert + bool exists = m_conn->resultExists( + QString::fromLatin1("SELECT 1 FROM kexi__db WHERE db_property=%1") + .arg(m_conn->driver()->escapeString(name)), ok); + if (!ok) { + setError(m_conn, i18n("Could not set caption for database property \"%1\".").arg(name)); + return false; + } + + if (exists) { + if (!m_conn->executeSQL( + QString::fromLatin1("UPDATE kexi__db SET db_value=%1 WHERE db_property=%2") + .arg(m_conn->driver()->escapeString(caption)) + .arg(m_conn->driver()->escapeString(name)))) + { + setError(m_conn, i18n("Could not set caption for database property \"%1\".").arg(name)); + return false; + } + return true; + } + + if (!m_conn->executeSQL( + QString::fromLatin1("INSERT INTO kexi__db (db_property, db_value) VALUES (%1, %2)") + .arg(m_conn->driver()->escapeString(name)) + .arg(m_conn->driver()->escapeString(caption)))) + { + setError(m_conn, i18n("Could not set caption for database property \"%1\".").arg(name)); + return false; + } + return true; +} + +QVariant DatabaseProperties::value( const QString& _name ) +{ + QString result; + QString name(_name.stripWhiteSpace()); + if (true!=m_conn->querySingleString( + QString::fromLatin1("SELECT db_value FROM kexi__db WHERE db_property=") + + m_conn->driver()->escapeString(name), result)) { + m_conn->setError(ERR_NO_DB_PROPERTY, i18n("Could not read database property \"%1\".").arg(name)); + return QVariant(); + } + return result; +} + +QString DatabaseProperties::caption( const QString& _name ) +{ + QString result; + QString name(_name.stripWhiteSpace()); + //captions have ' ' prefix + name.prepend(" "); + if (true!=m_conn->querySingleString( + QString::fromLatin1("SELECT db_value FROM kexi__db WHERE db_property=") + + m_conn->driver()->escapeString(name), result)) { + setError(m_conn, i18n("Could not read database property \"%1\".").arg(name)); + return QString::null; + } + return result; +} + +QStringList DatabaseProperties::names() +{ + QStringList result; + if (true!=m_conn->queryStringList( + QString::fromLatin1("SELECT db_value FROM kexi__db WHERE db_property NOT LIKE ") + + m_conn->driver()->escapeString(QString::fromLatin1(" %%")), result, 0 /*0-th*/)) { + // ^^ exclude captions + setError(m_conn, i18n("Could not read database properties.")); + return QStringList(); + } + return result; +} |