1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/* This file is part of the KDE project
Copyright (C) 2003-2005 Jaroslaw Staniek <[email protected]>
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.
*/
#ifndef KEXIDB_OBJECT_H
#define KEXIDB_OBJECT_H
#include <kexidb/error.h>
#include <tdemessagebox.h>
#include <kstdguiitem.h>
#include <tqstring.h>
namespace KexiDB {
class MessageHandler;
/*! Prototype of KexiDB object, handles result of last operation.
*/
class KEXI_DB_EXPORT Object
{
public:
/*! \return true if there was error during last operation on the object. */
bool error() const { return m_hasError; }
/*! \return (localized) error message if there was error during last operation on the object,
else: 0. */
const TQString& errorMsg() const { return m_errMsg; }
/*! \return error number of if there was error during last operation on the object,
else: 0. */
int errorNum() const { return m_errno; }
//! \return previous server result number, for error displaying purposes.
int previousServerResult() const { return m_previousServerResultNum; }
TQString previousServerResultName() const { return m_previousServerResultName; }
/*! Sends errorMsg() to debug output. */
void debugError();
/*! Clears error flag.
Also calls drv_clearServerResult().
You can reimplement this method in subclasses to clear even more members,
but remember to also call Object::clearError(). */
virtual void clearError();
/*! KexiDB library offers detailed error numbers using errorNum()
and detailed error i18n'd messages using errorMsg() -
this information is not engine-dependent (almost).
Use this in your application to give users more information on what's up.
This method returns (non-i18n'd !) engine-specific error message,
if there was any error during last server-side operation,
otherwise null string.
Reimplement this for your driver
- default implementation just returns null string.
\sa serverErrorMsg()
*/
virtual TQString serverErrorMsg();
/*! \return engine-specific last server-side operation result number.
Use this in your application to give users more information on what's up.
Reimplement this for your driver - default implementation just returns 0.
Note that this result value is not the same as the one returned
by errorNum() (Object::m_errno member)
\sa serverErrorMsg(), drv_clearServerResult()
*/
virtual int serverResult();
/*! \return engine-specific last server-side operation result name,
(name for serverResult()).
Use this in your application to give users more information on what's up.
Reimplement this for your driver - default implementation
just returns null string.
Note that this result name is not the same as the error message returned
by serverErorMsg() or erorMsg()
\sa serverErrorMsg(), drv_clearServerResult()
*/
virtual TQString serverResultName();
/*! \return message title that sometimes is provided and prepended
to the main warning/error message. Used by MessageHandler. */
TQString msgTitle() const { return m_msgTitle; }
/*! \return sql string of actually executed SQL statement,
usually using drv_executeSQL(). If there was error during executing SQL statement,
before, that string is returned instead. */
const TQString recentSQLString() const { return m_errorSql.isEmpty() ? m_sql : m_errorSql; }
protected:
/* Constructs a new object.
\a handler can be provided to receive error messages. */
Object(MessageHandler* handler = 0);
virtual ~Object();
/*! Sets the (localized) error code to \a code and message to \a msg.
You have to set at least nonzero error code \a code,
although it is also adviced to set descriptive message \a msg.
Eventually, if you omit all parameters, ERR_OTHER code will be set
and default message for this will be set.
Use this in KexiDB::Object subclasses to informa the world about your
object's state. */
virtual void setError(int code = ERR_OTHER, const TQString &msg = TQString() );
/*! \overload void setError(int code, const TQString &msg = TQString() )
Sets error code to ERR_OTHER. Use this if you don't care about
setting error code.
*/
virtual void setError( const TQString &msg );
/*! \overload void setError(const TQString &msg)
Also sets \a title. */
virtual void setError( const TQString &title, const TQString &msg );
/*! Copies the (localized) error message and code from other KexiDB::Object. */
void setError( KexiDB::Object *obj, const TQString& prependMessage = TQString() );
/*! Copies the (localized) error message and code from other KexiDB::Object
with custom error \a code. */
virtual void setError( KexiDB::Object *obj, int code,
const TQString& prependMessage = TQString() );
/*! Interactively asks a question. Console or GUI can be used for this,
depending on installed message handler. For GUI version, KMessageBox class is used.
See KexiDB::MessageHandler::askQuestion() for details. */
virtual int askQuestion( const TQString& message,
KMessageBox::DialogType dlgType, KMessageBox::ButtonCode defaultResult,
const KGuiItem &buttonYes=KStdGuiItem::yes(),
const KGuiItem &buttonNo=KStdGuiItem::no(),
const TQString &dontShowAskAgainName = TQString(),
int options = KMessageBox::Notify,
MessageHandler* msgHandler = 0 );
/*! Clears number of last server operation's result stored
as a single integer. Formally, this integer should be set to value
that means "NO ERRORS" or "OK". This method is called by clearError().
For reimplementation. By default does nothing.
\sa serverErrorMsg()
*/
virtual void drv_clearServerResult() {};
//! used to store of actually executed SQL statement
TQString m_sql, m_errorSql;
int m_serverResult;
TQString m_serverResultName, m_serverErrorMsg;
TQString m_errMsg;
private:
int m_errno;
bool m_hasError;
//! previous server result number, for error displaying purposes.
int m_previousServerResultNum, m_previousServerResultNum2;
//! previous server result name, for error displaying purposes.
TQString m_previousServerResultName, m_previousServerResultName2;
TQString m_msgTitle;
MessageHandler *m_msgHandler;
class Private;
Private *d; //!< for future extensions
friend class MessageTitle;
};
} //namespace KexiDB
#endif
|