kexi
dbproperties.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "dbproperties.h"
00021 #include <klocale.h>
00022
00023 using namespace KexiDB;
00024
00025 DatabaseProperties::DatabaseProperties(Connection *conn)
00026 : KexiDB::Object()
00027 , m_conn(conn)
00028 {
00029 }
00030
00031 DatabaseProperties::~DatabaseProperties()
00032 {
00033 }
00034
00035 bool DatabaseProperties::setValue( const QString& _name, const QVariant& value )
00036 {
00037 QString name(_name.stripWhiteSpace());
00038 bool ok;
00039
00040 bool exists = m_conn->resultExists(
00041 QString::fromLatin1("select 1 from kexi__db where db_property=%1")
00042 .arg(m_conn->driver()->escapeString(name)), ok);
00043 if (!ok) {
00044 setError(m_conn, i18n("Could not set value of database property \"%1\".").arg(name));
00045 return false;
00046 }
00047
00048 if (exists) {
00049 if (!m_conn->executeSQL(
00050 QString::fromLatin1("update kexi__db set db_value=%1 where db_property=%2")
00051 .arg(m_conn->driver()->escapeString(value.toString()))
00052 .arg(m_conn->driver()->escapeString(name))))
00053 {
00054 setError(m_conn, i18n("Could not set value of database property \"%1\".").arg(name));
00055 return false;
00056 }
00057 return true;
00058 }
00059
00060 if (!m_conn->executeSQL(
00061 QString::fromLatin1("insert into kexi__db (db_property, db_value) values (%1, %2)")
00062 .arg(m_conn->driver()->escapeString(name))
00063 .arg(m_conn->driver()->escapeString(value.toString()))))
00064 {
00065 setError(m_conn, i18n("Could not set value of database property \"%1\".").arg(name));
00066 return false;
00067 }
00068 return true;
00069 }
00070
00071 bool DatabaseProperties::setCaption( const QString& _name, const QString& caption )
00072 {
00073 QString name(_name.stripWhiteSpace());
00074
00075 name.prepend(" ");
00076 bool ok;
00077
00078 bool exists = m_conn->resultExists(
00079 QString::fromLatin1("select 1 from kexi__db where db_property=%1")
00080 .arg(m_conn->driver()->escapeString(name)), ok);
00081 if (!ok) {
00082 setError(m_conn, i18n("Could not set caption for database property \"%1\".").arg(name));
00083 return false;
00084 }
00085
00086 if (exists) {
00087 if (!m_conn->executeSQL(
00088 QString::fromLatin1("update kexi__db set db_value=%1 where db_property=%2")
00089 .arg(m_conn->driver()->escapeString(caption))
00090 .arg(m_conn->driver()->escapeString(name))))
00091 {
00092 setError(m_conn, i18n("Could not set caption for database property \"%1\".").arg(name));
00093 return false;
00094 }
00095 return true;
00096 }
00097
00098 if (!m_conn->executeSQL(
00099 QString::fromLatin1("insert into kexi__db (db_property, db_value) values (%1, %2)")
00100 .arg(m_conn->driver()->escapeString(name))
00101 .arg(m_conn->driver()->escapeString(caption))))
00102 {
00103 setError(m_conn, i18n("Could not set caption for database property \"%1\".").arg(name));
00104 return false;
00105 }
00106 return true;
00107 }
00108
00109 QVariant DatabaseProperties::value( const QString& _name )
00110 {
00111 QString result;
00112 QString name(_name.stripWhiteSpace());
00113 if (true!=m_conn->querySingleString(
00114 QString::fromLatin1("select db_value from kexi__db where db_property=")
00115 + m_conn->driver()->escapeString(name), result)) {
00116 m_conn->setError(ERR_NO_DB_PROPERTY, i18n("Could not read database property \"%1\".").arg(name));
00117 return QVariant();
00118 }
00119 return result;
00120 }
00121
00122 QString DatabaseProperties::caption( const QString& _name )
00123 {
00124 QString result;
00125 QString name(_name.stripWhiteSpace());
00126
00127 name.prepend(" ");
00128 if (true!=m_conn->querySingleString(
00129 QString::fromLatin1("select db_value from kexi__db where db_property=")
00130 + m_conn->driver()->escapeString(name), result)) {
00131 setError(m_conn, i18n("Could not read database property \"%1\".").arg(name));
00132 return QString::null;
00133 }
00134 return result;
00135 }
00136
00137 QStringList DatabaseProperties::names()
00138 {
00139 QStringList result;
00140 if (true!=m_conn->queryStringList(
00141 QString::fromLatin1("select db_value from kexi__db where db_property not like ")
00142 + m_conn->driver()->escapeString(QString::fromLatin1(" %%")), result, 0 )) {
00143
00144 setError(m_conn, i18n("Could not read database properties."));
00145 return QStringList();
00146 }
00147 return result;
00148 }
|