DCL 4.0
Loading...
Searching...
No Matches
SQLException.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2#if __DCL_WINDOWS
3#include <windows.h>
4#endif
5
6#include <dcl/Object.h>
7
8#if __DCL_HAVE_ALLOC_DEBUG
9#undef __DCL_ALLOC_LEVEL
10#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
11#endif
12
13#include <dcl/Charset.h>
14#include <dcl/Thread.h>
15#include <dcl/SQL.h>
16
17#if __DCL_DEBUG
18#undef __THIS_FILE__
19static const char_t __THIS_FILE__[] = __T("dcl/SQLException.cpp");
20#endif
21
22__DCL_BEGIN_NAMESPACE
23
25
27{
28 StringBuilder r;
29#ifdef __DCL_DEBUG
30 if (_connHandle->errorFileName())
31 {
32 r = _connHandle->errorFileName();
33 r += __T(":");
34 r += Int32::toString(_connHandle->errorLine(), 10) + __T(": ");
35 }
36#endif
37
38 if (_connHandle->errorCode() == SQL::eServerError)
39 {
40 r += _connHandle->serverTitle();
41 r += __T(": ");
42
43 ByteString s;
44 size_t n = 1024;
45 ByteBuffer* buf = ByteBuffer::create(n);
46 bool b = _connHandle->getErrorMessage(buf->data(), &n);
47 if (b) {
48 buf->__dataLength = n;
49 s = buf;
50 }
51 buf->release();
52
53 if (s.length() > 0) {
54 try {
55 r += UTF8Decoder::decode(s);
56 }
57 catch (CharsetConvertException* e) {
58 // __DCL_TRACE_E(e);
59 e->destroy();
60 }
61 }
62 else {
63 r += __T("The Server Error Message is unavailable!!");
64 }
65 }
66 else {
67 r += __T("DCL: ");
68 size_t n = 256;
69 CharBuffer* buf = CharBuffer::create_e(n);
70 if (!SQL::getErrorMessage(buf->data(), &n, _connHandle->errorCode()))
71 {
72 if (buf->__allocLength < n) {
73 CharBuffer::extend(buf, n);
74 }
75 SQL::getErrorMessage(buf->data(), &n, _connHandle->errorCode());
76 }
77 r.append(buf->data(), n);
78 buf->release();
79 }
80
81 return r;
82}
83
86{
87 __DCL_ASSERT(_conn && _conn->handle());
88
89 __message = getServerMessage(_conn->handle());
90}
91
92SQLException::SQLException(SQLConnection* _conn, const String& _message)
94{
95 __DCL_ASSERT(_conn && _conn->handle());
96 __message = getServerMessage(_conn->handle()) + __T(": ");
97 __message = __message + _message;
98}
99
101 : Exception(NULL)
102{
103 __DCL_ASSERT(_query && _query->handle()->connection());
104 __message = getServerMessage(_query->connection()->handle());
105}
106
107SQLException::SQLException(SQLQuery* _query, const String& _message)
108 : Exception(NULL)
109{
110 __DCL_ASSERT(_query && _query->handle()->connection());
111 __message = getServerMessage(_query->connection()->handle()) + __T(": ");
112 __message = __message + _message;
113}
114
116 : Exception(NULL)
117{
118 __DCL_ASSERT(_field && _field->handle()->connection());
119 StringBuilder sb = getServerMessage(_field->handle()->connection()) + __T(": ");
120 sb += _field->name();
121 sb += __T("(");
122 sb += _field->dataTypeName();
123 sb += __T(",");
124 sb += _field->handle()->serverDataTypeName();
125 sb += __T(")");
126 __message = sb.toString();
127}
128
130 SQLField* _field,
131 const wchar_t* _cast,
132 Exception* _cause
133 )
134 : Exception(_cause)
135{
136 StringBuilder sb = __T("SQLData access type error: ");
137 sb += _field->name();
138 sb += __T("(");
139 sb += _field->dataTypeName();
140 sb += __T("), access: ");
141 sb += _cast;
142 __message = sb.toString();
143}
144
146 SQLField* _field,
147 const wchar_t* _cast,
148 AsErrorCode _errorCode
149 )
150 : Exception(NULL)
151{
152 StringBuilder sb = __T("SQLData access type error: ");
153 sb += _field->name();
154 sb += __T("(");
155 sb += _field->dataTypeName();
156 sb += __T("), access: ");
157 sb += _cast;
158 switch(_errorCode)
159 {
160 case eInvalidCast :
161 sb += __T(": Data convert impossible");
162 break;
163 case eOutOfRange :
164 sb += __T(": Numeric convert out of range");
165 break;
166 default :
167 __DCL_ASSERT(false);
168 }
169 __message = sb.toString();
170}
171
173 : Exception(NULL)
174{
175 __DCL_ASSERT(_param && _param->handle()->connection());
176 __message = getServerMessage(_param->handle()->connection()) + __T(": ");
177
178 __message = __message + _param->name();
179}
180
182{
183 return __message;
184}
185
186__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
wchar_t char_t
Definition Config.h:275
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:228
#define __T(str)
Definition Object.h:44
ByteString r
ByteBuffer * buf
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
virtual void destroy()
Definition Exception.cpp:74
Exception(Exception *_cause=NULL)
String toString(unsigned _base=10) const
Definition Numeric.inl:87
const wchar_t * serverTitle() const
Definition SQLCore.inl:94
bool getErrorMessage(char *_pbuf, size_t *_pn)
Definition SQLCore.cpp:776
Error errorCode() const
Definition SQLCore.inl:72
SQL::Connection * handle() const
Definition SQL.inl:160
String getServerMessage(SQL::Connection *_connHandle)
virtual String toString() const
SQLException(SQLConnection *_conn)
Definition SQL.h:48
@ eServerError
Definition SQLCore.h:21
static bool getErrorMessage(wchar_t *_buf, size_t *_buflen, Error _errorCode)
Definition SQLCore.cpp:40
SQLConnection * connection() const
Definition SQL.inl:154
SQL::Query * handle() const
Definition SQL.inl:149